From bab5007847869002d68e1950f0f0335d867be22b Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Tue, 18 Dec 2018 22:10:20 +0100 Subject: [PATCH] call PENDING.ADD from BlockbookActions --- src/actions/ethereum/BlockchainActions.js | 35 +++++++++++++++++++++-- src/actions/ripple/BlockchainActions.js | 23 +++++++++------ 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/actions/ethereum/BlockchainActions.js b/src/actions/ethereum/BlockchainActions.js index fc27ce05..0a209433 100644 --- a/src/actions/ethereum/BlockchainActions.js +++ b/src/actions/ethereum/BlockchainActions.js @@ -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 => async (dis } }; -export const onNotification = (/*network: string*/): PromiseAction => async (): Promise => { +export const onNotification = (payload: $ElementType): PromiseAction => async (dispatch: Dispatch, getState: GetState): Promise => { + 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 diff --git a/src/actions/ripple/BlockchainActions.js b/src/actions/ripple/BlockchainActions.js index 3091c461..12915d8f 100644 --- a/src/actions/ripple/BlockchainActions.js +++ b/src/actions/ripple/BlockchainActions.js @@ -13,6 +13,7 @@ import type { PromiseAction, } from 'flowtype'; +const DECIMALS: number = 6; export const subscribe = (network: string): PromiseAction => async (dispatch: Dispatch, getState: GetState): Promise => { const accounts: Array = getState().accounts.filter(a => a.network === network).map(a => a.address); @@ -22,7 +23,6 @@ export const subscribe = (network: string): PromiseAction => async (dispat }); }; - export const onBlockMined = (network: string): PromiseAction => async (dispatch: Dispatch, getState: GetState): Promise => { const fee = await TrezorConnect.blockchainGetFee({ coin: network, @@ -51,15 +51,22 @@ export const onNotification = (payload: $ElementType