* added validation for key after scanning uri qr to check if user is logged in with required key

This commit is contained in:
Sadaqat Ali 2023-09-17 13:04:55 +05:00
parent e62c42f00d
commit 08fa1bcf2d
3 changed files with 31 additions and 9 deletions

View File

@ -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;
}

View File

@ -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",

View File

@ -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);