Skip to content

Commit

Permalink
feat(sell): fetch, paginate and display swap and sb txs into single t…
Browse files Browse the repository at this point in the history
…x list
  • Loading branch information
schnogz committed Dec 6, 2020
1 parent 7b4250e commit 88726a5
Show file tree
Hide file tree
Showing 14 changed files with 298 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type MessagesType = {
'buttons.contact_support': 'Contact Support'
'buttons.continue': 'Continue'
'buttons.deposit': 'Deposit'
'buttons.deposited': 'Deposited'
'buttons.done': 'Done'
'buttons.go_back': 'Go Back'
'buttons.hide': 'Hide'
Expand Down Expand Up @@ -52,6 +53,7 @@ type MessagesType = {
'buttons.verify_now': 'Verify Now'
'buttons.viewstatus': 'View Status'
'buttons.withdraw': 'Withdraw'
'buttons.withdrew': 'Withdrew'
'buttons.withdraw_value': 'Withdraw {value}'
'components.DateInputBox.placeholder.month': 'Month'
'components.EmailVerification.changeemail': 'Change Email'
Expand Down Expand Up @@ -346,6 +348,7 @@ type MessagesType = {
'copy.private_key': 'Private Key'
'copy.refunded': 'Refunded'
'copy.select_swap_wallets': 'Select the Wallet you want to Swap from and the crypto you want to receive.'
'copy.sold': 'Sold'
'copy.suggested': 'Suggested'
'copy.swap': 'Swap'
'copy.swap_account_from_error': 'You cannot swap between these types of accounts. Try changing the From account.'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Text } from 'blockchain-info-components'
import { FormattedMessage } from 'react-intl'
import React, { useState } from 'react'

import { CoinTypeEnum, FiatSBAndSwapTransactionType } from 'core/types'
import { Text } from 'blockchain-info-components'

import {
Addresses,
Col,
Expand All @@ -15,17 +18,14 @@ import {
TxRow,
TxRowContainer
} from '../components'
import { CoinTypeEnum, SBTransactionType } from 'core/types'

import {
DepositOrWithdrawal,
Destination,
IconTx,
Origin,
Status,
Timestamp
Timestamp,
TransactionType
} from './model'
import { FormattedMessage } from 'react-intl'
import { Props as OwnProps } from '../TransactionList'

const CustodialTxListItem: React.FC<Props> = props => {
Expand All @@ -43,7 +43,7 @@ const CustodialTxListItem: React.FC<Props> = props => {
weight={600}
data-e2e='txTypeText'
>
<DepositOrWithdrawal {...props} /> {props.tx.amount.symbol}
<TransactionType {...props} /> {props.tx.amount.symbol}
</Text>
<Timestamp {...props} />
</StatusAndType>
Expand All @@ -52,12 +52,12 @@ const CustodialTxListItem: React.FC<Props> = props => {
<Addresses
from={
<>
{props.tx.amount.symbol} <Origin {...props} />
<Origin {...props} />
</>
}
to={
<>
{props.tx.amount.symbol} <Destination {...props} />
<Destination {...props} />
</>
}
/>
Expand Down Expand Up @@ -117,7 +117,7 @@ const CustodialTxListItem: React.FC<Props> = props => {
}

export type Props = OwnProps & {
tx: SBTransactionType
tx: FiatSBAndSwapTransactionType
}

export default CustodialTxListItem
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ const Icon = styled(BCIcon)`

export const IconTx = (props: Props) => {
switch (props.tx.state) {
case 'FINISHED':
return (
<IconWrapper color='fiat-light'>
<Icon size='20px' color='fiat' name='plus' />
</IconWrapper>
)
case 'COMPLETE':
return props.coin in WalletFiatEnum ? (
<IconWrapper color='fiat-light'>
Expand Down Expand Up @@ -72,6 +78,7 @@ export const Timestamp = (props: Props) => {
const getTimeOrStatus = () => {
switch (props.tx.state) {
case 'COMPLETE':
case 'FINISHED':
return <SharedTimestamp time={props.tx.insertedAt} />
default:
return <Status {...props} />
Expand All @@ -91,7 +98,7 @@ export const Timestamp = (props: Props) => {
)
}

export const DepositOrWithdrawal = (props: Props) => {
export const TransactionType = (props: Props) => {
if (props.tx.amount.symbol in CoinTypeEnum) {
switch (props.tx.type) {
case 'DEPOSIT':
Expand All @@ -110,19 +117,23 @@ export const DepositOrWithdrawal = (props: Props) => {
)
case 'REFUNDED':
return <FormattedMessage id='copy.refunded' defaultMessage='Refunded' />
case 'SELL':
return <FormattedMessage id='copy.sold' defaultMessage='Sold' />
}
} else {
switch (props.tx.type) {
case 'DEPOSIT':
return (
<FormattedMessage id='buttons.deposit' defaultMessage='Deposit' />
<FormattedMessage id='buttons.deposited' defaultMessage='Deposited' />
)
case 'REFUNDED':
return <FormattedMessage id='copy.refunded' defaultMessage='Refunded' />
case 'SELL':
return <FormattedMessage id='copy.sold' defaultMessage='Sold' />
case 'WITHDRAWAL':
return (
<FormattedMessage id='buttons.withdraw' defaultMessage='Withdraw' />
<FormattedMessage id='buttons.withdrew' defaultMessage='Withdrew' />
)
case 'REFUNDED':
return <FormattedMessage id='copy.refunded' defaultMessage='Refunded' />
}
}
}
Expand All @@ -131,37 +142,45 @@ export const Origin = (props: Props) => {
switch (props.tx.type) {
case 'REFUNDED':
case 'DEPOSIT':
if (props.tx.amount.symbol in CoinTypeEnum) {
return <>Wallet</>
}

return <>Bank Account</>
return props.tx.amount.symbol in CoinTypeEnum ? (
<>{props.coinTicker} Wallet</>
) : (
<>Bank Account</>
)
case 'SELL':
return props.tx.extraAttributes ? (
<>{props.tx.amount.symbol} Wallet</>
) : (
<>{props.tx.amount.symbol} Trading Wallet</>
)
case 'WITHDRAWAL':
return <>Trading Wallet</>
return <>{props.coinTicker} Wallet</>
}
}

export const Destination = (props: Props) => {
switch (props.tx.type) {
case 'REFUNDED':
case 'DEPOSIT':
return <>Trading Wallet</>
return <>{props.coinTicker} Wallet</>
case 'SELL':
return <>{props.coinTicker} Wallet</>
case 'WITHDRAWAL':
if (props.tx.amount.symbol in CoinTypeEnum) {
return <>Wallet</>
}

return <>Bank Account</>
return props.tx.amount.symbol in CoinTypeEnum ? (
<>{props.tx.amount.symbol} Wallet</>
) : (
<>Bank Account</>
)
}
}

export const Status = (props: Props) => {
switch (props.tx.state) {
case 'COMPLETE':
case 'FINISHED':
if (
props.tx.amount.symbol in CoinTypeEnum &&
props.tx.extraAttributes !== null &&
'confirmations' in props.tx.extraAttributes
props.tx.extraAttributes?.confirmations
) {
return (
<Confirmations
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
CoinType,
FiatSBAndSwapTransactionType,
FiatType,
ProcessedTxType,
RemoteDataType,
Expand Down Expand Up @@ -49,7 +50,10 @@ class TransactionList extends PureComponent<Props> {
) : 'pair' in tx ? (
<SimpleBuyListItem order={tx} />
) : (
<CustodialTxListItem tx={tx} {...this.props} />
<CustodialTxListItem
tx={tx as FiatSBAndSwapTransactionType}
{...this.props}
/>
)
})}
</TransactionsWrapper>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { ProcessedTxType, SBOrderType, SBTransactionType } from 'core/types'
import {
FiatSBAndSwapTransactionType,
ProcessedTxType,
SBOrderType,
SBTransactionType
} from 'core/types'

export type TransferType = 'sent' | 'received' | 'transferred' | ''
export type TxType = SBTransactionType | SBOrderType | ProcessedTxType
export type TxType =
| SBTransactionType
| SBOrderType
| ProcessedTxType
| FiatSBAndSwapTransactionType
26 changes: 20 additions & 6 deletions packages/blockchain-wallet-v4/src/network/api/simpleBuy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,25 @@ export default ({
}
})

const getSBTransactions = (
currency: WalletCurrencyType,
next?: string | null,
limit?: string,
type?: 'DEPOSIT' | 'WITHDRAWAL',
type getSBTransactionsType = {
currency: WalletCurrencyType
fromId?: string
fromValue?: string
limit?: number
next?: string | null
state?: SBTransactionStateType
): SBTransactionsType =>
type?: 'DEPOSIT' | 'WITHDRAWAL'
}

const getSBTransactions = ({
currency,
fromId,
fromValue,
limit,
next,
state,
type
}: getSBTransactionsType): SBTransactionsType =>
next
? authorizedGet({
url: nabuUrl,
Expand All @@ -250,6 +262,8 @@ export default ({
data: {
currency,
limit,
fromId,
fromValue,
pending: true,
product: 'SIMPLEBUY',
state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export type SBTransactionType = {
status: 'UNCONFIRMED' | 'CONFIRMED'
txHash: string
}
type: 'DEPOSIT' | 'REFUNDED'
type: 'DEPOSIT' | 'REFUNDED' | 'SELL'
}
| {
extraAttributes: null | {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ export default ({ api }: { api: APIType }) => {
offset > 0 && !nextSBTransactionsURL
? yield { prev: null, next: null, items: [] }
: // get transactions whether or not nextSBTransactionsURL is null
yield call(api.getSBTransactions, currency, nextSBTransactionsURL)
yield call(api.getSBTransactions, {
currency,
next: nextSBTransactionsURL
})

const pendingTxsOnState = S.getSBTransactionsPending(
yield select(),
Expand Down
24 changes: 24 additions & 0 deletions packages/blockchain-wallet-v4/src/redux/data/custodial/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as AT from './actionTypes'
import {
ProcessedSwapOrderType,
SBOrderType,
SBTransactionStateType,
SBTransactionType,
WalletCurrencyType
} from 'core/types'
Expand Down Expand Up @@ -29,3 +30,26 @@ interface SetNextSBTransactionsURL {
}

export type SBCoreActionTypes = SetNextSBTransactionsURL

// 🚨 TEMP HACK 🚨
// TODO: remove once we have unified custodial transaction endpoints
export type FiatSBAndSwapTransactionType = {
amount: { symbol: WalletCurrencyType; value: string }
amountMinor: string
extraAttributes: null | {
address: string
amount: {
[key in WalletCurrencyType]: number
}
confirmations: number
dsr: number
hash: string
id: string
status: 'UNCONFIRMED' | 'CONFIRMED'
txHash: string
}
id: string
insertedAt: string
state: SBTransactionStateType | 'FINISHED'
type: 'DEPOSIT' | 'WITHDRAWAL' | 'REFUNDED' | 'SELL'
}
7 changes: 4 additions & 3 deletions packages/blockchain-wallet-v4/src/redux/data/fiat/actions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { WalletFiatType } from 'core/types'

import * as AT from './actionTypes'
import { FiatActionTypes } from './types'
import { SBTransactionsType, WalletFiatType } from 'core/types'
import { FiatActionTypes, FiatTransactionPageResponseType } from './types'

// FETCH_FIAT_TRANSACTIONS
export const fetchTransactions = (
Expand All @@ -26,7 +27,7 @@ export const fetchTransactionsLoading = (
})
export const fetchTransactionsSuccess = (
currency: WalletFiatType,
response: SBTransactionsType,
response: FiatTransactionPageResponseType,
reset?: boolean
): FiatActionTypes => ({
type: AT.FETCH_FIAT_TRANSACTIONS_SUCCESS,
Expand Down

0 comments on commit 88726a5

Please sign in to comment.