Skip to content

Commit

Permalink
feat(download transactions): fixed issue with imported BTC address
Browse files Browse the repository at this point in the history
  • Loading branch information
milan-bc committed Dec 2, 2021
1 parent e73bcad commit d24d52b
Showing 1 changed file with 58 additions and 55 deletions.
113 changes: 58 additions & 55 deletions packages/blockchain-wallet-v4/src/redux/data/btc/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,63 +40,14 @@ export default ({ api }: { api: APIType }) => {
yield put(A.fetchDataFailure(errorHandler(e)))
}
}

const watchTransactions = function* () {
while (true) {
const action = yield take(AT.FETCH_BTC_TRANSACTIONS)
yield call(fetchTransactions, action)
}
}

const fetchTransactions = function* (action) {
try {
const { payload } = action
const { address, filter, reset } = payload
const pages = yield select(S.getTransactions)
const offset = reset ? 0 : length(pages) * TX_PER_PAGE
const transactionsAtBound = yield select(S.getTransactionsAtBound)
if (transactionsAtBound && !reset) return
yield put(A.fetchTransactionsLoading(reset))
const context = yield select(S.getContext)
const walletContext = yield select(S.getWalletContext)
const data = yield call(
api.fetchBlockchainData,
context,
{
n: TX_PER_PAGE,
offset,
onlyShow: address || concat(walletContext.legacy, walletContext.bech32 || [])
},
filter
)
const atBounds = length(data.txs) < TX_PER_PAGE
yield put(A.transactionsAtBound(atBounds))
const txPage: Array<ProcessedTxType> = yield call(__processTxs, data.txs)
const nextBSTransactionsURL = selectors.data.custodial.getNextBSTransactionsURL(
yield select(),
'BTC'
)
const custodialPage: FetchCustodialOrdersAndTransactionsReturnType = yield call(
fetchCustodialOrdersAndTransactions,
txPage,
offset,
atBounds,
'BTC',
reset ? null : nextBSTransactionsURL
)
const page = flatten([txPage, custodialPage.orders]).sort((a, b) => {
return moment(b.insertedAt).valueOf() - moment(a.insertedAt).valueOf()
})
yield put(A.fetchTransactionsSuccess(page, reset))
} catch (e) {
yield put(A.fetchTransactionsFailure(e.message))
}
}

const fetchTransactionHistory = function* ({ payload }) {
const { address, end, start } = payload
const bech32Address = address.find((add) => prop('type', add) === 'bech32')
const legacyAddress = address.find((add) => prop('type', add) === 'legacy')
const bech32Address = Array.isArray(address)
? address.find((add) => prop('type', add) === 'bech32')
: address
const legacyAddress = Array.isArray(address)
? address.find((add) => prop('type', add) === 'legacy')
: address
const startDate = moment(start).format('DD/MM/YYYY')
const endDate = moment(end).format('DD/MM/YYYY')
try {
Expand Down Expand Up @@ -159,6 +110,58 @@ export default ({ api }: { api: APIType }) => {
return ProcessTxs(walletR, accountListR, txs, txNotes, addressLabels)
}

const fetchTransactions = function* (action) {
try {
const { payload } = action
const { address, filter, reset } = payload
const pages = yield select(S.getTransactions)
const offset = reset ? 0 : length(pages) * TX_PER_PAGE
const transactionsAtBound = yield select(S.getTransactionsAtBound)
if (transactionsAtBound && !reset) return
yield put(A.fetchTransactionsLoading(reset))
const context = yield select(S.getContext)
const walletContext = yield select(S.getWalletContext)
const data = yield call(
api.fetchBlockchainData,
context,
{
n: TX_PER_PAGE,
offset,
onlyShow: address || concat(walletContext.legacy, walletContext.bech32 || [])
},
filter
)
const atBounds = length(data.txs) < TX_PER_PAGE
yield put(A.transactionsAtBound(atBounds))
const txPage: Array<ProcessedTxType> = yield call(__processTxs, data.txs)
const nextBSTransactionsURL = selectors.data.custodial.getNextBSTransactionsURL(
yield select(),
'BTC'
)
const custodialPage: FetchCustodialOrdersAndTransactionsReturnType = yield call(
fetchCustodialOrdersAndTransactions,
txPage,
offset,
atBounds,
'BTC',
reset ? null : nextBSTransactionsURL
)
const page = flatten([txPage, custodialPage.orders]).sort((a, b) => {
return moment(b.insertedAt).valueOf() - moment(a.insertedAt).valueOf()
})
yield put(A.fetchTransactionsSuccess(page, reset))
} catch (e) {
yield put(A.fetchTransactionsFailure(e.message))
}
}

const watchTransactions = function* () {
while (true) {
const action = yield take(AT.FETCH_BTC_TRANSACTIONS)
yield call(fetchTransactions, action)
}
}

const fetchFiatAtTime = function* (action) {
const { amount, currency, hash, time } = action.payload
try {
Expand Down

0 comments on commit d24d52b

Please sign in to comment.