mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-11-24 08:55:14 +03:00
* added validation for key after scanning uri qr to check if user is logged in with required key
This commit is contained in:
parent
e62c42f00d
commit
08fa1bcf2d
@ -156,16 +156,26 @@ export const QRModal = ({}: QRModalProps) => {
|
||||
}
|
||||
|
||||
const parsed = hiveuri.decode(uri);
|
||||
const parsedHiveUriValidation = validateParsedHiveUri(parsed);
|
||||
const authoritiesMap = new Map();
|
||||
authoritiesMap.set('active', currentAccount?.local?.activeKey ? true : false);
|
||||
authoritiesMap.set('posting', currentAccount?.local?.postingKey ? true : false);
|
||||
authoritiesMap.set('owner', currentAccount?.local?.ownerKey ? true : false);
|
||||
authoritiesMap.set('memo', currentAccount?.local?.memoKey ? true : false);
|
||||
|
||||
const parsedHiveUriValidation = validateParsedHiveUri(parsed, authoritiesMap);
|
||||
if (parsedHiveUriValidation.error) {
|
||||
// show alert to user if parsed uri contains invalid operation data
|
||||
Alert.alert(
|
||||
intl.formatMessage({
|
||||
id: parsedHiveUriValidation.key1,
|
||||
}),
|
||||
intl.formatMessage({
|
||||
id: parsedHiveUriValidation.key2,
|
||||
}),
|
||||
intl.formatMessage(
|
||||
{ id: parsedHiveUriValidation.key1 },
|
||||
{ key: parsedHiveUriValidation.keyType },
|
||||
),
|
||||
intl.formatMessage(
|
||||
{
|
||||
id: parsedHiveUriValidation.key2,
|
||||
},
|
||||
{ key: parsedHiveUriValidation.keyType },
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
@ -1047,7 +1047,9 @@
|
||||
"invalid_op_desc": "try contacting QR/link author",
|
||||
"invalid_amount": "Invalid Amount",
|
||||
"invalid_amount_desc": "Enter valid amount in proper format",
|
||||
"transaction_failed": "Transaction Failed!"
|
||||
"transaction_failed": "Transaction Failed!",
|
||||
"invalid_key": "{key} key is required to perform this transaction",
|
||||
"invalid_key_desc": "kindly login with {key} key or master key to perform this transaction"
|
||||
},
|
||||
"history": {
|
||||
"edit": "Edit History",
|
||||
|
@ -38,6 +38,7 @@ const getOperationProps = (opName: string) => {
|
||||
const signerField = findParentKey(op, '__signer');
|
||||
return {
|
||||
opName: op.name,
|
||||
opAuthority: op.authority || '',
|
||||
signerField,
|
||||
};
|
||||
} else {
|
||||
@ -65,12 +66,13 @@ const _formatAmount = (amount: string) => {
|
||||
* Returns an object with error status, keys for showing errors, and operation name parsed from operations.json
|
||||
*
|
||||
* */
|
||||
export const validateParsedHiveUri = (parsedUri: any) => {
|
||||
export const validateParsedHiveUri = (parsedUri: any, authoritiesMap: Map<string, boolean>) => {
|
||||
let validateObj = {
|
||||
error: false,
|
||||
key1: '',
|
||||
key2: '',
|
||||
opName: '',
|
||||
keyType: '',
|
||||
tx: parsedUri.tx,
|
||||
};
|
||||
|
||||
@ -93,12 +95,20 @@ export const validateParsedHiveUri = (parsedUri: any) => {
|
||||
return validateObj;
|
||||
}
|
||||
const opProps = getOperationProps(operationName); // get operation props from operations.json file i-e signer field and operation name
|
||||
validateObj.keyType = opProps?.opAuthority || ''; // set key type to validate object
|
||||
|
||||
if (!opProps) {
|
||||
validateObj.error = true;
|
||||
validateObj.key1 = 'qr.invalid_op';
|
||||
validateObj.key2 = 'qr.invalid_op_desc';
|
||||
return validateObj;
|
||||
}
|
||||
if (authoritiesMap && !authoritiesMap.get(opProps.opAuthority)) {
|
||||
validateObj.error = true;
|
||||
validateObj.key1 = 'qr.invalid_key';
|
||||
validateObj.key2 = 'qr.invalid_key_desc';
|
||||
return validateObj;
|
||||
}
|
||||
// if amount field present in operation, validate and check for proper formatting and format to 3 decimal places
|
||||
if (operationObj.hasOwnProperty('amount')) {
|
||||
const amount = _formatAmount(operationObj.amount);
|
||||
|
Loading…
Reference in New Issue
Block a user