Skip to content

Commit 68253e7

Browse files
committed
Add Zcash buy/sell support with Banxa
Add ZEC to CURRENCY_PLUGINID_MAP in the Banxa ramp plugin to enable Zcash buy/sell when supported by Banxa's API.
1 parent 26eb994 commit 68253e7

2 files changed

Lines changed: 23 additions & 12 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased (develop)
44

5+
- added: Zcash buy/sell support with Banxa
6+
57
## 4.41.0 (staging)
68

79
- changed: Replace `currencyCode` usage with `EdgeTokenId` throughout the app

‎src/plugins/ramps/banxa/banxaRampPlugin.ts‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ const CURRENCY_PLUGINID_MAP: Record<string, string> = {
307307
TON: 'ton',
308308
XLM: 'stellar',
309309
XRP: 'ripple',
310-
XTZ: 'tezos'
310+
XTZ: 'tezos',
311+
ZEC: 'zcash'
311312
}
312313

313314
const COIN_TO_CURRENCY_CODE_MAP: StringMap = { BTC: 'BTC' }
@@ -1206,16 +1207,24 @@ export const banxaRampPlugin: RampPluginFactory = (
12061207
)
12071208
return
12081209
}
1209-
// Prefer segwit where available; fallback to default public address
1210+
// Prefer transparent or segwit address where available; fallback to default
12101211
const addresses = await coreWallet.getAddresses({ tokenId: null })
1211-
const [defaultAddress] = addresses
1212-
if (defaultAddress == null)
1213-
throw new Error('Banxa missing receive address')
1214-
const segwitAddress = addresses.find(
1215-
row => row.addressType === 'segwitAddress'
1212+
const getAddressTypePriority = (
1213+
type: string | undefined
1214+
): number => {
1215+
if (type === 'transparentAddress') return 1
1216+
if (type === 'segwitAddress') return 1
1217+
return 2
1218+
}
1219+
// Sort addresses by priority
1220+
addresses.sort(
1221+
(a, b) =>
1222+
getAddressTypePriority(a.addressType) -
1223+
getAddressTypePriority(b.addressType)
12161224
)
1217-
const receivePublicAddress =
1218-
segwitAddress?.publicAddress ?? defaultAddress.publicAddress
1225+
const [receiveAddress] = addresses
1226+
if (receiveAddress == null)
1227+
throw new Error('Banxa missing receive address')
12191228

12201229
const bodyParams: any = {
12211230
payment_method_id: paymentObj?.id ?? '',
@@ -1240,13 +1249,13 @@ export const banxaRampPlugin: RampPluginFactory = (
12401249
if (testnet && banxaChain === 'BTC') {
12411250
bodyParams.wallet_address = TESTNET_ADDRESS
12421251
} else {
1243-
bodyParams.wallet_address = receivePublicAddress
1252+
bodyParams.wallet_address = receiveAddress.publicAddress
12441253
}
12451254
} else {
12461255
if (testnet && banxaChain === 'BTC') {
12471256
bodyParams.refund_address = TESTNET_ADDRESS
12481257
} else {
1249-
bodyParams.refund_address = receivePublicAddress
1258+
bodyParams.refund_address = receiveAddress.publicAddress
12501259
}
12511260
}
12521261

@@ -1482,7 +1491,7 @@ export const banxaRampPlugin: RampPluginFactory = (
14821491
// Post the txid back to Banxa
14831492
const bodyParams = {
14841493
tx_hash: txid,
1485-
source_address: receivePublicAddress,
1494+
source_address: receiveAddress.publicAddress,
14861495
destination_address: publicAddress
14871496
}
14881497
await banxaFetch({

0 commit comments

Comments
 (0)