Skip to content

Commit

Permalink
feat(interest): enable deposits of ERC20
Browse files Browse the repository at this point in the history
  • Loading branch information
schnogz committed Jul 17, 2020
1 parent 47e75cb commit 015d757
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
Expand Up @@ -57,6 +57,10 @@ export default ({ coreSagas, networks }) => {
const coin = prop('coin', source)
const addressOrIndex = prop('address', source)
const addressType = prop('type', source)
const erc20List = (yield select(
selectors.core.walletOptions.getErc20CoinList
)).getOrElse([])
isSourceErc20 = includes(coin, erc20List)
const [network, provisionalScript] = isSourceErc20
? ethOptions
: prop(coin, {
Expand Down
Expand Up @@ -172,14 +172,21 @@ export default ({
const value = isDisplayed
? new BigNumber(action.payload).toNumber()
: new BigNumber(action.payload).dividedBy(rate).toNumber()
const getAccountIndexOrAccount = coin => {
switch (coin) {
case 'ETH':
case 'PAX':
case 'USDT':
return values.interestDepositAccount.address
default:
return values.interestDepositAccount.index
}
}
let provisionalPayment: PaymentValue = yield call(
calculateProvisionalPayment,
{
...values.interestDepositAccount,
address:
coin === 'ETH'
? values.interestDepositAccount.address
: values.interestDepositAccount.index
address: getAccountIndexOrAccount(coin)
},
value
)
Expand Down Expand Up @@ -260,7 +267,6 @@ export default ({
)
yield put(A.setWithdrawalMinimimumsLoading())
yield put(A.setWithdrawalMinimimumsSuccess(response))
// setWithdrawalMinimimumsSuccess init form for analytics
} catch (e) {
const error = errorHandler(e)
yield put(A.setWithdrawalMinimimumsFailure(error))
Expand Down
@@ -1,21 +1,24 @@
import * as A from './actions'
import * as S from './selectors'
import { ADDRESS_TYPES } from 'blockchain-wallet-v4/src/redux/payment/btc/utils'
import { call, CallEffect, put, select } from 'redux-saga/effects'
import { includes } from 'ramda'

import { ADDRESS_TYPES } from 'blockchain-wallet-v4/src/redux/payment/btc/utils'
import {
CoinType,
FiatType,
PaymentType,
PaymentValue,
RemoteDataType
} from 'core/types'
import { convertBaseToStandard } from '../exchange/services'
import { Exchange } from 'blockchain-wallet-v4/src'
import { INVALID_COIN_TYPE } from 'blockchain-wallet-v4/src/model'
import { promptForSecondPassword } from 'services/SagaService'
import { RatesType } from '../borrow/types'
import { selectors } from 'data'

import * as A from './actions'
import * as S from './selectors'
import { convertBaseToStandard } from '../exchange/services'
import { RatesType } from '../borrow/types'

export default ({ coreSagas, networks }: { coreSagas: any; networks: any }) => {
const buildAndPublishPayment = function * (
coin: CoinType,
Expand Down Expand Up @@ -117,33 +120,30 @@ export default ({ coreSagas, networks }: { coreSagas: any; networks: any }) => {
}
}

const createPayment = function * (index?: number) {
const createPayment = function * (accountIndex?: number) {
let payment
const coin = S.getCoinType(yield select())
const erc20List = (yield select(
selectors.core.walletOptions.getErc20CoinList
)).getOrElse([])
const isErc20 = includes(coin, erc20List)

switch (coin) {
case 'BTC':
payment = coreSagas.payment.btc.create({
network: networks.btc
})
payment = yield payment.init()
payment = yield payment.from(index, ADDRESS_TYPES.ACCOUNT)
payment = yield payment.from(accountIndex, ADDRESS_TYPES.ACCOUNT)
payment = yield payment.fee('regular')
break
case 'ETH':
payment = coreSagas.payment.eth.create({
network: networks.eth
})
payment = yield payment.init({ isErc20: false, coin })
payment = yield payment.from()
payment = yield payment.fee('priority')
break
case 'USDT':
case 'PAX':
payment = coreSagas.payment.eth.create({
network: networks.eth
})
payment = yield payment.init({ isErc20: true, coin })
payment = yield payment.init({ isErc20, coin })
payment = yield payment.from()
payment = yield payment.fee('priority')
break
Expand Down

0 comments on commit 015d757

Please sign in to comment.