Skip to content

Commit 02ec9bb

Browse files
committed
fixup! Ramp plugin architecture
Fix Paybis plugin: - Use makeUuid() directly instead of edge-user prefix - Add explicit null checks (!x -> x == null) - Remove validateSupportRequest wrapper, inline validateRegion calls - Update checkAssetSupport to use EdgeAsset instead of separate pluginId/tokenId
1 parent 2ec2ed3 commit 02ec9bb

File tree

1 file changed

+29
-56
lines changed

1 file changed

+29
-56
lines changed

src/plugins/ramps/paybis/paybisRampPlugin.ts

Lines changed: 29 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import type { EdgeAsset, StringMap } from '../../../types/types'
3939
import { sha512HashAndSign } from '../../../util/crypto'
4040
import { CryptoAmount } from '../../../util/CryptoAmount'
4141
import { getCurrencyCodeMultiplier } from '../../../util/CurrencyInfoHelpers'
42+
import { makeUuid } from '../../../util/rnUtils'
4243
import { removeIsoPrefix } from '../../../util/utils'
4344
import {
4445
SendErrorBackPressed,
@@ -47,7 +48,6 @@ import {
4748
import type {
4849
FiatDirection,
4950
FiatPaymentType,
50-
FiatPluginRegionCode,
5151
SaveTxActionParams
5252
} from '../../gui/fiatPluginTypes'
5353
import type {
@@ -593,19 +593,12 @@ export const paybisRampPlugin: RampPluginFactory = (
593593
partnerUserId = await pluginConfig.store
594594
.getItem('partnerUserId')
595595
.catch(() => '')
596-
if (partnerUserId === '' && pluginConfig.makeUuid != null) {
597-
partnerUserId = await pluginConfig.makeUuid()
598-
await pluginConfig.store.setItem('partnerUserId', partnerUserId)
599-
} else if (partnerUserId === '') {
600-
partnerUserId = `edge-user-${Date.now()}-${Math.random()
601-
.toString(36)
602-
.substring(7)}`
596+
if (partnerUserId === '') {
597+
partnerUserId = await makeUuid()
603598
await pluginConfig.store.setItem('partnerUserId', partnerUserId)
604599
}
605600
} else {
606-
partnerUserId = `edge-user-${Date.now()}-${Math.random()
607-
.toString(36)
608-
.substring(7)}`
601+
partnerUserId = await makeUuid()
609602
}
610603

611604
state = {
@@ -629,37 +622,15 @@ export const paybisRampPlugin: RampPluginFactory = (
629622
}
630623
}
631624

632-
const validateSupportRequest = (
633-
regionCode?: FiatPluginRegionCode,
634-
countryCode?: string
635-
): { supported: false } | undefined => {
636-
// Check region restrictions
637-
if (regionCode != null) {
638-
try {
639-
validateRegion(pluginId, regionCode, SUPPORTED_REGIONS)
640-
} catch (error) {
641-
return { supported: false }
642-
}
643-
}
644-
645-
// Check country-specific restrictions
646-
if (countryCode === 'GB') {
647-
return { supported: false }
648-
}
649-
650-
return undefined
651-
}
652-
653625
const checkAssetSupport = (
654626
direction: FiatDirection,
655627
fiatCurrencyCode: string,
656-
cryptoPluginId: string,
657-
tokenId?: string | null
628+
asset: EdgeAsset
658629
): { supported: false } | undefined => {
659630
// Check if crypto is supported
660631
const paybisCc =
661-
EDGE_TO_PAYBIS_CURRENCY_MAP[`${cryptoPluginId}_${tokenId ?? ''}`]
662-
if (!paybisCc) {
632+
EDGE_TO_PAYBIS_CURRENCY_MAP[`${asset.pluginId}_${asset.tokenId ?? ''}`]
633+
if (paybisCc == null) {
663634
return { supported: false }
664635
}
665636

@@ -720,21 +691,20 @@ export const paybisRampPlugin: RampPluginFactory = (
720691
// Ensure assets are initialized for the direction
721692
await ensureAssetsInitialized(direction)
722693

723-
// Validate region and country restrictions
724-
const regionResult = validateSupportRequest(
725-
regionCode,
726-
regionCode.countryCode
727-
)
728-
if (regionResult != null) {
729-
return regionResult
694+
// Validate region restrictions
695+
if (regionCode != null) {
696+
try {
697+
validateRegion(pluginId, regionCode, SUPPORTED_REGIONS)
698+
} catch (error) {
699+
return { supported: false }
700+
}
730701
}
731702

732703
// Check asset support
733704
const assetResult = checkAssetSupport(
734705
direction,
735706
`iso:${fiatAsset.currencyCode}`,
736-
cryptoAsset.pluginId,
737-
cryptoAsset.tokenId
707+
cryptoAsset
738708
)
739709
if (assetResult != null) {
740710
return assetResult
@@ -754,7 +724,7 @@ export const paybisRampPlugin: RampPluginFactory = (
754724
request: RampQuoteRequest
755725
): Promise<RampQuoteResult[]> => {
756726
await ensureStateInitialized()
757-
if (!state) throw new Error('Plugin state not initialized')
727+
if (state == null) throw new Error('Plugin state not initialized')
758728

759729
const {
760730
amountType,
@@ -769,14 +739,14 @@ export const paybisRampPlugin: RampPluginFactory = (
769739
tokenId
770740
} = request
771741

772-
// Validate region and country restrictions using helper
773-
const regionResult = validateSupportRequest(
774-
regionCode,
775-
regionCode.countryCode
776-
)
777-
if (regionResult != null) {
778-
// Return empty array for unsupported regions
779-
return []
742+
// Validate region restrictions
743+
if (regionCode != null) {
744+
try {
745+
validateRegion(pluginId, regionCode, SUPPORTED_REGIONS)
746+
} catch (error) {
747+
// Return empty array for unsupported regions
748+
return []
749+
}
780750
}
781751

782752
// Initialize assets for the direction
@@ -820,11 +790,14 @@ export const paybisRampPlugin: RampPluginFactory = (
820790
const fiat = removeIsoPrefix(fiatCurrencyCode)
821791

822792
// Check asset support using helper
793+
const cryptoAsset: EdgeAsset = {
794+
pluginId: currencyPluginId,
795+
tokenId: tokenId ?? null
796+
}
823797
const assetResult = checkAssetSupport(
824798
direction,
825799
fiatCurrencyCode,
826-
currencyPluginId,
827-
tokenId
800+
cryptoAsset
828801
)
829802
if (assetResult != null) {
830803
// Return empty array for unsupported asset pairs

0 commit comments

Comments
 (0)