From f0e0b4fee23a60ef4005710a02aa9de574d695f3 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Wed, 26 Sep 2018 19:35:36 +0200 Subject: [PATCH] rename selectedAccount.visible to shouldRender --- src/actions/SelectedAccountActions.js | 65 +++++-------------- src/reducers/SelectedAccountReducer.js | 4 +- .../Wallet/views/AccountReceive/index.js | 3 +- src/views/Wallet/views/AccountSend/index.js | 5 +- .../Wallet/views/AccountSummary/index.js | 4 +- 5 files changed, 27 insertions(+), 54 deletions(-) diff --git a/src/actions/SelectedAccountActions.js b/src/actions/SelectedAccountActions.js index a5f1a91d..02826e00 100644 --- a/src/actions/SelectedAccountActions.js +++ b/src/actions/SelectedAccountActions.js @@ -22,10 +22,10 @@ export type SelectedAccountAction = { }; type AccountStatus = { - type: string; - title: string; - message?: string; - visible: boolean; + type: string; // notification type + title: string; // notification title + message?: string; // notification message + shouldRender: boolean; // should render account page } export const dispose = (): Action => ({ @@ -38,7 +38,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState): return { type: 'info', title: 'Loading device...', - visible: false, + shouldRender: false, }; } @@ -53,7 +53,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState): return { type: 'info', title: 'Loading account state...', - visible: false, + shouldRender: false, }; } @@ -62,7 +62,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState): return { type: 'backend', title: 'Backend is not connected', - visible: false, + shouldRender: false, }; } @@ -75,7 +75,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState): return { type: 'info', title: 'Loading accounts...', - visible: false, + shouldRender: false, }; } // case 2: device is unavailable (created with different passphrase settings) account cannot be accessed @@ -83,7 +83,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState): type: 'info', title: `Device ${device.instanceLabel} is unavailable`, message: 'Change passphrase settings to use this device', - visible: false, + shouldRender: false, }; } @@ -92,7 +92,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState): type: 'info', title: `Device ${device.instanceLabel} is disconnected`, message: 'Connect device to load accounts', - visible: false, + shouldRender: false, }; } @@ -101,7 +101,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState): return { type: 'warning', title: 'Account does not exist', - visible: false, + shouldRender: false, }; } @@ -109,7 +109,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState): return { type: 'info', title: 'Loading accounts...', - visible: false, + shouldRender: false, }; } @@ -118,7 +118,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState): return { type: 'info', title: `Device ${device.instanceLabel} is disconnected`, - visible: true, + shouldRender: true, }; } if (!device.available) { @@ -126,7 +126,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState): type: 'info', title: `Device ${device.instanceLabel} is unavailable`, message: 'Change passphrase settings to use this device', - visible: true, + shouldRender: true, }; } @@ -135,7 +135,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState): return { type: 'info', title: 'Loading accounts...', - visible: true, + shouldRender: true, }; } @@ -178,50 +178,21 @@ export const observe = (prevState: State, action: Action): AsyncAction => async tokens, pending, notification: null, - visible: false, + shouldRender: false, }; // get "selectedAccount" status from newState const status = getAccountStatus(state, newState); newState.notification = status || null; - newState.visible = status ? status.visible : true; + newState.shouldRender = status ? status.shouldRender : true; // check if newState is different than previous state - const stateChanged = reducerUtils.observeChanges(prevState.selectedAccount, newState, ['location', 'account', 'network', 'discovery', 'tokens', 'pending', 'status', 'visible']); + const stateChanged = reducerUtils.observeChanges(prevState.selectedAccount, newState, ['location', 'account', 'network', 'discovery', 'tokens', 'pending', 'notification', 'shouldRender']); if (stateChanged) { // update values in reducer dispatch({ type: ACCOUNT.UPDATE_SELECTED_ACCOUNT, payload: newState, }); - - // TODO: move this to send account actions - /* - if (location.state.send) { - const rejectedTxs = pending.filter(tx => tx.rejected); - rejectedTxs.forEach((tx) => { - dispatch({ - type: NOTIFICATION.ADD, - payload: { - type: 'warning', - title: 'Pending transaction rejected', - message: `Transaction with id: ${tx.id} not found.`, - cancelable: true, - actions: [ - { - label: 'OK', - callback: () => { - dispatch({ - type: PENDING.TX_RESOLVED, - tx, - }); - }, - }, - ], - }, - }); - }); - } - */ } }; diff --git a/src/reducers/SelectedAccountReducer.js b/src/reducers/SelectedAccountReducer.js index f64ea582..1b400668 100644 --- a/src/reducers/SelectedAccountReducer.js +++ b/src/reducers/SelectedAccountReducer.js @@ -22,7 +22,7 @@ export type State = { title: string, message?: string, }, - visible: boolean, + shouldRender: boolean, }; export const initialState: State = { @@ -33,7 +33,7 @@ export const initialState: State = { pending: [], discovery: null, notification: null, - visible: false, + shouldRender: false, }; export default (state: State = initialState, action: Action): State => { diff --git a/src/views/Wallet/views/AccountReceive/index.js b/src/views/Wallet/views/AccountReceive/index.js index d76a1cab..9e80b195 100644 --- a/src/views/Wallet/views/AccountReceive/index.js +++ b/src/views/Wallet/views/AccountReceive/index.js @@ -133,9 +133,10 @@ const AccountReceive = (props: Props) => { const { account, discovery, + shouldRender, } = props.selectedAccount; - if (!device || !account || !discovery) return null; + if (!device || !account || !discovery || !shouldRender) return null; const { addressVerified, diff --git a/src/views/Wallet/views/AccountSend/index.js b/src/views/Wallet/views/AccountSend/index.js index 6da252b5..7007d92d 100644 --- a/src/views/Wallet/views/AccountSend/index.js +++ b/src/views/Wallet/views/AccountSend/index.js @@ -190,6 +190,7 @@ const AccountSend = (props: Props) => { network, discovery, tokens, + shouldRender, } = props.selectedAccount; const { address, @@ -218,6 +219,8 @@ const AccountSend = (props: Props) => { onSend, } = props.sendFormActions; + if (!device || !account || !discovery || !network || !shouldRender) return null; + const isCurrentCurrencyToken = networkSymbol !== currency; let selectedTokenBalance = 0; @@ -226,8 +229,6 @@ const AccountSend = (props: Props) => { selectedTokenBalance = selectedToken.balance; } - if (!device || !account || !discovery || !network) return null; - let isSendButtonDisabled: boolean = Object.keys(errors).length > 0 || total === '0' || amount.length === 0 || address.length === 0 || sending; let sendButtonText: string = 'Send'; if (networkSymbol !== currency && amount.length > 0 && !errors.amount) { diff --git a/src/views/Wallet/views/AccountSummary/index.js b/src/views/Wallet/views/AccountSummary/index.js index 6e78da1d..405428b9 100644 --- a/src/views/Wallet/views/AccountSummary/index.js +++ b/src/views/Wallet/views/AccountSummary/index.js @@ -64,11 +64,11 @@ const AccountSummary = (props: Props) => { network, tokens, pending, - visible, + shouldRender, } = props.selectedAccount; // flow - if (!device || !account || !network || !visible) return null; + if (!device || !account || !network || !shouldRender) return null; const explorerLink: string = `${network.explorer.address}${account.address}`; const pendingAmount: BigNumber = stateUtils.getPendingAmount(pending, network.symbol);