Skip to content

Commit

Permalink
feat(interest): custodial account deposits
Browse files Browse the repository at this point in the history
  • Loading branch information
schnogz committed Nov 16, 2020
1 parent cbe704a commit 68146eb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,23 @@ export default ({
prop('type', formValues.interestDepositAccount) === 'CUSTODIAL'

yield put(A.setPaymentLoading())
// custodial deposit
yield put(actions.form.change(DEPOSIT_FORM, 'depositAmount', undefined))
yield put(actions.form.focus(DEPOSIT_FORM, 'depositAmount'))

if (isCustodialDeposit) {
custodialBalances = (yield select(
selectors.components.simpleBuy.getSBBalances
)).getOrFail('Failed to get balance')
}

depositPayment = yield call(createPayment, {
...formValues.interestDepositAccount,
address: getAccountIndexOrAccount(
coin,
formValues.interestDepositAccount
)
})

yield call(createLimits, depositPayment, custodialBalances)
yield put(A.setPaymentSuccess(depositPayment))
}
Expand Down Expand Up @@ -366,15 +370,14 @@ export default ({
)
if (isCustodialDeposit) {
const { amount } = payment.value()
const amountString = amount && amount[0].toString()
// custodial deposit
yield call(
// @ts-ignore
api.initiateCustodialTransfer,
amount && amount[0].toString(),
coin,
'SAVINGS',
'SIMPLEBUY'
)
yield call(api.initiateCustodialTransfer, {
amount: amountString as string,
currency: coin,
destination: 'SAVINGS',
origin: 'SIMPLEBUY'
})
} else {
// non-custodial deposit
yield call(fetchInterestAccount, coin)
Expand Down Expand Up @@ -402,7 +405,7 @@ export default ({
yield put(
actions.analytics.logEvent(INTEREST_EVENTS.DEPOSIT.SEND_SUCCESS)
)
yield delay(2500)
yield delay(3000)
yield put(A.fetchInterestBalance())
yield put(actions.router.push('/interest/history'))
} catch (e) {
Expand Down
15 changes: 3 additions & 12 deletions packages/blockchain-wallet-v4/src/network/api/custodial/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
BeneficiariesType,
BeneficiaryType,
CustodialProductType,
CustodialTransferRequestType,
NabuCustodialProductType,
PaymentDepositPendingResponseType,
WithdrawalLockCheckResponseType,
Expand Down Expand Up @@ -84,22 +85,12 @@ export default ({ authorizedGet, authorizedPost, nabuUrl }) => {
}
})

const initiateCustodialTransfer = (
amount: string,
currency: CoinType,
destination: NabuCustodialProductType,
origin: NabuCustodialProductType
) =>
const initiateCustodialTransfer = (request: CustodialTransferRequestType) =>
authorizedPost({
url: nabuUrl,
endPoint: '/custodial/transfer',
contentType: 'application/json',
data: {
amount,
currency,
destination,
origin
}
data: request
})

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,10 @@ type WithdrawalLockCheckRule = {
export type WithdrawalLockCheckResponseType = {
rule?: WithdrawalLockCheckRule
}

export type CustodialTransferRequestType = {
amount: string
currency: CoinType
destination: NabuCustodialProductType
origin: NabuCustodialProductType
}

0 comments on commit 68146eb

Please sign in to comment.