1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-28 03:08:30 +00:00

update fee in reducer only if changed

This commit is contained in:
Szymon Lesisz 2018-12-05 14:11:03 +01:00
parent 6d78e3a8f7
commit 3ae45ddd7e
2 changed files with 12 additions and 5 deletions

View File

@ -16,6 +16,7 @@ export type BlockchainAction = {
type: typeof BLOCKCHAIN.READY, type: typeof BLOCKCHAIN.READY,
} | { } | {
type: typeof BLOCKCHAIN.UPDATE_FEE, type: typeof BLOCKCHAIN.UPDATE_FEE,
shortcut: string,
fee: string, fee: string,
} }

View File

@ -23,16 +23,22 @@ export const subscribe = (network: string): PromiseAction<void> => async (dispat
}; };
export const onBlockMined = (network: string): PromiseAction<void> => async (dispatch: Dispatch): Promise<void> => { export const onBlockMined = (network: string): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
const fee = await TrezorConnect.blockchainGetFee({ const fee = await TrezorConnect.blockchainGetFee({
coin: network, coin: network,
}); });
if (!fee.success) return; if (!fee.success) return;
dispatch({ const blockchain = getState().blockchain.find(b => b.shortcut === network);
type: BLOCKCHAIN.UPDATE_FEE, if (!blockchain) return;
fee: fee.payload,
}); if (fee.payload !== blockchain.fee) {
dispatch({
type: BLOCKCHAIN.UPDATE_FEE,
shortcut: network,
fee: fee.payload,
});
}
}; };
export const onNotification = (payload: $ElementType<BlockchainNotification, 'payload'>): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => { export const onNotification = (payload: $ElementType<BlockchainNotification, 'payload'>): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {