Skip to content

Commit

Permalink
feat(request): add extras for request comp
Browse files Browse the repository at this point in the history
  • Loading branch information
plondon committed Apr 15, 2021
1 parent 23eaf0e commit 3178189
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 29 deletions.
1 change: 1 addition & 0 deletions config/mocks/wallet-options-v4.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
"GBQ6RTEHEHXFPKSWCIM4KSVQXBANLFMVV6FJIZDLTF3ZOGFHTBDZUYDD"
],
"hasLockboxSupport": true,
"isMemoBased": true,
"learnMoreLink": "https://support.blockchain.com/hc/en-us/articles/360019105171-What-is-Stellar-",
"minConfirmations": 1,
"txExplorerBaseUrl": "https://stellarchain.io/tx",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SwapAccountType } from '../swap/types'
import * as AT from './actionTypes'
import { RequestActionTypes } from './types'
import { RequestActionTypes, RequestExtrasType } from './types'

export const getNextAddress = (account: SwapAccountType) => ({
type: AT.GET_NEXT_ADDRESS,
Expand All @@ -19,8 +19,9 @@ export const getNextAddressFailure = (
})
export const getNextAddressSuccess = (
key: string,
address: string
address: string,
extras: RequestExtrasType
): RequestActionTypes => ({
type: AT.GET_NEXT_ADDRESS_SUCCESS,
payload: { key, address }
payload: { key, address, extras }
})
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export function requestReducer(
case AT.GET_NEXT_ADDRESS_SUCCESS:
return {
...state,
[action.payload.key]: Remote.Success(action.payload.address)
[action.payload.key]: Remote.Success({
address: action.payload.address,
extras: action.payload.extras
})
}
default:
return state
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import { call, CallEffect, put, PutEffect } from 'redux-saga/effects'
import {
call,
CallEffect,
put,
PutEffect,
select,
SelectEffect
} from 'redux-saga/effects'

import { APIType } from 'blockchain-wallet-v4/src/network/api'
import { errorHandler } from 'blockchain-wallet-v4/src/utils'
import { SupportedWalletCurrenciesType } from 'core/types'
import { selectors } from 'data'

import coinSagas from '../../coins/sagas'
import profileSagas from '../../modules/profile/sagas'
import * as A from './actions'
import { RequestExtrasType } from './types'
import { generateKey } from './utils'

export default ({
Expand All @@ -26,26 +36,36 @@ export default ({

const getNextAddress = function * (
action: ReturnType<typeof A.getNextAddress>
): Generator<CallEffect | PutEffect, void, any> {
): Generator<CallEffect | PutEffect | SelectEffect, void, any> {
const key = generateKey(action.payload.account)
const supportedCoins = selectors.core.walletOptions
.getSupportedCoins(yield select())
.getOrElse({} as SupportedWalletCurrenciesType)
try {
yield put(A.getNextAddressLoading(key))
let address
if (action.payload.account.type === 'CUSTODIAL') {
waitForUserData()
const custodial: ReturnType<typeof api.getSBPaymentAccount> = yield call(
api.getSBPaymentAccount,
action.payload.account.coin
)
address = custodial.address
}
let extras: RequestExtrasType = {}
const account = action.payload.account

if (action.payload.account.type === 'ACCOUNT') {
const { accountIndex, coin } = action.payload.account
address = yield call(getNextReceiveAddressForCoin, coin, accountIndex)
switch (account.type) {
case 'ACCOUNT':
const { accountIndex, coin } = account
address = yield call(getNextReceiveAddressForCoin, coin, accountIndex)
break
case 'CUSTODIAL':
waitForUserData()
const custodial: ReturnType<typeof api.getSBPaymentAccount> = yield call(
api.getSBPaymentAccount,
account.coin
)
address = custodial.address
if (supportedCoins[account.coin].isMemoBased) {
address = address.split(':')[0]
extras.Memo = address.split(':')[1]
}
}

yield put(A.getNextAddressSuccess(key, address))
yield put(A.getNextAddressSuccess(key, address, extras))
} catch (e) {
const error = errorHandler(e)
yield put(A.getNextAddressFailure(key, error))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ export type RequestState = {
'BTC Private Key Wallet': Remote.Success<"18sikQNP236uPKRtUMrUF8H2vwv9CKbKfP">
}
*/
[key in string]: RemoteDataType<any, string>
[key in string]: RemoteDataType<
string,
{ address: string; extras: RequestExtrasType }
>
}

export type RequestExtrasType = { [key in string]: string }

interface GetNextAddressFailureActionType {
payload: {
error: string
Expand All @@ -28,6 +33,7 @@ interface GetNextAddressLoadingActionType {
interface GetNextAddressSuccessActionType {
payload: {
address: string
extras: RequestExtrasType
key: string
}
type: typeof AT.GET_NEXT_ADDRESS_SUCCESS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { REQUEST_ACCOUNTS_SELECTOR } from 'data/coins/model/request'
import { getCoinAccounts } from 'data/coins/selectors'
import { CoinAccountSelectorType } from 'data/coins/types'
import { SwapAccountType } from 'data/components/swap/types'
import { UserDataType } from 'data/types'

export const getData = createDeepEqualSelector(
[
Expand All @@ -16,19 +15,16 @@ export const getData = createDeepEqualSelector(
...REQUEST_ACCOUNTS_SELECTOR
} as CoinAccountSelectorType),
selectors.core.walletOptions.getAllCoinAvailabilities,
selectors.modules.profile.getUserData,
selectors.modules.profile.isSilverOrAbove,
(state, ownProps) => ({ ownProps, state })
],
(accounts, coinAvailabilitiesR, userDataR, { ownProps }) => {
(accounts, coinAvailabilitiesR, isSilverOrAbove, { ownProps }) => {
const { selectedCoin } = ownProps?.formValues || {}
const coinAvailabilities = coinAvailabilitiesR.getOrFail(
'No available coins.'
)
const prunedAccounts = [] as Array<SwapAccountType>
const userData = userDataR.getOrElse({
tiers: { current: 0, next: 0, selected: 0 }
} as UserDataType)
const isAtLeastTier1 = userData.tiers.current >= 1
const isAtLeastTier1 = isSilverOrAbove

// @ts-ignore
map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class RequestShowAddress extends React.PureComponent<Props> {
</Text>
<Text color='grey800' size='16px' weight={600} lineHeight='24px'>
{this.props.addressR.cata({
Success: val => val,
Success: val => val.address,
Failure: err => (
<FormattedMessage
id='components.alerts.unknown_error'
Expand All @@ -145,7 +145,7 @@ class RequestShowAddress extends React.PureComponent<Props> {
{this.props.addressR.cata({
Success: val => (
<CopyClipboardButton
textToCopy={val}
textToCopy={val.address}
color='blue600'
size='24px'
/>
Expand All @@ -156,13 +156,43 @@ class RequestShowAddress extends React.PureComponent<Props> {
})}
</ClipboardWrapper>
</AddressWrapper>
{this.props.addressR.cata({
Success: val =>
val.extras
? Object.keys(val.extras).map(extra => (
<AddressWrapper>
<AddressDisplay>
<Text
color='grey600'
size='14px'
lineHeight='21px'
weight={500}
>
{extra}
</Text>
<Text
color='grey800'
size='16px'
weight={600}
lineHeight='24px'
>
{val.extras[extra as string]}
</Text>
</AddressDisplay>
</AddressWrapper>
))
: null,
Failure: () => null,
Loading: () => null,
NotAsked: () => null
})}
<QRCodeContainer>
{this.props.addressR.cata({
Success: val => (
<QRCodeWrapper
data-e2e='requestAddressQrCode'
size={280}
value={val}
value={val.address}
/>
),
Failure: err => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type SupportedCoinType = {
displayName: string
hasLockboxSupport: boolean
invited?: boolean
isMemoBased?: boolean
learnMoreLink: string
method?: boolean
minConfirmations: number
Expand Down

0 comments on commit 3178189

Please sign in to comment.