Skip to content

Commit

Permalink
feat(send): withdrawal fees xlm, erc20
Browse files Browse the repository at this point in the history
  • Loading branch information
plondon committed Apr 21, 2021
1 parent 8e99378 commit c8b3e6e
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,19 @@ export default ({
'DEFAULT'
)
const fee =
response.fees.find(({ symbol }) => symbol === 'ETH')
response.fees.find(({ symbol }) => symbol === coin)
?.minorValue || '0'
source = fromPayload.label
payment = yield payment.from(
source,
fromPayload.type,
new BigNumber(fromPayload.withdrawable).minus(fee).toString()
)
payment = yield payment.fee(new BigNumber(fee).toNumber(), '')
payment = yield payment.fee(
new BigNumber(fee).toNumber(),
'',
coin
)
yield put(A.sendEthPaymentUpdatedSuccess(payment.value()))
yield put(change(FORM, 'to', null))
break
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import BigNumber from 'bignumber.js'
import { equals, head, includes, last, path, pathOr, prop, propOr } from 'ramda'
import {
change,
Expand Down Expand Up @@ -127,7 +128,16 @@ export default ({
const source = prop('address', payload) || payload
const fromType = prop('type', payload)
if (fromType === 'CUSTODIAL') {
payment = yield call(setFrom, payment, payload, fromType)
const response: ReturnType<typeof api.getWithdrawalFees> = yield call(
api.getWithdrawalFees,
'mercury',
'DEFAULT'
)
const fee =
response.fees.find(({ symbol }) => symbol === 'XLM')
?.minorValue || '0'
payment = yield call(setFrom, payment, payload, fromType, fee)
payment = yield payment.fee(fee)
yield put(A.paymentUpdatedSuccess(payment.value()))
yield put(change(FORM, 'to', null))
} else {
Expand Down Expand Up @@ -388,7 +398,8 @@ export default ({
const setFrom = function * (
payment: XlmPaymentType,
from?: string | CustodialFromType,
type?: AddressTypesType
type?: AddressTypesType,
fee?: string
) {
let updatedPayment
try {
Expand All @@ -400,7 +411,9 @@ export default ({
payment.from,
fromCustodialT.label,
type,
fromCustodialT.withdrawable
new BigNumber(fromCustodialT.withdrawable)
.minus(fee || '0')
.toString()
)
break
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ const FirstStep = props => {
defaultMessage='Network Fee'
/>
</FormLabel>
<ComboDisplay size='13px' weight={600} coin='ETH'>
<ComboDisplay size='13px' weight={600} coin={coin}>
{fee}
</ComboDisplay>
</FeeFormGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,23 +301,21 @@ const FirstStep = props => {
/>
</FormItem>
</FormGroup>
{!isFromCustody && (
<FormGroup inline margin={'10px'}>
<FormItem>
<Text size='16px' weight={500}>
<FormattedMessage
id='modals.sendxlm.firststep.fee'
defaultMessage='Transaction Fee:'
/>
</Text>
<Text>
<ComboDisplay size='13px' coin='XLM' weight={500}>
{fee}
</ComboDisplay>
</Text>
</FormItem>
</FormGroup>
)}
<FormGroup inline margin={'10px'}>
<FormItem>
<Text size='16px' weight={500}>
<FormattedMessage
id='modals.sendxlm.firststep.fee'
defaultMessage='Transaction Fee:'
/>
</Text>
<Text>
<ComboDisplay size='13px' coin='XLM' weight={500}>
{fee}
</ComboDisplay>
</Text>
</FormItem>
</FormGroup>
{isFromCustody && !isMnemonicVerified ? (
<MnemonicRequiredForCustodySend />
) : null}
Expand Down
8 changes: 4 additions & 4 deletions packages/blockchain-wallet-v4/src/redux/payment/eth/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,15 @@ export default ({ api }) => {
)
},

* fee(value, origin) {
* fee(value, origin, coin) {
let contract
let account = origin

if (p.from && p.from.type === 'CUSTODIAL') {
const feeInGwei = Exchange.convertEtherToEther({
const feeInGwei = Exchange.convertCoinToCoin({
value,
fromUnit: 'WEI',
toUnit: 'GWEI'
baseToStandard: true,
coin
}).value

return makePayment(
Expand Down
7 changes: 6 additions & 1 deletion packages/blockchain-wallet-v4/src/redux/payment/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ export type EthPaymentType = IPaymentType & {
amount: (n: number | string) => EthPaymentType
coin: 'ETH' | 'PAX' | 'USDT' | 'WDGLD' | 'YFI' | 'AAVE'
description: (arg: string) => EthPaymentType
fee: (arg: number, account: string) => EthPaymentType
fee: (
arg: number,
account: string,
coin?: Erc20CoinType | 'ETH'
) => EthPaymentType
init: (arg: {
coin: 'ETH' | Erc20CoinType
isErc20?: boolean
Expand All @@ -124,6 +128,7 @@ export type XlmPaymentType = IPaymentType & {
amount: (n: number | string) => XlmPaymentType
coin: 'XLM'
description: (arg: string) => XlmPaymentType
fee: (arg: string) => XlmPaymentType
memo: (arg: string) => XlmPaymentType
memoType: (arg: string) => XlmPaymentType
value: () => XlmPaymentValue
Expand Down
8 changes: 8 additions & 0 deletions packages/blockchain-wallet-v4/src/redux/payment/xlm/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ export default ({ api }) => {
},

* fee(value) {
if (p.from && p.from.type === 'CUSTODIAL') {
return makePayment(
merge(p, {
fee: value
})
)
}

const fee = yield call(calculateFee, value, prop('fees', p))
return makePayment(merge(p, { fee }))
},
Expand Down

0 comments on commit c8b3e6e

Please sign in to comment.