mirror of
https://github.com/trezor/trezor-wallet
synced 2024-12-29 10:28:08 +00:00
Added messages to loading, added more cases
This commit is contained in:
parent
7b7eb5350d
commit
c5a9c8fdb7
@ -42,7 +42,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState):
|
|||||||
const device = state.wallet.selectedDevice;
|
const device = state.wallet.selectedDevice;
|
||||||
if (!device || !device.state) {
|
if (!device || !device.state) {
|
||||||
return {
|
return {
|
||||||
type: 'info',
|
type: 'loader-progress',
|
||||||
title: 'Loading device...',
|
title: 'Loading device...',
|
||||||
shouldRender: false,
|
shouldRender: false,
|
||||||
};
|
};
|
||||||
@ -57,7 +57,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState):
|
|||||||
// corner case: accountState didn't finish loading state after LOCATION_CHANGE action
|
// corner case: accountState didn't finish loading state after LOCATION_CHANGE action
|
||||||
if (!network) {
|
if (!network) {
|
||||||
return {
|
return {
|
||||||
type: 'info',
|
type: 'loader-progress',
|
||||||
title: 'Loading account state...',
|
title: 'Loading account state...',
|
||||||
shouldRender: false,
|
shouldRender: false,
|
||||||
};
|
};
|
||||||
@ -79,14 +79,14 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState):
|
|||||||
// case 1: device is connected but discovery not started yet (probably waiting for auth)
|
// case 1: device is connected but discovery not started yet (probably waiting for auth)
|
||||||
if (device.available) {
|
if (device.available) {
|
||||||
return {
|
return {
|
||||||
type: 'info',
|
type: 'loader-progress',
|
||||||
title: 'Authenticating device...',
|
title: 'Authenticating device...',
|
||||||
shouldRender: 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
|
||||||
return {
|
return {
|
||||||
type: 'info',
|
type: 'loader-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',
|
||||||
shouldRender: false,
|
shouldRender: false,
|
||||||
@ -95,7 +95,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState):
|
|||||||
|
|
||||||
// case 3: device is disconnected
|
// case 3: device is disconnected
|
||||||
return {
|
return {
|
||||||
type: 'info',
|
type: 'loader-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',
|
||||||
shouldRender: false,
|
shouldRender: false,
|
||||||
@ -105,7 +105,7 @@ const getAccountStatus = (state: State, selectedAccount: SelectedAccountState):
|
|||||||
if (discovery.completed) {
|
if (discovery.completed) {
|
||||||
// case 4: account not found and discovery is completed
|
// case 4: account not found and discovery is completed
|
||||||
return {
|
return {
|
||||||
type: 'warning',
|
type: 'loader-info',
|
||||||
title: 'Account does not exist',
|
title: 'Account does not exist',
|
||||||
shouldRender: false,
|
shouldRender: false,
|
||||||
};
|
};
|
||||||
@ -154,6 +154,11 @@ export const observe = (prevState: State, action: Action): PayloadAction<boolean
|
|||||||
if (actions.indexOf(action.type) < 0) return false;
|
if (actions.indexOf(action.type) < 0) return false;
|
||||||
|
|
||||||
const state: State = getState();
|
const state: State = getState();
|
||||||
|
const notification = {
|
||||||
|
type: null,
|
||||||
|
message: null,
|
||||||
|
title: null,
|
||||||
|
};
|
||||||
const { location } = state.router;
|
const { location } = state.router;
|
||||||
// displayed route is not an account route
|
// displayed route is not an account route
|
||||||
if (!location.state.account) return false;
|
if (!location.state.account) return false;
|
||||||
@ -173,13 +178,13 @@ export const observe = (prevState: State, action: Action): PayloadAction<boolean
|
|||||||
discovery,
|
discovery,
|
||||||
tokens,
|
tokens,
|
||||||
pending,
|
pending,
|
||||||
notification: null,
|
notification,
|
||||||
shouldRender: 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 || notification;
|
||||||
newState.shouldRender = status ? status.shouldRender : 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, {
|
const stateChanged = reducerUtils.observeChanges(prevState.selectedAccount, newState, {
|
||||||
|
@ -7,7 +7,7 @@ import type { Props } from '../../index';
|
|||||||
// There could be only one account notification
|
// There could be only one account notification
|
||||||
export default (props: Props) => {
|
export default (props: Props) => {
|
||||||
const { network, notification } = props.selectedAccount;
|
const { network, notification } = props.selectedAccount;
|
||||||
if (network && notification) {
|
if (network && notification.type && notification.type !== 'loader-progress' && notification.type !== 'loader-info') {
|
||||||
if (notification.type === 'backend') {
|
if (notification.type === 'backend') {
|
||||||
// special case: backend is down
|
// special case: backend is down
|
||||||
// TODO: this is a different component with "auto resolve" button
|
// TODO: this is a different component with "auto resolve" button
|
||||||
|
@ -17,10 +17,10 @@ export type State = {
|
|||||||
tokens: Array<Token>,
|
tokens: Array<Token>,
|
||||||
pending: Array<PendingTx>,
|
pending: Array<PendingTx>,
|
||||||
discovery: ?Discovery,
|
discovery: ?Discovery,
|
||||||
notification: ?{
|
notification: {
|
||||||
type: string,
|
type: ?string,
|
||||||
title: string,
|
title: ?string,
|
||||||
message?: string,
|
message: ?string,
|
||||||
},
|
},
|
||||||
shouldRender: boolean,
|
shouldRender: boolean,
|
||||||
};
|
};
|
||||||
@ -32,7 +32,11 @@ export const initialState: State = {
|
|||||||
tokens: [],
|
tokens: [],
|
||||||
pending: [],
|
pending: [],
|
||||||
discovery: null,
|
discovery: null,
|
||||||
notification: null,
|
notification: {
|
||||||
|
type: null,
|
||||||
|
title: null,
|
||||||
|
message: null,
|
||||||
|
},
|
||||||
shouldRender: false,
|
shouldRender: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ const Loading = styled.div`
|
|||||||
flex: 1;
|
flex: 1;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
flex-direction: row;
|
flex-direction: column;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const Text = styled.div`
|
const Text = styled.div`
|
||||||
@ -26,16 +26,32 @@ const Text = styled.div`
|
|||||||
margin-left: 10px;
|
margin-left: 10px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const Message = styled.div`
|
||||||
|
font-size: ${FONT_SIZE.SMALL};
|
||||||
|
color: ${colors.TEXT_PRIMARY};
|
||||||
|
`;
|
||||||
|
|
||||||
|
const Row = styled.div`
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
`;
|
||||||
|
|
||||||
const Content = ({
|
const Content = ({
|
||||||
children,
|
children,
|
||||||
|
title,
|
||||||
|
message,
|
||||||
|
type,
|
||||||
isLoading = false,
|
isLoading = false,
|
||||||
}) => (
|
}) => (
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
{!isLoading && children}
|
{(!isLoading) && children}
|
||||||
{isLoading && (
|
{isLoading && (type === 'loader-progress' || type === 'loader-info') && (
|
||||||
<Loading>
|
<Loading>
|
||||||
<Loader size={30} />
|
<Row>
|
||||||
<Text>Initializing accounts</Text>
|
{type === 'loader-progress' && <Loader size={30} />}
|
||||||
|
<Text>{title || 'Initializing accounts'}</Text>
|
||||||
|
</Row>
|
||||||
|
{message && <Message>{message}</Message>}
|
||||||
</Loading>
|
</Loading>
|
||||||
)}
|
)}
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
@ -44,6 +60,9 @@ const Content = ({
|
|||||||
Content.propTypes = {
|
Content.propTypes = {
|
||||||
children: PropTypes.element,
|
children: PropTypes.element,
|
||||||
isLoading: PropTypes.bool,
|
isLoading: PropTypes.bool,
|
||||||
|
title: PropTypes.string,
|
||||||
|
message: PropTypes.string,
|
||||||
|
type: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Content;
|
export default Content;
|
||||||
|
@ -93,9 +93,10 @@ const AccountReceive = (props: Props) => {
|
|||||||
account,
|
account,
|
||||||
discovery,
|
discovery,
|
||||||
shouldRender,
|
shouldRender,
|
||||||
|
notification,
|
||||||
} = props.selectedAccount;
|
} = props.selectedAccount;
|
||||||
|
const { type, title, message } = notification;
|
||||||
if (!device || !account || !discovery || !shouldRender) return null;
|
if (!device || !account || !discovery || !shouldRender) return <Content type={type} title={title} message={message} isLoading />;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
addressVerified,
|
addressVerified,
|
||||||
@ -111,7 +112,7 @@ const AccountReceive = (props: Props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Content isLoading={!discovery.completed}>
|
<Content>
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<H2>Receive Ethereum or tokens</H2>
|
<H2>Receive Ethereum or tokens</H2>
|
||||||
<AddressWrapper isShowingQrCode={addressVerified || addressUnverified}>
|
<AddressWrapper isShowingQrCode={addressVerified || addressUnverified}>
|
||||||
|
@ -185,6 +185,7 @@ const AccountSend = (props: Props) => {
|
|||||||
discovery,
|
discovery,
|
||||||
tokens,
|
tokens,
|
||||||
shouldRender,
|
shouldRender,
|
||||||
|
notification,
|
||||||
} = props.selectedAccount;
|
} = props.selectedAccount;
|
||||||
const {
|
const {
|
||||||
address,
|
address,
|
||||||
@ -213,8 +214,8 @@ const AccountSend = (props: Props) => {
|
|||||||
updateFeeLevels,
|
updateFeeLevels,
|
||||||
onSend,
|
onSend,
|
||||||
} = props.sendFormActions;
|
} = props.sendFormActions;
|
||||||
|
const { type, title, message } = notification;
|
||||||
if (!device || !account || !discovery || !network || !shouldRender) return null;
|
if (!device || !account || !discovery || !network || !shouldRender) return <Content type={type} title={title} message={message} isLoading />;
|
||||||
|
|
||||||
const isCurrentCurrencyToken = networkSymbol !== currency;
|
const isCurrentCurrencyToken = networkSymbol !== currency;
|
||||||
|
|
||||||
@ -248,7 +249,7 @@ const AccountSend = (props: Props) => {
|
|||||||
const isAdvancedSettingsHidden = !advanced;
|
const isAdvancedSettingsHidden = !advanced;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Content isLoading={!discovery.completed}>
|
<Content>
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<H2>Send Ethereum or tokens</H2>
|
<H2>Send Ethereum or tokens</H2>
|
||||||
<InputRow>
|
<InputRow>
|
||||||
|
@ -73,20 +73,20 @@ const AccountSummary = (props: Props) => {
|
|||||||
account,
|
account,
|
||||||
network,
|
network,
|
||||||
tokens,
|
tokens,
|
||||||
discovery,
|
|
||||||
pending,
|
pending,
|
||||||
|
notification,
|
||||||
shouldRender,
|
shouldRender,
|
||||||
} = props.selectedAccount;
|
} = props.selectedAccount;
|
||||||
|
|
||||||
// flow
|
const { type, title, message } = notification;
|
||||||
if (!device || !account || !network || !shouldRender) return null;
|
if (!device || !account || !network || !shouldRender) return <Content type={type} title={title} message={message} isLoading />;
|
||||||
|
|
||||||
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);
|
||||||
const balance: string = new BigNumber(account.balance).minus(pendingAmount).toString(10);
|
const balance: string = new BigNumber(account.balance).minus(pendingAmount).toString(10);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Content isLoading={!discovery.completed}>
|
<Content>
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<AccountHeading>
|
<AccountHeading>
|
||||||
<AccountName>
|
<AccountName>
|
||||||
|
Loading…
Reference in New Issue
Block a user