Browse Source

Fix LibcoreBridge#synchronize to be properly unsubscribed

master
Gaëtan Renaudeau 7 years ago
parent
commit
36698c5856
  1. 28
      src/bridge/LibcoreBridge.js

28
src/bridge/LibcoreBridge.js

@ -1,9 +1,8 @@
// @flow
import React from 'react'
import { BigNumber } from 'bignumber.js'
import { Observable } from 'rxjs'
import LRU from 'lru-cache'
import { map } from 'rxjs/operators'
import LRU from 'lru-cache'
import type { Account } from '@ledgerhq/live-common/lib/types'
import { decodeAccount, encodeAccount } from 'reducers/accounts'
import FeesBitcoinKind from 'components/FeesField/BitcoinKind'
@ -121,18 +120,10 @@ const LibcoreBridge: WalletBridge<Transaction> = {
},
synchronize: account =>
Observable.create(o => {
// FIXME TODO:
// - when you implement addPendingOperation you also here need to:
// - if there were pendingOperations that are now in operations, remove them as well.
// - if there are pendingOperations that is older than a threshold (that depends on blockchain speed typically)
// then we probably should trash them out? it's a complex question for UI
;(async () => {
try {
const rawAccount = encodeAccount(account)
const rawSyncedAccount = await libcoreSyncAccount.send({ rawAccount }).toPromise()
libcoreSyncAccount.send({ rawAccount: encodeAccount(account) }).pipe(
map(rawSyncedAccount => {
const syncedAccount = decodeAccount(rawSyncedAccount)
o.next(account => {
return account => {
const accountOps = account.operations
const syncedOps = syncedAccount.operations
const patch: $Shape<Account> = {
@ -161,18 +152,9 @@ const LibcoreBridge: WalletBridge<Transaction> = {
...account,
...patch,
}
})
o.complete()
} catch (e) {
o.error(e)
}
})()
return {
unsubscribe() {
// LibcoreBridge: unsub sync not currently implemented
},
}
}),
),
pullMoreOperations: () => Promise.reject(notImplemented),

Loading…
Cancel
Save