Skip to content

Commit

Permalink
fix: add guard for draft tx in send validation
Browse files Browse the repository at this point in the history
  • Loading branch information
BZahory committed Aug 1, 2024
1 parent 883fd75 commit 75e6c33
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ui/ducks/send/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,10 @@ const slice = createSlice({
const draftTransaction =
state.draftTransactions[state.currentTransactionUUID];

if (!draftTransaction) {
return;
}

const amountValue = new Numeric(draftTransaction.amount.value, 16);

switch (true) {
Expand Down Expand Up @@ -1557,6 +1561,11 @@ const slice = createSlice({
validateGasField: (state) => {
const draftTransaction =
state.draftTransactions[state.currentTransactionUUID];

if (!draftTransaction) {
return;
}

const insufficientFunds = !isBalanceSufficient({
amount:
draftTransaction.sendAsset.type === AssetType.native
Expand Down
41 changes: 41 additions & 0 deletions ui/ducks/send/send.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,29 @@ describe('Send Slice', () => {
);
expect(draftTransaction.status).toBe(SEND_STATUSES.INVALID);
});

it('should not throw error when draft transaction does not exist', () => {
const tokenAssetState = getInitialSendStateWithExistingTxState({
amount: {
value: '0x77359400', // 2000000000
},
sendAsset: {
type: AssetType.token,
balance: '0x6fc23ac0', // 1875000000
details: {
decimals: 0,
},
},
});

const action = {
type: 'send/validateAmountField',
};

delete tokenAssetState.draftTransactions['test-uuid'];

expect(() => sendReducer(tokenAssetState, action)).not.toThrow();
});
});

describe('validateGasField', () => {
Expand All @@ -1101,6 +1124,24 @@ describe('Send Slice', () => {
INSUFFICIENT_FUNDS_ERROR,
);
});
it('should not throw error when draft transaction does not exist', () => {
const gasFieldState = getInitialSendStateWithExistingTxState({
account: {
balance: '0x0',
},
gas: {
gasTotal: '0x1319718a5000', // 21000000000000
},
});

delete gasFieldState.draftTransactions['test-uuid'];

const action = {
type: 'send/validateGasField',
};

expect(() => sendReducer(gasFieldState, action)).not.toThrow();
});
});

// TODO: update this
Expand Down

0 comments on commit 75e6c33

Please sign in to comment.