Skip to content
This repository has been archived by the owner on Nov 11, 2021. It is now read-only.

Commit

Permalink
Merge pull request #252 from trezor/fix/validate-token-in-send-draft
Browse files Browse the repository at this point in the history
token existence validation
  • Loading branch information
vladimirvolek committed Nov 22, 2018
2 parents 154fce5 + 2a7d539 commit 35b97f9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/actions/SendFormActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,20 @@ export const observe = (prevState: ReducersState, action: Action): ThunkAction =
let shouldUpdate: boolean = false;
// check if "selectedAccount" reducer changed
shouldUpdate = reducerUtils.observeChanges(prevState.selectedAccount, currentState.selectedAccount, {
account: ['balance', 'nonce'],
account: ['balance', 'nonce', 'tokens'],
});
if (shouldUpdate && currentState.sendForm.currency !== currentState.sendForm.networkSymbol) {
// make sure that this token is added into account
const { account, tokens } = getState().selectedAccount;
if (!account) return;
const token = findToken(tokens, account.address, currentState.sendForm.currency, account.deviceState);
if (!token) {
// token not found, re-init form
dispatch(init());
return;
}
}


// check if "sendForm" reducer changed
if (!shouldUpdate) {
Expand Down
11 changes: 11 additions & 0 deletions src/actions/SessionStorageActions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow */
import * as storageUtils from 'utils/storage';
import { findToken } from 'reducers/TokensReducer';

import type { State as SendFormState } from 'reducers/SendFormReducer';
import type {
Expand Down Expand Up @@ -38,6 +39,16 @@ export const loadDraftTransaction = (): PayloadAction<?SendFormState> => (dispat
storageUtils.remove(TYPE, key);
return null;
}
// check if selected currency is token and make sure that this token is added into account
if (state.currency !== state.networkSymbol) {
const { account, tokens } = getState().selectedAccount;
if (!account) return null;
const token = findToken(tokens, account.address, state.currency, account.deviceState);
if (!token) {
storageUtils.remove(TYPE, key);
return null;
}
}
return state;
};

Expand Down

0 comments on commit 35b97f9

Please sign in to comment.