Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: banxa doesn't work with testnets #2765

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/wallet-mobile/.env
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ WALLET_1_NETWORK_ID=300

WALLET_2_NETWORK_ID=300
WALLET_2_MNEMONIC=abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon share

BANXA_TEST_WALLET=addr1qyfuspldlchc5kechfe5jzdrr9jms2s9w0tq4hggy9zgkhxssydveuc8xyx4zh27fwcmr62mraeezjwf24hzkyejwfmq7yptmd
2 changes: 2 additions & 0 deletions apps/wallet-mobile/.env.nightly
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ COMMIT=cc2ffa0d
BUILD_VARIANT=NIGHTLY
SENTRY_DSN=https://59637d7dcb274b6a9e9f708e0082b3d5@o1138840.ingest.sentry.io/6260389
DISABLE_LOGBOX=true

BANXA_TEST_WALLET=addr1qyfuspldlchc5kechfe5jzdrr9jms2s9w0tq4hggy9zgkhxssydveuc8xyx4zh27fwcmr62mraeezjwf24hzkyejwfmq7yptmd
2 changes: 2 additions & 0 deletions apps/wallet-mobile/.env.staging
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ WALLET_1_NETWORK_ID=300

WALLET_2_NETWORK_ID=300
WALLET_2_MNEMONIC=abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon share

BANXA_TEST_WALLET=addr1qyfuspldlchc5kechfe5jzdrr9jms2s9w0tq4hggy9zgkhxssydveuc8xyx4zh27fwcmr62mraeezjwf24hzkyejwfmq7yptmd
5 changes: 4 additions & 1 deletion apps/wallet-mobile/src/TxHistory/ActionsBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {features} from '../features'
import {useSend} from '../features/Send/common/SendContext'
import {useSwapTouched} from '../features/Swap/common/SwapFormProvider'
import {actionMessages} from '../i18n/global-messages'
import env from '../legacy/env'
import {useMetrics} from '../metrics/metricsManager'
import {TxHistoryRouteNavigation} from '../navigation'
import {useSelectedWallet} from '../SelectedWallet'
Expand Down Expand Up @@ -39,8 +40,10 @@ export const ActionsBanner = ({disabled = false}: {disabled: boolean}) => {
})

const handleOnBuy = () => {
// banxa doesn't support testnet for the sandbox it needs a mainnet address
const sandboxWallet = env.getString('BANXA_TEST_WALLET')
const isMainnet = wallet.networkId !== 300
const walletAddress = wallet.externalAddresses[0]
const walletAddress = isMainnet ? wallet.externalAddresses[0] : sandboxWallet
const banxa = banxaModuleMaker({isProduction: isMainnet, partner: 'emurgo'})
const url = banxa.createReferralUrl({
coinType: 'ADA',
Expand Down
2 changes: 1 addition & 1 deletion apps/wallet-mobile/src/legacy/env.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BuildConfig from 'react-native-config'

const getString = (key: string) => BuildConfig[key]
const getString = (key: string) => BuildConfig[key] ?? ''

const getBoolean = (key: string, defaultValue: boolean) => {
const value = getString(key)
Expand Down
11 changes: 6 additions & 5 deletions packages/banxa/src/adapters/zod-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ export const BanxaUrlReferralQueryStringParamsSchema = z
walletAddress: z.string(),
walletAddressTag: z.string().optional(),
})
.refine(
(data) =>
data.coinType === 'ADA' &&
banxaIsPossibleCardanoAddress(data.walletAddress),
)
.refine((data) => {
return (
(data.coinType === 'ADA' || data.coinType === 'TADA') &&
banxaIsPossibleCardanoAddress(data.walletAddress)
)
})
12 changes: 6 additions & 6 deletions packages/banxa/src/helpers/wallet-address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import {banxaIsPossibleCardanoAddress} from './wallet-address'

describe('banxaIsPossibleCardanoAddress', () => {
// Test valid Byron addresses
test('should return true for valid Byron mainnet addresses', () => {
test('should return false for valid Byron mainnet addresses', () => {
expect(
banxaIsPossibleCardanoAddress(
'Ae2tdPwUPEZ5VwwZpNmy1ruH7mfmGv4JDqY4RiUZsMUTVDcsSsSh2Gu5noo',
),
).toBe(true)
).toBe(false)
expect(
banxaIsPossibleCardanoAddress(
'Ae2tdPwUPEZMK3H6mAmaSB1E4dGvcwRTe1tTkoSCNmQWBNxF6twLDwZoxt8',
),
).toBe(true)
).toBe(false)
})

// Test valid Shelley addresses
Expand All @@ -30,17 +30,17 @@ describe('banxaIsPossibleCardanoAddress', () => {
})

// Test valid Shelley testnet addresses
test('should return true for valid Shelley testnet addresses', () => {
test('should return false for valid Shelley testnet addresses', () => {
expect(
banxaIsPossibleCardanoAddress(
'addr_test1q9xwspw7mcmrhlzsp5v3xxvtzgqhp5tkmdt6zydu9evmvg28gr8v6svtefqgghsk93y4qqtv7kjeg5k06c8qxy4r89agqheknqv',
),
).toBe(true)
).toBe(false)
expect(
banxaIsPossibleCardanoAddress(
'addr_test1qqlzhn7wya6s2c3x6px63hklwt2ss9f8s0v5c90v6w8wtfl5mv6m2tckwqlyvlwmnx9ct68fqk7nngeja4kvz65prdrqudmm25h',
),
).toBe(true)
).toBe(false)
})

// Test invalid addresses
Expand Down
9 changes: 2 additions & 7 deletions packages/banxa/src/helpers/wallet-address.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
/**
* Validates if is possible Cardano mainnet or testnet address.
* We leave the address validation to the Banxa API, this is a simple check to avoid basic mistakes.
* Banxa referal link doesn't work with testnet addreses or byron addresses.
* @param {string} address - The Cardano address to validate.
* @returns {boolean} - Returns true if the address looks like a Cardano address.
*/
export function banxaIsPossibleCardanoAddress(address: string) {
const byronRegex = /^[Ae2][0-9A-Za-z]{57,58}$/
const shelleyRegex = /^(addr1)[0-9a-z]+$/
const shelleyTestnetRegex = /^(addr_test1)[0-9a-z]+$/
return (
byronRegex.test(address) ||
shelleyRegex.test(address) ||
shelleyTestnetRegex.test(address)
)
return shelleyRegex.test(address)
}