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

call PENDING.ADD from BlockbookActions

This commit is contained in:
Szymon Lesisz 2018-12-18 22:10:20 +01:00
parent cbc0151a62
commit bab5007847
2 changed files with 48 additions and 10 deletions

View File

@ -2,6 +2,7 @@
import TrezorConnect from 'trezor-connect';
import BigNumber from 'bignumber.js';
import * as PENDING from 'actions/constants/pendingTx';
import type {
TrezorDevice,
@ -9,7 +10,7 @@ import type {
GetState,
PromiseAction,
} from 'flowtype';
import type { EthereumAccount } from 'trezor-connect';
import type { EthereumAccount, BlockchainNotification } from 'trezor-connect';
import type { Token } from 'reducers/TokensReducer';
import type { NetworkToken } from 'reducers/LocalStorageReducer';
import * as Web3Actions from 'actions/Web3Actions';
@ -125,7 +126,37 @@ export const onBlockMined = (network: string): PromiseAction<void> => async (dis
}
};
export const onNotification = (/*network: string*/): PromiseAction<void> => async (): Promise<void> => {
export const onNotification = (payload: $ElementType<BlockchainNotification, 'payload'>): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
const { notification } = payload;
const account = getState().accounts.find(a => a.address === notification.address);
if (!account) return;
if (notification.status === 'pending') {
dispatch({
type: PENDING.ADD,
payload: {
type: notification.type,
address: notification.address,
deviceState: account.deviceState,
inputs: notification.inputs,
outputs: notification.outputs,
sequence: notification.sequence,
hash: notification.hash,
network: account.network,
currency: notification.currency || account.network, // TODO: how to catch token?
amount: notification.amount,
total: notification.total,
fee: notification.fee,
},
});
// todo: replace "send success" notification with link to explorer
}
// todo: get transaction history here
// console.warn("OnBlAccount", account);
// this event can be triggered multiple times

View File

@ -13,6 +13,7 @@ import type {
PromiseAction,
} from 'flowtype';
const DECIMALS: number = 6;
export const subscribe = (network: string): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
const accounts: Array<string> = getState().accounts.filter(a => a.network === network).map(a => a.address);
@ -22,7 +23,6 @@ export const subscribe = (network: string): PromiseAction<void> => async (dispat
});
};
export const onBlockMined = (network: string): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
const fee = await TrezorConnect.blockchainGetFee({
coin: network,
@ -51,15 +51,22 @@ export const onNotification = (payload: $ElementType<BlockchainNotification, 'pa
type: PENDING.ADD,
payload: {
type: notification.type,
address: account.address,
deviceState: account.deviceState,
sequence: account.sequence,
inputs: notification.inputs,
outputs: notification.outputs,
sequence: notification.sequence,
hash: notification.hash,
network: account.network,
address: account.address,
currency: account.network,
amount: notification.amount,
total: notification.amount,
fee: notification.fee,
// amount: notification.amount,
// fee: notification.fee,
amount: toDecimalAmount(notification.amount, DECIMALS),
total: notification.type === 'send' ? toDecimalAmount(notification.total, DECIMALS) : toDecimalAmount(notification.amount, DECIMALS),
fee: toDecimalAmount(notification.fee, DECIMALS),
},
});
@ -83,8 +90,8 @@ export const onNotification = (payload: $ElementType<BlockchainNotification, 'pa
dispatch(AccountsActions.update({
...account,
balance: toDecimalAmount(updatedAccount.payload.balance, 6),
availableDevice: toDecimalAmount(updatedAccount.payload.availableBalance, 6),
balance: toDecimalAmount(updatedAccount.payload.balance, DECIMALS),
availableDevice: toDecimalAmount(updatedAccount.payload.availableBalance, DECIMALS),
block: updatedAccount.payload.block,
sequence: updatedAccount.payload.sequence,
}));