diff --git a/src/bridge/LibcoreBridge.js b/src/bridge/LibcoreBridge.js index 9e0ad063..9ac806ee 100644 --- a/src/bridge/LibcoreBridge.js +++ b/src/bridge/LibcoreBridge.js @@ -1,6 +1,7 @@ // @flow import React from 'react' import { map } from 'rxjs/operators' +import type { Account } from '@ledgerhq/live-common/lib/types' import { decodeAccount, encodeAccount } from 'reducers/accounts' import FeesBitcoinKind from 'components/FeesField/BitcoinKind' import libcoreScanAccounts from 'commands/libcoreScanAccounts' @@ -61,15 +62,31 @@ const LibcoreBridge: WalletBridge = { const rawAccount = encodeAccount(account) const rawSyncedAccount = await libcoreSyncAccount.send({ rawAccount }).toPromise() const syncedAccount = decodeAccount(rawSyncedAccount) - next(account => ({ - ...account, - freshAddress: syncedAccount.freshAddress, - freshAddressPath: syncedAccount.freshAddressPath, - balance: syncedAccount.balance, - blockHeight: syncedAccount.blockHeight, - operations: syncedAccount.operations, // TODO: is a simple replace enough? - lastSyncDate: new Date(), - })) + next(account => { + const accountOps = account.operations + const syncedOps = syncedAccount.operations + const patch: $Shape = { + freshAddress: syncedAccount.freshAddress, + freshAddressPath: syncedAccount.freshAddressPath, + balance: syncedAccount.balance, + blockHeight: syncedAccount.blockHeight, + lastSyncDate: new Date(), + } + + const hasChanged = + accountOps.length !== syncedOps.length || // size change, we do a full refresh for now... + (accountOps.length > 0 && syncedOps.length > 0 && accountOps[0].id !== syncedOps[0].id) // if same size, only check if the last item has changed. + + if (hasChanged) { + patch.operations = syncedAccount.operations + patch.pendingOperations = [] // For now, we assume a change will clean the pendings. + } + + return { + ...account, + ...patch, + } + }) complete() } catch (e) { error(e) @@ -136,6 +153,11 @@ const LibcoreBridge: WalletBridge = { return op }, + + addPendingOperation: (account, operation) => ({ + ...account, + pendingOperations: [operation].concat(account.pendingOperations), + }), } export default LibcoreBridge diff --git a/src/commands/libcoreSignAndBroadcast.js b/src/commands/libcoreSignAndBroadcast.js index 7823fe44..79ef35ec 100644 --- a/src/commands/libcoreSignAndBroadcast.js +++ b/src/commands/libcoreSignAndBroadcast.js @@ -105,7 +105,7 @@ export async function doSignAndBroadcast({ id: txHash, hash: txHash, type: 'OUT', - value: amount, + value: transaction.amount, fee: 0, blockHash: null, blockHeight: null,