Skip to content

Commit

Permalink
feat(send): withdrawal fees, btc only
Browse files Browse the repository at this point in the history
  • Loading branch information
plondon committed Apr 20, 2021
1 parent a2af623 commit 6b0f898
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,20 @@ export default ({
payment = yield payment.from(payloadT.xpub, fromType)
break
case 'CUSTODIAL':
const response: ReturnType<typeof api.getWithdrawalFees> = yield call(
api.getWithdrawalFees,
'mercury',
'DEFAULT'
)
const fee =
response.fees.find(({ symbol }) => symbol === 'BTC')
?.minorValue || '0'
payment = yield payment.from(
payloadT.label,
fromType,
payloadT.withdrawable
new BigNumber(payloadT.withdrawable).minus(fee).toString()
)
payment = yield payment.fee(new BigNumber(fee).toNumber())
yield put(A.sendBtcPaymentUpdatedSuccess(payment.value()))
yield put(change(FORM, 'to', null))
break
Expand Down Expand Up @@ -506,11 +515,14 @@ export default ({
const value = payment.value()
if (!value.to) return
if (!value.amount) return
if (!value.selection) return

yield call(
api.withdrawSBFunds,
value.to[0].address,
'BTC',
new BigNumber(value.amount[0]).toString()
new BigNumber(value.amount[0]).toString(),
value.selection.fee
)
} else {
const value = payment.value()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import styled from 'styled-components'
import { Icon, Image, Text } from 'blockchain-info-components'
import {
BeneficiaryType,
NabuMoneyFloatType
NabuSymbolNumberType
} from 'blockchain-wallet-v4/src/types'
import { AddNewButton } from 'components/Brokerage'
import { FlyoutWrapper } from 'components/Flyout'
Expand All @@ -19,7 +19,7 @@ type OwnProps = {
account: BankTransferAccountType | undefined
bankTransferAccounts: BankTransferAccountType[]
beneficiaries: BeneficiaryType[]
minAmount: NabuMoneyFloatType
minAmount: NabuSymbolNumberType
}
type Props = _P & OwnProps

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import styled from 'styled-components'
import { Button, HeartbeatLoader, Icon, Text } from 'blockchain-info-components'
import { displayFiatToFiat } from 'blockchain-wallet-v4/src/exchange'
import { fiatToString } from 'blockchain-wallet-v4/src/exchange/currency'
import { NabuMoneyFloatType } from 'blockchain-wallet-v4/src/types'
import { NabuSymbolNumberType } from 'blockchain-wallet-v4/src/types'
import { ErrorCartridge } from 'components/Cartridge'
import CoinDisplay from 'components/Display/CoinDisplay'
import { FlyoutWrapper, Row, Title, Value } from 'components/Flyout'
Expand Down Expand Up @@ -177,7 +177,7 @@ const Success: React.FC<InjectedFormProps<
)
}

export type Props = OwnProps & SuccessStateType & { fees: NabuMoneyFloatType }
export type Props = OwnProps & SuccessStateType & { fees: NabuSymbolNumberType }

export default reduxForm<WithdrawCheckoutFormValuesType, Props>({
form: 'confirmCustodyWithdraw',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { displayFiatToFiat } from 'blockchain-wallet-v4/src/exchange'
import Currencies from 'blockchain-wallet-v4/src/exchange/currencies'
import {
BeneficiaryType,
NabuMoneyFloatType
NabuSymbolNumberType
} from 'blockchain-wallet-v4/src/types'
import { BlueCartridge, ErrorCartridge } from 'components/Cartridge'
import CoinDisplay from 'components/Display/CoinDisplay'
Expand Down Expand Up @@ -363,7 +363,7 @@ export type Props = OwnProps &
userData: UserDataType,
beneficiary?: BeneficiaryType | BankTransferAccountType
) => void
minAmount: NabuMoneyFloatType
minAmount: NabuSymbolNumberType
}

export default reduxForm<WithdrawCheckoutFormValuesType, Props>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Icon } from 'blockchain-info-components'
import {
BeneficiaryType,
FiatType,
NabuMoneyFloatType
NabuSymbolNumberType
} from 'blockchain-wallet-v4/src/types'
import {
GreyCartridge,
Expand Down Expand Up @@ -99,7 +99,7 @@ const Bank = ({ bankDetails, icon, isActive, onClick, text }: BankProps) => (
type BankWireProps = {
beneficiary: BeneficiaryType
isActive?: boolean
minAmount?: NabuMoneyFloatType
minAmount?: NabuSymbolNumberType
onClick: () => void
type: 'DEPOSIT' | 'WITHDRAWAL'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,86 +286,84 @@ const FirstStep = props => {
)}
</FormItem>
</FormGroup>
{!isPayPro ? (
isFromCustody ? null : (
<>
<FeeFormGroup inline margin={'10px'}>
<ColLeft>
<FeeFormContainer toggled={feePerByteToggled}>
<FeeFormLabel>
<FormattedMessage
id='modals.sendbtc.firststep.networkfee'
defaultMessage='Network Fee'
{!isPayPro && !isFromCustody ? (
<>
<FeeFormGroup inline margin={'10px'}>
<ColLeft>
<FeeFormContainer toggled={feePerByteToggled}>
<FeeFormLabel>
<FormattedMessage
id='modals.sendbtc.firststep.networkfee'
defaultMessage='Network Fee'
/>
<span>&nbsp;</span>
{!feePerByteToggled && (
<Field
name='feePerByte'
component={SelectBox}
elements={feePerByteElements}
/>
<span>&nbsp;</span>
{!feePerByteToggled && (
<Field
name='feePerByte'
component={SelectBox}
elements={feePerByteElements}
/>
)}
{feePerByteToggled && (
<FeeOptionsContainer>
<RegularFeeLink fee={regularFeePerByte} />
<span>&nbsp;</span>
<PriorityFeeLink fee={priorityFeePerByte} />
</FeeOptionsContainer>
)}
</FeeFormLabel>
)}
{feePerByteToggled && (
<FeePerByteContainer style={{ marginTop: '10px' }}>
<Field
name='feePerByte'
component={NumberBoxDebounced}
validate={[required, minimumOneSatoshi]}
warn={[minimumFeePerByte, maximumFeePerByte]}
errorBottom
errorLeft
unit='sat/byte'
data-e2e='sendBtcCustomFeeInput'
/>
</FeePerByteContainer>
<FeeOptionsContainer>
<RegularFeeLink fee={regularFeePerByte} />
<span>&nbsp;</span>
<PriorityFeeLink fee={priorityFeePerByte} />
</FeeOptionsContainer>
)}
</FeeFormContainer>
</ColLeft>
<ColRight>
<ComboDisplay size='13px' weight={600} coin='BTC'>
{totalFee}
</ComboDisplay>
<Link
size='12px'
weight={400}
capitalize
onClick={handleFeePerByteToggle}
data-e2e='sendBtcCustomFeeLink'
>
{feePerByteToggled ? (
<FormattedMessage
id='buttons.cancel'
defaultMessage='Cancel'
</FeeFormLabel>
{feePerByteToggled && (
<FeePerByteContainer style={{ marginTop: '10px' }}>
<Field
name='feePerByte'
component={NumberBoxDebounced}
validate={[required, minimumOneSatoshi]}
warn={[minimumFeePerByte, maximumFeePerByte]}
errorBottom
errorLeft
unit='sat/byte'
data-e2e='sendBtcCustomFeeInput'
/>
) : (
<FormattedMessage
id='modals.sendbtc.firststep.customizefee'
defaultMessage='Customize Fee'
/>
)}
</Link>
</ColRight>
</FeeFormGroup>
{feePerByteToggled && (
<CustomFeeAlertBanner type='alert'>
<Text size='12px'>
</FeePerByteContainer>
)}
</FeeFormContainer>
</ColLeft>
<ColRight>
<ComboDisplay size='13px' weight={600} coin='BTC'>
{totalFee}
</ComboDisplay>
<Link
size='12px'
weight={400}
capitalize
onClick={handleFeePerByteToggle}
data-e2e='sendBtcCustomFeeLink'
>
{feePerByteToggled ? (
<FormattedMessage
id='modals.sendbtc.firststep.customfeeinfo'
defaultMessage='This feature is recommended for advanced users only. By choosing a custom fee, you risk overpaying or your transaction never being confirmed.'
id='buttons.cancel'
defaultMessage='Cancel'
/>
</Text>
</CustomFeeAlertBanner>
)}
</>
)
) : (
<FormattedMessage
id='modals.sendbtc.firststep.customizefee'
defaultMessage='Customize Fee'
/>
)}
</Link>
</ColRight>
</FeeFormGroup>
{feePerByteToggled && (
<CustomFeeAlertBanner type='alert'>
<Text size='12px'>
<FormattedMessage
id='modals.sendbtc.firststep.customfeeinfo'
defaultMessage='This feature is recommended for advanced users only. By choosing a custom fee, you risk overpaying or your transaction never being confirmed.'
/>
</Text>
</CustomFeeAlertBanner>
)}
</>
) : (
<FeeFormGroup margin={'10px'}>
<FormLabel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default ({ authorizedGet, authorizedPost, nabuUrl }) => {

const getWithdrawalFees = (
product: WithdrawalFeesProductType,
paymentMethod?: SBPaymentTypes | 'ALL'
paymentMethod?: SBPaymentTypes | 'DEFAULT' | 'ALL'
): WithdrawalMinsAndFeesResponse =>
authorizedGet({
url: nabuUrl,
Expand Down
12 changes: 9 additions & 3 deletions packages/blockchain-wallet-v4/src/network/api/custodial/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ export enum ProductTypes {

export type NabuCustodialProductType = keyof typeof ProductTypes

export type WithdrawalFeesProductType = 'simplebuy' | 'mercurial'
export type WithdrawalFeesProductType = 'simplebuy' | 'mercury'

export type NabuMoneyFloatType = {
symbol: CoinType | FiatType
value: string
}

export type NabuSymbolNumberType = {
minorValue: string
symbol: CoinType | FiatType
value: number
}

export type NabuCurrencyNumberType = {
currency: CoinType | FiatType
value: number
Expand Down Expand Up @@ -77,8 +83,8 @@ export type WithdrawResponseType = {

export type WithdrawalMinsAndFeesResponse = {
feeType: 'NETWORK'
fees: Array<NabuMoneyFloatType>
minAmounts: Array<NabuMoneyFloatType>
fees: Array<NabuSymbolNumberType>
minAmounts: Array<NabuSymbolNumberType>
}

export type WithdrawalLockCheckRule = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ export default ({
const withdrawSBFunds = (
address: string,
currency: keyof CurrenciesType,
amount: string
amount: string,
fee?: number
) =>
authorizedPost({
url: nabuUrl,
Expand All @@ -421,7 +422,8 @@ export default ({
data: {
address,
currency,
amount
amount,
fee
}
})

Expand Down
2 changes: 2 additions & 0 deletions packages/blockchain-wallet-v4/src/redux/payment/btc/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ export default ({ api }) => {
},

* fee(value) {
if (p.fromType === 'CUSTODIAL')
return makePayment(merge(p, { selection: { fee: value } }))
let fee = yield call(__calculateFee, value, prop('fees', p))
let effectiveBalance = yield call(__calculateEffectiveBalance, {
coins: prop('coins', p),
Expand Down

0 comments on commit 6b0f898

Please sign in to comment.