Skip to content

Commit

Permalink
fix: live check for account activation status before sign payload
Browse files Browse the repository at this point in the history
  • Loading branch information
N3TC4T committed Jan 17, 2025
1 parent d3a1e8a commit 5ca14f9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const PaymentValidation: ValidationType<Payment> = (tx: Payment): Promise<void>
return;
}
} catch (e) {
reject(Localize.t('account.unableGetAccountInfo'));
reject(new Error(Localize.t('account.unableGetAccountInfo')));
return;
}
}
Expand Down
85 changes: 63 additions & 22 deletions src/screens/Modal/ReviewTransaction/ReviewTransactionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import ErrorView from './Shared/ErrorView';

import { StepsContext } from './Context';
import { Props, State, Steps } from './types';
import LedgerService from '@services/LedgerService';

/* Component ==================================================================== */
class ReviewTransactionModal extends Component<Props, State> {
Expand Down Expand Up @@ -238,6 +239,52 @@ class ReviewTransactionModal extends Component<Props, State> {
});
}

// do not continue
return;
}

// user may close the page at this point while we have been waiting for transaction validation
// we need to return if component is not mounted
if (!this.mounted) {
return;
}

// Live check if account is activated before continue for signing regular transaction
// ignore pseudo and multi-sign transactions
// ignore for "Import" transaction as it can be submitted even if account is not activated
if (
!payload.isPseudoTransaction() &&
!payload.isMultiSign() &&
transaction.Type !== TransactionTypes.Import
) {
const sourceAccountInfo = await LedgerService.getAccountInfo(source.address).catch(() => {
// do not catch
});

// if we couldn't get the account info then fallback to cached method
if (
(!sourceAccountInfo && source.balance === 0) ||
(sourceAccountInfo && 'error' in sourceAccountInfo && sourceAccountInfo.error === 'actNotFound')
) {
Navigator.showAlertModal({
type: 'error',
text: Localize.t('account.selectedAccountIsNotActivatedPleaseChooseAnotherOne'),
buttons: [
{
text: Localize.t('global.ok'),
light: false,
},
],
});

// do not continue
return;
}
}

// user may close the page at this point while we have been waiting for transaction validation
// we need to return if component is not mounted
if (!this.mounted) {
return;
}

Expand All @@ -261,36 +308,17 @@ class ReviewTransactionModal extends Component<Props, State> {
],
});
}

// do not continue
return;
}

// user may close the page at this point
// user may close the page at this point while we have been waiting for transaction validation
// we need to return if component is not mounted
if (!this.mounted) {
return;
}

// account is not activated and want to sign a tx
// ignore for "Import" transaction as it can be submitted even if account is not activated
if (
!payload.isPseudoTransaction() &&
transaction.Type !== TransactionTypes.Import &&
!payload.isMultiSign() &&
source!.balance === 0
) {
Navigator.showAlertModal({
type: 'error',
text: Localize.t('account.selectedAccountIsNotActivatedPleaseChooseAnotherOne'),
buttons: [
{
text: Localize.t('global.ok'),
light: false,
},
],
});
return;
}

// check for account delete and alert user
if (transaction.Type === TransactionTypes.AccountDelete) {
Navigator.showAlertModal({
Expand All @@ -313,6 +341,8 @@ class ReviewTransactionModal extends Component<Props, State> {
},
],
});

// do not continue
return;
}

Expand Down Expand Up @@ -350,6 +380,8 @@ class ReviewTransactionModal extends Component<Props, State> {
},
],
});

// do not continue
return;
}
}
Expand Down Expand Up @@ -389,6 +421,8 @@ class ReviewTransactionModal extends Component<Props, State> {
},
],
});

// do not continue
return;
}
}
Expand All @@ -411,6 +445,8 @@ class ReviewTransactionModal extends Component<Props, State> {
},
],
});

// do not continue
return;
}

Expand All @@ -436,6 +472,8 @@ class ReviewTransactionModal extends Component<Props, State> {
},
],
});

// do not continue
return;
}

Expand Down Expand Up @@ -463,10 +501,13 @@ class ReviewTransactionModal extends Component<Props, State> {
},
],
});

// do not continue
return;
}
} catch {
Toast(Localize.t('send.unableGetRecipientAccountInfoPleaseTryAgain'));
// do not continue
return;
}
}
Expand Down

0 comments on commit 5ca14f9

Please sign in to comment.