mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-24 09:18:09 +00:00
rename selectedAccount.visible to shouldRender
This commit is contained in:
parent
61d9713b0b
commit
f0e0b4fee2
@ -22,10 +22,10 @@ export type SelectedAccountAction = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
type AccountStatus = {
|
type AccountStatus = {
|
||||||
type: string;
|
type: string; // notification type
|
||||||
title: string;
|
title: string; // notification title
|
||||||
message?: string;
|
message?: string; // notification message
|
||||||
visible: boolean;
|
shouldRender: boolean; // should render account page
|
||||||
}
|
}
|
||||||
|
|
||||||
export const dispose = (): Action => ({
|
export const dispose = (): Action => ({
|
||||||
@ -38,7 +38,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState):
|
|||||||
return {
|
return {
|
||||||
type: 'info',
|
type: 'info',
|
||||||
title: 'Loading device...',
|
title: 'Loading device...',
|
||||||
visible: false,
|
shouldRender: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState):
|
|||||||
return {
|
return {
|
||||||
type: 'info',
|
type: 'info',
|
||||||
title: 'Loading account state...',
|
title: 'Loading account state...',
|
||||||
visible: false,
|
shouldRender: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState):
|
|||||||
return {
|
return {
|
||||||
type: 'backend',
|
type: 'backend',
|
||||||
title: 'Backend is not connected',
|
title: 'Backend is not connected',
|
||||||
visible: false,
|
shouldRender: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState):
|
|||||||
return {
|
return {
|
||||||
type: 'info',
|
type: 'info',
|
||||||
title: 'Loading accounts...',
|
title: 'Loading accounts...',
|
||||||
visible: false,
|
shouldRender: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// case 2: device is unavailable (created with different passphrase settings) account cannot be accessed
|
// 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',
|
type: 'info',
|
||||||
title: `Device ${device.instanceLabel} is unavailable`,
|
title: `Device ${device.instanceLabel} is unavailable`,
|
||||||
message: 'Change passphrase settings to use this device',
|
message: 'Change passphrase settings to use this device',
|
||||||
visible: false,
|
shouldRender: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState):
|
|||||||
type: 'info',
|
type: 'info',
|
||||||
title: `Device ${device.instanceLabel} is disconnected`,
|
title: `Device ${device.instanceLabel} is disconnected`,
|
||||||
message: 'Connect device to load accounts',
|
message: 'Connect device to load accounts',
|
||||||
visible: false,
|
shouldRender: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState):
|
|||||||
return {
|
return {
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
title: 'Account does not exist',
|
title: 'Account does not exist',
|
||||||
visible: false,
|
shouldRender: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState):
|
|||||||
return {
|
return {
|
||||||
type: 'info',
|
type: 'info',
|
||||||
title: 'Loading accounts...',
|
title: 'Loading accounts...',
|
||||||
visible: false,
|
shouldRender: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState):
|
|||||||
return {
|
return {
|
||||||
type: 'info',
|
type: 'info',
|
||||||
title: `Device ${device.instanceLabel} is disconnected`,
|
title: `Device ${device.instanceLabel} is disconnected`,
|
||||||
visible: true,
|
shouldRender: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (!device.available) {
|
if (!device.available) {
|
||||||
@ -126,7 +126,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState):
|
|||||||
type: 'info',
|
type: 'info',
|
||||||
title: `Device ${device.instanceLabel} is unavailable`,
|
title: `Device ${device.instanceLabel} is unavailable`,
|
||||||
message: 'Change passphrase settings to use this device',
|
message: 'Change passphrase settings to use this device',
|
||||||
visible: true,
|
shouldRender: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState):
|
|||||||
return {
|
return {
|
||||||
type: 'info',
|
type: 'info',
|
||||||
title: 'Loading accounts...',
|
title: 'Loading accounts...',
|
||||||
visible: true,
|
shouldRender: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,50 +178,21 @@ export const observe = (prevState: State, action: Action): AsyncAction => async
|
|||||||
tokens,
|
tokens,
|
||||||
pending,
|
pending,
|
||||||
notification: null,
|
notification: null,
|
||||||
visible: false,
|
shouldRender: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
// get "selectedAccount" status from newState
|
// get "selectedAccount" status from newState
|
||||||
const status = getAccountStatus(state, newState);
|
const status = getAccountStatus(state, newState);
|
||||||
newState.notification = status || null;
|
newState.notification = status || null;
|
||||||
newState.visible = status ? status.visible : true;
|
newState.shouldRender = status ? status.shouldRender : true;
|
||||||
|
|
||||||
// check if newState is different than previous state
|
// 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) {
|
if (stateChanged) {
|
||||||
// update values in reducer
|
// update values in reducer
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACCOUNT.UPDATE_SELECTED_ACCOUNT,
|
type: ACCOUNT.UPDATE_SELECTED_ACCOUNT,
|
||||||
payload: newState,
|
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,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -22,7 +22,7 @@ export type State = {
|
|||||||
title: string,
|
title: string,
|
||||||
message?: string,
|
message?: string,
|
||||||
},
|
},
|
||||||
visible: boolean,
|
shouldRender: boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initialState: State = {
|
export const initialState: State = {
|
||||||
@ -33,7 +33,7 @@ export const initialState: State = {
|
|||||||
pending: [],
|
pending: [],
|
||||||
discovery: null,
|
discovery: null,
|
||||||
notification: null,
|
notification: null,
|
||||||
visible: false,
|
shouldRender: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (state: State = initialState, action: Action): State => {
|
export default (state: State = initialState, action: Action): State => {
|
||||||
|
@ -133,9 +133,10 @@ const AccountReceive = (props: Props) => {
|
|||||||
const {
|
const {
|
||||||
account,
|
account,
|
||||||
discovery,
|
discovery,
|
||||||
|
shouldRender,
|
||||||
} = props.selectedAccount;
|
} = props.selectedAccount;
|
||||||
|
|
||||||
if (!device || !account || !discovery) return null;
|
if (!device || !account || !discovery || !shouldRender) return null;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
addressVerified,
|
addressVerified,
|
||||||
|
@ -190,6 +190,7 @@ const AccountSend = (props: Props) => {
|
|||||||
network,
|
network,
|
||||||
discovery,
|
discovery,
|
||||||
tokens,
|
tokens,
|
||||||
|
shouldRender,
|
||||||
} = props.selectedAccount;
|
} = props.selectedAccount;
|
||||||
const {
|
const {
|
||||||
address,
|
address,
|
||||||
@ -218,6 +219,8 @@ const AccountSend = (props: Props) => {
|
|||||||
onSend,
|
onSend,
|
||||||
} = props.sendFormActions;
|
} = props.sendFormActions;
|
||||||
|
|
||||||
|
if (!device || !account || !discovery || !network || !shouldRender) return null;
|
||||||
|
|
||||||
const isCurrentCurrencyToken = networkSymbol !== currency;
|
const isCurrentCurrencyToken = networkSymbol !== currency;
|
||||||
|
|
||||||
let selectedTokenBalance = 0;
|
let selectedTokenBalance = 0;
|
||||||
@ -226,8 +229,6 @@ const AccountSend = (props: Props) => {
|
|||||||
selectedTokenBalance = selectedToken.balance;
|
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 isSendButtonDisabled: boolean = Object.keys(errors).length > 0 || total === '0' || amount.length === 0 || address.length === 0 || sending;
|
||||||
let sendButtonText: string = 'Send';
|
let sendButtonText: string = 'Send';
|
||||||
if (networkSymbol !== currency && amount.length > 0 && !errors.amount) {
|
if (networkSymbol !== currency && amount.length > 0 && !errors.amount) {
|
||||||
|
@ -64,11 +64,11 @@ const AccountSummary = (props: Props) => {
|
|||||||
network,
|
network,
|
||||||
tokens,
|
tokens,
|
||||||
pending,
|
pending,
|
||||||
visible,
|
shouldRender,
|
||||||
} = props.selectedAccount;
|
} = props.selectedAccount;
|
||||||
|
|
||||||
// flow
|
// flow
|
||||||
if (!device || !account || !network || !visible) return null;
|
if (!device || !account || !network || !shouldRender) return null;
|
||||||
|
|
||||||
const explorerLink: string = `${network.explorer.address}${account.address}`;
|
const explorerLink: string = `${network.explorer.address}${account.address}`;
|
||||||
const pendingAmount: BigNumber = stateUtils.getPendingAmount(pending, network.symbol);
|
const pendingAmount: BigNumber = stateUtils.getPendingAmount(pending, network.symbol);
|
||||||
|
Loading…
Reference in New Issue
Block a user