Skip to content

Commit

Permalink
feat(simple buy): add txs to all coin tx lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip London committed Mar 24, 2020
1 parent b125fa7 commit 235b0f2
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { merge } from 'ramda'

export default ({ rootUrl, apiUrl, get, post }) => {
const fetchBchData = (context, { n = 50, offset = 0, onlyShow } = {}) => {
const fetchBchData = (
context,
{ n = 50, offset = 0, onlyShow = false } = {}
) => {
const data = {
active: (Array.isArray(context) ? context : [context]).join('|'),
format: 'json',
Expand Down
4 changes: 3 additions & 1 deletion packages/blockchain-wallet-v4/src/network/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ const api = ({
export default api

export type APIType = ReturnType<typeof borrow> &
ReturnType<typeof bch> &
ReturnType<typeof btc> &
ReturnType<typeof misc> &
ReturnType<typeof simpleBuy> &
ReturnType<typeof wallet>
ReturnType<typeof wallet> &
ReturnType<typeof xlm>
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ export default ({ apiUrl, horizonUrl, network, get }) => {
publicKey,
limit,
pagingToken,
reset,
reset = false,
order = 'desc'
}: {
limit?: number
order?: string
pagingToken?: string
publicKey: string
reset?: boolean
}) => {
const txCallBuilder = server
.transactions()
Expand All @@ -60,6 +66,7 @@ export default ({ apiUrl, horizonUrl, network, get }) => {
.then(
compose(
head,
// @ts-ignore
prop('records')
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ describe('bch data sagas', () => {
.next(bchFetchData)
.call(dataBchSagas.__processTxs, bchFetchData.txs)
.next(processedTxs)
.put(A.fetchTransactionsSuccess(processedTxs, payload.reset))
.next()
// .put(A.fetchTransactionsSuccess(processedTxs, payload.reset))
})

it('should finish', () => {
Expand Down
21 changes: 17 additions & 4 deletions packages/blockchain-wallet-v4/src/redux/data/bch/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@ import * as selectors from '../../selectors'
import * as transactions from '../../../transactions'
import * as walletSelectors from '../../wallet/selectors'
import { addFromToAccountNames } from '../../../utils/accounts'
import { APIType } from 'core/network/api'
import {
BCH_FORK_TIME,
convertFromCashAddrIfCashAddr,
TX_PER_PAGE
} from '../../../utils/bch'
import { BchTxType } from 'core/transactions/types'
import { call, put, select, take } from 'redux-saga/effects'
import { errorHandler, MISSING_WALLET } from '../../../utils'
import { flatten, indexBy, length, map, path, prop } from 'ramda'
import { getAccountsList, getBchTxNotes } from '../../kvStore/bch/selectors'
import { getLockboxBchAccounts } from '../../kvStore/lockbox/selectors'
import { HDAccountList } from '../../../types'
import { indexBy, length, map, path, prop } from 'ramda'
import { HDAccountList, SBOrderType } from '../../../types'
import moment from 'moment'
import Remote from '../../../remote'
import simpleBuySagas from '../simpleBuy/sagas'

const transformTx = transactions.bch.transformTx

export default ({ api }) => {
export default ({ api }: { api: APIType }) => {
const { fetchSBOrders } = simpleBuySagas({ api })

const fetchData = function * () {
try {
yield put(A.fetchDataLoading())
Expand Down Expand Up @@ -75,7 +80,15 @@ export default ({ api }) => {
const filteredTxs = data.txs.filter(tx => tx.time > BCH_FORK_TIME)
const atBounds = length(filteredTxs) < TX_PER_PAGE
yield put(A.transactionsAtBound(atBounds))
const page = yield call(__processTxs, filteredTxs)
const txPage: Array<BchTxType> = yield call(__processTxs, filteredTxs)
const sbPage: Array<SBOrderType> = yield call(
fetchSBOrders,
txPage,
offset
)
const page = flatten([txPage, sbPage]).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))
Expand Down
15 changes: 14 additions & 1 deletion packages/blockchain-wallet-v4/src/redux/data/eth/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { call, put, select, take } from 'redux-saga/effects'
import { errorHandler } from '../../../utils'
import { EthTxType } from 'core/transactions/types'
import { getLockboxEthContext } from '../../kvStore/lockbox/selectors'
import { SBOrderType } from 'core/types'
import BigNumber from 'bignumber.js'
import moment from 'moment'
import simpleBuySagas from '../simpleBuy/sagas'
Expand Down Expand Up @@ -290,7 +291,19 @@ export default ({ api }) => {
if (isNil(txs)) return
const atBounds = length(txs) < TX_PER_PAGE
yield put(A.erc20TransactionsAtBound(token, atBounds))
const page = yield call(__processErc20Txs, txs, token)
const walletPage: Array<EthTxType> = yield call(
__processErc20Txs,
txs,
token
)
const sbPage: Array<SBOrderType> = yield call(
fetchSBOrders,
walletPage,
nextPage
)
const page = flatten([walletPage, sbPage]).sort((a, b) => {
return moment(b.insertedAt).valueOf() - moment(a.insertedAt).valueOf()
})
yield put(A.fetchErc20TransactionsSuccess(token, page, reset))
} catch (e) {
yield put(A.fetchErc20TransactionsFailure(token, e.message))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ export default ({ api }: { api: APIType }) => {
let after // ⏫
let before // ⏬

// if offset is 0 get transactions from after the oldestTx
// if offset === 0 get transactions from after the oldestTx
// if offset === 0 and no transactions get all before and after
// if offset > 0 get transactions before the latestTx
// if offset > 0 get transactions after the oldestTx
// if no transactions get all before and after
// if offset > 0 and no transactions return []
// if any error is thrown return []
if (offset === 0) {
if (oldestTx) {
after = moment(oldestTx.insertedAt).toISOString()
}
} else {
if (!page[0]) return []
if (latestTx) {
before = moment(latestTx.insertedAt).toISOString()
}
Expand All @@ -35,6 +38,7 @@ export default ({ api }: { api: APIType }) => {
return yield call(api.getSBOrders, { before, after })
} catch (e) {
// no simple buy transactions
return []
}
}

Expand Down
28 changes: 20 additions & 8 deletions packages/blockchain-wallet-v4/src/redux/data/xlm/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
concat,
equals,
filter,
flatten,
join,
last,
length,
Expand All @@ -22,12 +23,16 @@ import {
values
} from 'ramda'
import { all, call, put, select } from 'redux-saga/effects'
import { APIType } from 'core/network/api'
import { getAccounts, getXlmTxNotes } from '../../kvStore/xlm/selectors'
import { getLockboxXlmAccounts } from '../../kvStore/lockbox/selectors'
import { SBOrderType } from 'core/types'
import { xlm } from '../../../transactions'
import { XlmTxType } from 'core/transactions/types'
import BigNumber from 'bignumber.js'
import moment from 'moment'
import Remote from '../../../remote'
import simpleBuySagas from '../simpleBuy/sagas'

const { transformTx, decodeOperations, isLumenOperation } = xlm

Expand All @@ -49,7 +54,9 @@ const sumBalance = compose(
values
)

export default ({ api, networks }) => {
export default ({ api, networks }: { api: APIType; networks: any }) => {
const { fetchSBOrders } = simpleBuySagas({ api })

const fetchLedgerDetails = function * () {
try {
yield put(A.setLedgerDetailsLoading())
Expand Down Expand Up @@ -111,21 +118,28 @@ export default ({ api, networks }) => {
.map(last)
.map(prop('pagingToken'))
.getOrElse(null)
const offset = reset ? null : length(pages) * TX_PER_PAGE
const offset = reset ? 0 : length(pages) * TX_PER_PAGE
const transactionsAtBound = yield select(S.getTransactionsAtBound)
if (Remote.Loading.is(last(pages))) return
if (transactionsAtBound && !reset) return
yield put(A.fetchTransactionsLoading(reset))
const txs = yield call(api.getXlmTransactions, {
publicKey,
limit: TX_PER_PAGE,
cursor: offset,
pagingToken,
reset
})
const atBounds = length(txs) < TX_PER_PAGE
yield put(A.transactionsAtBound(atBounds))
const page = yield call(__processTxs, txs)
const txPage: Array<XlmTxType> = yield call(__processTxs, txs)
const sbPage: Array<SBOrderType> = yield call(
fetchSBOrders,
txPage,
offset
)
const page = flatten([txPage, sbPage]).sort((a, b) => {
return moment(b.insertedAt).valueOf() - moment(a.insertedAt).valueOf()
})
yield put(A.fetchTransactionsSuccess(page, reset))
} catch (e) {
const statusCode = path(['response', 'status'], e)
Expand All @@ -141,14 +155,13 @@ export default ({ api, networks }) => {
const fetchTransactionHistory = function * ({ payload }) {
const { address, start, end } = payload
let currentPage = 0
let pagingToken = null
let pagingToken

try {
yield put(A.fetchTransactionHistoryLoading())
let fullTxList = yield call(api.getXlmTransactions, {
publicKey: address,
limit: TX_REPORT_PAGE_SIZE,
cursor: currentPage
limit: TX_REPORT_PAGE_SIZE
})
currentPage++
// @ts-ignore
Expand All @@ -161,7 +174,6 @@ export default ({ api, networks }) => {
const txPage = yield call(api.getXlmTransactions, {
publicKey: address,
limit: TX_REPORT_PAGE_SIZE,
cursor: currentPage * TX_REPORT_PAGE_SIZE,
pagingToken
})
// exit if no results returned
Expand Down
1 change: 1 addition & 0 deletions packages/blockchain-wallet-v4/src/transactions/bch.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ export const _transformTx = (wallet, accountList, txNotes, tx) => {
amount: computeAmount(type, inputData, outputData),
type: toLower(type),
time: tx.time,
insertedAt: tx.time * 1000,
timeFormatted: getTime(tx),
fee: Remote.Success(tx.fee),
inputs: inputs,
Expand Down
7 changes: 5 additions & 2 deletions packages/blockchain-wallet-v4/src/transactions/eth.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,18 @@ export const getErc20Label = (address, token, state) => {

export const _transformErc20Tx = curry((addresses, state, token, tx) => {
const type = toLower(getType(tx, addresses))
const time = tx.timestamp || tx.timeStamp

return {
amount: parseInt(tx.value),
blockHeight: tx.blockNumber,
description: getErc20TxNote(state, token, tx.transactionHash).getOrElse(''),
fee: Remote.NotAsked,
from: getErc20Label(tx.from, token, state),
hash: tx.transactionHash,
timeFormatted: getTime(tx.timestamp),
time: tx.timestamp,
timeFormatted: getTime(time),
insertedAt: Number(time) * 1000,
time,
to: getErc20Label(tx.to, token, state),
type
}
Expand Down
17 changes: 16 additions & 1 deletion packages/blockchain-wallet-v4/src/transactions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,20 @@ export type EthTxType = {
to: string
type: 'sent' | 'received' | 'transferred'
}
export type XlmTxType = {
amount: string
belongsToWallet: true
blockHeight: number
description: string
from: string
hash: string
insertedAt: number
memo: undefined
memoType: string
pagingToken: string
time: string
to: string
type: 'sent' | 'received' | 'transferred'
}

export type ProcessedTxType = BtcTxType | BchTxType | EthTxType
export type ProcessedTxType = BtcTxType | BchTxType | EthTxType | XlmTxType
1 change: 1 addition & 0 deletions packages/blockchain-wallet-v4/src/transactions/xlm.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const transformTx = curry((accounts, txNotes, tx, operation) => {
memo,
memoType,
time,
insertedAt: Number(time) * 1000,
to: getLabel(accounts, to),
type,
pagingToken,
Expand Down

0 comments on commit 235b0f2

Please sign in to comment.