mirror of
https://github.com/trezor/trezor-wallet
synced 2024-12-31 19:30:53 +00:00
Merge pull request #331 from trezor/fix/connect-backend-spinner
Fix/spinner for connect backend button
This commit is contained in:
commit
5423caea4f
@ -19,6 +19,9 @@ export type BlockchainAction = {
|
|||||||
type: typeof BLOCKCHAIN.UPDATE_FEE,
|
type: typeof BLOCKCHAIN.UPDATE_FEE,
|
||||||
shortcut: string,
|
shortcut: string,
|
||||||
feeLevels: Array<BlockchainFeeLevel>,
|
feeLevels: Array<BlockchainFeeLevel>,
|
||||||
|
} | {
|
||||||
|
type: typeof BLOCKCHAIN.START_SUBSCRIBE,
|
||||||
|
shortcut: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Conditionally subscribe to blockchain backend
|
// Conditionally subscribe to blockchain backend
|
||||||
@ -52,6 +55,11 @@ export const subscribe = (networkName: string): PromiseAction<void> => async (di
|
|||||||
const network = config.networks.find(c => c.shortcut === networkName);
|
const network = config.networks.find(c => c.shortcut === networkName);
|
||||||
if (!network) return;
|
if (!network) return;
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: BLOCKCHAIN.START_SUBSCRIBE,
|
||||||
|
shortcut: network.shortcut,
|
||||||
|
});
|
||||||
|
|
||||||
switch (network.type) {
|
switch (network.type) {
|
||||||
case 'ethereum':
|
case 'ethereum':
|
||||||
await dispatch(EthereumBlockchainActions.subscribe(networkName));
|
await dispatch(EthereumBlockchainActions.subscribe(networkName));
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/* @flow */
|
/* @flow */
|
||||||
|
|
||||||
|
export const START_SUBSCRIBE: 'blockchain__start_subscribe' = 'blockchain__start_subscribe';
|
||||||
export const READY: 'blockchain__ready' = 'blockchain__ready';
|
export const READY: 'blockchain__ready' = 'blockchain__ready';
|
||||||
export const UPDATE_FEE: 'blockchain__update_fee' = 'blockchain__update_fee';
|
export const UPDATE_FEE: 'blockchain__update_fee' = 'blockchain__update_fee';
|
@ -8,6 +8,7 @@ import type { Props } from '../../index';
|
|||||||
export default (props: Props) => {
|
export default (props: Props) => {
|
||||||
const { network, notification } = props.selectedAccount;
|
const { network, notification } = props.selectedAccount;
|
||||||
if (!network || !notification) return null;
|
if (!network || !notification) return null;
|
||||||
|
const blockchain = props.blockchain.find(b => b.shortcut === network.shortcut);
|
||||||
|
|
||||||
if (notification.type === 'backend') {
|
if (notification.type === 'backend') {
|
||||||
// special case: backend is down
|
// special case: backend is down
|
||||||
@ -17,6 +18,7 @@ export default (props: Props) => {
|
|||||||
type="error"
|
type="error"
|
||||||
title={notification.title}
|
title={notification.title}
|
||||||
message={notification.message}
|
message={notification.message}
|
||||||
|
isActionInProgress={blockchain && blockchain.connecting}
|
||||||
actions={
|
actions={
|
||||||
[{
|
[{
|
||||||
label: 'Connect',
|
label: 'Connect',
|
||||||
|
@ -16,6 +16,7 @@ export type BlockchainNetwork = {
|
|||||||
feeTimestamp: number,
|
feeTimestamp: number,
|
||||||
feeLevels: Array<BlockchainFeeLevel>,
|
feeLevels: Array<BlockchainFeeLevel>,
|
||||||
connected: boolean,
|
connected: boolean,
|
||||||
|
connecting: boolean,
|
||||||
block: number,
|
block: number,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -23,6 +24,26 @@ export type State = Array<BlockchainNetwork>;
|
|||||||
|
|
||||||
export const initialState: State = [];
|
export const initialState: State = [];
|
||||||
|
|
||||||
|
const onStartSubscribe = (state: State, shortcut: string): State => {
|
||||||
|
const network = state.find(b => b.shortcut === shortcut);
|
||||||
|
if (network) {
|
||||||
|
const others = state.filter(b => b !== network);
|
||||||
|
return others.concat([{
|
||||||
|
...network,
|
||||||
|
connecting: true,
|
||||||
|
}]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return state.concat([{
|
||||||
|
shortcut,
|
||||||
|
connected: false,
|
||||||
|
connecting: true,
|
||||||
|
block: 0,
|
||||||
|
feeTimestamp: 0,
|
||||||
|
feeLevels: [],
|
||||||
|
}]);
|
||||||
|
};
|
||||||
|
|
||||||
const onConnect = (state: State, action: BlockchainConnect): State => {
|
const onConnect = (state: State, action: BlockchainConnect): State => {
|
||||||
const shortcut = action.payload.coin.shortcut.toLowerCase();
|
const shortcut = action.payload.coin.shortcut.toLowerCase();
|
||||||
const network = state.find(b => b.shortcut === shortcut);
|
const network = state.find(b => b.shortcut === shortcut);
|
||||||
@ -31,13 +52,16 @@ const onConnect = (state: State, action: BlockchainConnect): State => {
|
|||||||
const others = state.filter(b => b !== network);
|
const others = state.filter(b => b !== network);
|
||||||
return others.concat([{
|
return others.concat([{
|
||||||
...network,
|
...network,
|
||||||
|
block: info.block,
|
||||||
connected: true,
|
connected: true,
|
||||||
|
connecting: false,
|
||||||
}]);
|
}]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return state.concat([{
|
return state.concat([{
|
||||||
shortcut,
|
shortcut,
|
||||||
connected: true,
|
connected: true,
|
||||||
|
connecting: false,
|
||||||
block: info.block,
|
block: info.block,
|
||||||
feeTimestamp: 0,
|
feeTimestamp: 0,
|
||||||
feeLevels: [],
|
feeLevels: [],
|
||||||
@ -52,12 +76,14 @@ const onError = (state: State, action: BlockchainError): State => {
|
|||||||
return others.concat([{
|
return others.concat([{
|
||||||
...network,
|
...network,
|
||||||
connected: false,
|
connected: false,
|
||||||
|
connecting: false,
|
||||||
}]);
|
}]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return state.concat([{
|
return state.concat([{
|
||||||
shortcut,
|
shortcut,
|
||||||
connected: false,
|
connected: false,
|
||||||
|
connecting: false,
|
||||||
block: 0,
|
block: 0,
|
||||||
feeTimestamp: 0,
|
feeTimestamp: 0,
|
||||||
feeLevels: [],
|
feeLevels: [],
|
||||||
@ -93,6 +119,8 @@ const updateFee = (state: State, shortcut: string, feeLevels: Array<BlockchainFe
|
|||||||
|
|
||||||
export default (state: State = initialState, action: Action): State => {
|
export default (state: State = initialState, action: Action): State => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
case BLOCKCHAIN_ACTION.START_SUBSCRIBE:
|
||||||
|
return onStartSubscribe(state, action.shortcut);
|
||||||
case BLOCKCHAIN_EVENT.CONNECT:
|
case BLOCKCHAIN_EVENT.CONNECT:
|
||||||
return onConnect(state, action);
|
return onConnect(state, action);
|
||||||
case BLOCKCHAIN_EVENT.ERROR:
|
case BLOCKCHAIN_EVENT.ERROR:
|
||||||
|
Loading…
Reference in New Issue
Block a user