From c1fdada46db3e451d39905dd1fccebf42728a164 Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Fri, 17 May 2019 17:17:00 +0200 Subject: [PATCH 1/5] pass block number to xrp's onBlockMined --- src/actions/BlockchainActions.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/actions/BlockchainActions.js b/src/actions/BlockchainActions.js index e2650ac9..da2d9c66 100644 --- a/src/actions/BlockchainActions.js +++ b/src/actions/BlockchainActions.js @@ -84,6 +84,7 @@ export const onBlockMined = ( payload: $ElementType ): PromiseAction => async (dispatch: Dispatch, getState: GetState): Promise => { const shortcut = payload.coin.shortcut.toLowerCase(); + const { block } = payload; if (getState().router.location.state.network !== shortcut) return; const { config } = getState().localStorage; @@ -95,7 +96,7 @@ export const onBlockMined = ( await dispatch(EthereumBlockchainActions.onBlockMined(shortcut)); break; case 'ripple': - await dispatch(RippleBlockchainActions.onBlockMined(shortcut)); + await dispatch(RippleBlockchainActions.onBlockMined(shortcut, block)); break; default: break; From 25548debd07c3eb5fea1d8f2244b0931c9cc1b5c Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Fri, 17 May 2019 17:17:46 +0200 Subject: [PATCH 2/5] comment about potential incorrect balance with contracts --- src/actions/ethereum/BlockchainActions.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/actions/ethereum/BlockchainActions.js b/src/actions/ethereum/BlockchainActions.js index ce61a1d4..928f1474 100644 --- a/src/actions/ethereum/BlockchainActions.js +++ b/src/actions/ethereum/BlockchainActions.js @@ -141,6 +141,9 @@ export const onBlockMined = (network: string): PromiseAction => async ( dispatch(Web3Actions.updateAccount(accounts[i], a, network)); } else { // there are no new txs, just update block + // TODO: There still could be internal transactions as a result of contract + // If that's the case, account balance won't be updated + // Currently waiting for deprecating web3 and utilising new blockbook dispatch(AccountsActions.update({ ...accounts[i], block: a.block })); // HACK: since blockbook can't work with smart contracts for now From 07371d6be7fec69e641eeaad543cdd3ce502b9a0 Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Fri, 17 May 2019 17:41:00 +0200 Subject: [PATCH 3/5] update accounts on each block --- src/actions/ripple/BlockchainActions.js | 83 +++++++++++++++++-------- 1 file changed, 57 insertions(+), 26 deletions(-) diff --git a/src/actions/ripple/BlockchainActions.js b/src/actions/ripple/BlockchainActions.js index f107595e..2ca6ce08 100644 --- a/src/actions/ripple/BlockchainActions.js +++ b/src/actions/ripple/BlockchainActions.js @@ -47,24 +47,24 @@ export const getFeeLevels = (network: Network): PayloadAction => async ( +export const onBlockMined = (networkShortcut: string, block: number): PromiseAction => async ( dispatch: Dispatch, getState: GetState ): Promise => { - const blockchain = getState().blockchain.find(b => b.shortcut === network); + const blockchain = getState().blockchain.find(b => b.shortcut === networkShortcut); if (!blockchain) return; // flowtype fallback // if last update was more than 5 minutes ago const now = new Date().getTime(); if (blockchain.feeTimestamp < now - 300000) { const feeRequest = await TrezorConnect.blockchainEstimateFee({ - coin: network, + coin: networkShortcut, }); if (feeRequest.success && observeChanges(blockchain.feeLevels, feeRequest.payload)) { // check if downloaded fee levels are different dispatch({ type: BLOCKCHAIN.UPDATE_FEE, - shortcut: network, + shortcut: networkShortcut, feeLevels: feeRequest.payload, }); } @@ -72,28 +72,59 @@ export const onBlockMined = (network: string): PromiseAction => async ( // TODO: check for blockchain rollbacks here! - const accounts: Array = getState().accounts.filter(a => a.network === network); - // console.warn('ACCOUNTS', accounts); - if (accounts.length > 0) { - // const response = await TrezorConnect.rippleGetAccountInfo({ - // bundle: accounts, - // level: 'transactions', - // coin: network, - // }); - // if (!response.success) return; - // response.payload.forEach((a, i) => { - // if (a.transactions.length > 0) { - // console.warn('APDEJTED!', a, i); - // dispatch(AccountsActions.update({ - // ...accounts[i], - // balance: toDecimalAmount(a.balance, DECIMALS), - // availableBalance: toDecimalAmount(a.availableBalance, DECIMALS), - // block: a.block, - // sequence: a.sequence, - // })); - // } - // }); - } + const accounts: Array = getState().accounts.filter(a => a.network === networkShortcut); + if (accounts.length === 0) return; + const { networks } = getState().localStorage.config; + const network = networks.find(c => c.shortcut === networkShortcut); + if (!network) return; + + // HACK: Since Connect always returns account.transactions as 0 + // we don't have info about new transactions for the account since last update. + // Untill there is a better solution compare accounts block. + // If we missed some blocks (wallet was offline) we'll update the account reducer + // If we are update to date with the last block that means wallet was online + // and we will get Blockchain notification about new transaction if needed + accounts.forEach(async account => { + const missingBlocks = account.block !== block - 1; + if (!missingBlocks) { + // account was last updated on account.block, current block is +1, we didn't miss single block + // if there was new tx, blockchain notification would let us know + // so just update the block for the account + dispatch( + AccountsActions.update({ + ...account, + block, + }) + ); + } else { + // we missed some blocks (wallet was offline). get updated account info from connect + const response = await TrezorConnect.rippleGetAccountInfo({ + account: { + descriptor: account.descriptor, + }, + level: 'transactions', + coin: networkShortcut, + }); + + if (!response.success) return; + + const updatedAccount = response.payload; + + // new txs + dispatch( + AccountsActions.update({ + ...account, + balance: toDecimalAmount(updatedAccount.balance, network.decimals), + availableBalance: toDecimalAmount( + updatedAccount.availableBalance, + network.decimals + ), + block: updatedAccount.block, + sequence: updatedAccount.sequence, + }) + ); + } + }); }; export const onNotification = ( From d334139a7b13216e20be5a9e40ac50b0302b6da5 Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Fri, 17 May 2019 18:06:41 +0200 Subject: [PATCH 4/5] run ci --- src/actions/ripple/BlockchainActions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actions/ripple/BlockchainActions.js b/src/actions/ripple/BlockchainActions.js index 2ca6ce08..73097713 100644 --- a/src/actions/ripple/BlockchainActions.js +++ b/src/actions/ripple/BlockchainActions.js @@ -83,7 +83,7 @@ export const onBlockMined = (networkShortcut: string, block: number): PromiseAct // Untill there is a better solution compare accounts block. // If we missed some blocks (wallet was offline) we'll update the account reducer // If we are update to date with the last block that means wallet was online - // and we will get Blockchain notification about new transaction if needed + // and we would get Blockchain notification about new transaction if needed accounts.forEach(async account => { const missingBlocks = account.block !== block - 1; if (!missingBlocks) { From a052b0230d7d129a9863af4ee1ca98e0ef368bce Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Fri, 17 May 2019 18:09:13 +0200 Subject: [PATCH 5/5] run ci run --- src/actions/ripple/BlockchainActions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actions/ripple/BlockchainActions.js b/src/actions/ripple/BlockchainActions.js index 73097713..2c42911b 100644 --- a/src/actions/ripple/BlockchainActions.js +++ b/src/actions/ripple/BlockchainActions.js @@ -81,7 +81,7 @@ export const onBlockMined = (networkShortcut: string, block: number): PromiseAct // HACK: Since Connect always returns account.transactions as 0 // we don't have info about new transactions for the account since last update. // Untill there is a better solution compare accounts block. - // If we missed some blocks (wallet was offline) we'll update the account reducer + // If we missed some blocks (wallet was offline) we'll update the account // If we are update to date with the last block that means wallet was online // and we would get Blockchain notification about new transaction if needed accounts.forEach(async account => {