mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-28 03:08:30 +00:00
call PENDING.ADD from BlockbookActions
This commit is contained in:
parent
cbc0151a62
commit
bab5007847
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import TrezorConnect from 'trezor-connect';
|
import TrezorConnect from 'trezor-connect';
|
||||||
import BigNumber from 'bignumber.js';
|
import BigNumber from 'bignumber.js';
|
||||||
|
import * as PENDING from 'actions/constants/pendingTx';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
TrezorDevice,
|
TrezorDevice,
|
||||||
@ -9,7 +10,7 @@ import type {
|
|||||||
GetState,
|
GetState,
|
||||||
PromiseAction,
|
PromiseAction,
|
||||||
} from 'flowtype';
|
} from 'flowtype';
|
||||||
import type { EthereumAccount } from 'trezor-connect';
|
import type { EthereumAccount, BlockchainNotification } from 'trezor-connect';
|
||||||
import type { Token } from 'reducers/TokensReducer';
|
import type { Token } from 'reducers/TokensReducer';
|
||||||
import type { NetworkToken } from 'reducers/LocalStorageReducer';
|
import type { NetworkToken } from 'reducers/LocalStorageReducer';
|
||||||
import * as Web3Actions from 'actions/Web3Actions';
|
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
|
// todo: get transaction history here
|
||||||
// console.warn("OnBlAccount", account);
|
// console.warn("OnBlAccount", account);
|
||||||
// this event can be triggered multiple times
|
// this event can be triggered multiple times
|
||||||
|
@ -13,6 +13,7 @@ import type {
|
|||||||
PromiseAction,
|
PromiseAction,
|
||||||
} from 'flowtype';
|
} from 'flowtype';
|
||||||
|
|
||||||
|
const DECIMALS: number = 6;
|
||||||
|
|
||||||
export const subscribe = (network: string): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
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);
|
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> => {
|
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,
|
||||||
@ -51,15 +51,22 @@ export const onNotification = (payload: $ElementType<BlockchainNotification, 'pa
|
|||||||
type: PENDING.ADD,
|
type: PENDING.ADD,
|
||||||
payload: {
|
payload: {
|
||||||
type: notification.type,
|
type: notification.type,
|
||||||
|
address: account.address,
|
||||||
deviceState: account.deviceState,
|
deviceState: account.deviceState,
|
||||||
sequence: account.sequence,
|
|
||||||
|
inputs: notification.inputs,
|
||||||
|
outputs: notification.outputs,
|
||||||
|
|
||||||
|
sequence: notification.sequence,
|
||||||
hash: notification.hash,
|
hash: notification.hash,
|
||||||
network: account.network,
|
network: account.network,
|
||||||
address: account.address,
|
|
||||||
currency: account.network,
|
currency: account.network,
|
||||||
amount: notification.amount,
|
// amount: notification.amount,
|
||||||
total: notification.amount,
|
// fee: notification.fee,
|
||||||
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({
|
dispatch(AccountsActions.update({
|
||||||
...account,
|
...account,
|
||||||
balance: toDecimalAmount(updatedAccount.payload.balance, 6),
|
balance: toDecimalAmount(updatedAccount.payload.balance, DECIMALS),
|
||||||
availableDevice: toDecimalAmount(updatedAccount.payload.availableBalance, 6),
|
availableDevice: toDecimalAmount(updatedAccount.payload.availableBalance, DECIMALS),
|
||||||
block: updatedAccount.payload.block,
|
block: updatedAccount.payload.block,
|
||||||
sequence: updatedAccount.payload.sequence,
|
sequence: updatedAccount.payload.sequence,
|
||||||
}));
|
}));
|
||||||
|
Loading…
Reference in New Issue
Block a user