Skip to content

Commit

Permalink
[Rewards 3.0] Remove disabled wallet providers from connect modal
Browse files Browse the repository at this point in the history
  • Loading branch information
zenparsing committed Jan 13, 2025
1 parent efc41ce commit 18c32c9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
ExternalWalletProvider,
isSelfCustodyProvider,
getExternalWalletProviderName,
isExternalWalletProviderAllowed
isExternalWalletProviderAllowed,
isExternalWalletProviderDisabled
} from '../../shared/lib/external_wallet'

import * as routes from '../lib/app_routes'
Expand All @@ -37,7 +38,7 @@ export function ConnectAccount() {
const { getString } = useLocaleContext()
const wrapCallback = useCallbackWrapper()

const [
let [
countryCode,
regions,
providers,
Expand Down Expand Up @@ -65,6 +66,10 @@ export function ConnectAccount() {
}
}, [])

providers = providers.filter((name) => {
return !isExternalWalletProviderDisabled(regions && regions[name] || null)
})

function onBack() {
router.setRoute(routes.home)
}
Expand Down Expand Up @@ -160,10 +165,6 @@ export function ConnectAccount() {
}

function renderCustodialSection() {
if (!providers) {
return null
}

const entries = providers.filter((name) => !isSelfCustodyProvider(name))
if (entries.length === 0) {
return null
Expand Down Expand Up @@ -193,10 +194,6 @@ export function ConnectAccount() {
}

function renderSelfCustodySection() {
if (!providers) {
return null
}

const entries = providers.filter(isSelfCustodyProvider)
if (entries.length === 0) {
return null
Expand Down
26 changes: 20 additions & 6 deletions components/brave_rewards/resources/shared/lib/external_wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface ExternalWallet {
}

// Returns the external wallet provider name for the specified provider.
export function getExternalWalletProviderName (
export function getExternalWalletProviderName(
provider: ExternalWalletProvider
) {
switch (provider) {
Expand All @@ -34,7 +34,7 @@ export function getExternalWalletProviderName (
// |null| if the key is invalid. This function is provided for backward
// compatibility with code that does not yet use the |ExternalWalletProvider|
// type.
export function externalWalletProviderFromString (
export function externalWalletProviderFromString(
key: string
): ExternalWalletProvider | null {
switch (key) {
Expand All @@ -53,15 +53,15 @@ export function externalWalletProviderFromString (
// provider key, or the empty string if the key is not recognized. This function
// is provided for backward compatibility with code that does not yet use the
// |ExternalWalletProvider| type. Prefer |getExternalWalletProviderName|.
export function lookupExternalWalletProviderName (providerKey: string) {
export function lookupExternalWalletProviderName(providerKey: string) {
const provider = externalWalletProviderFromString(providerKey)
return provider ? getExternalWalletProviderName(provider) : ''
}

// Converts external wallet information returned from the `chrome.braveRewards`
// extension API into an |ExternalWallet| object, or |null| if the specified
// object cannot be converted.
export function externalWalletFromExtensionData (
export function externalWalletFromExtensionData(
data: any
): ExternalWallet | null {
if (!data || typeof data !== 'object') {
Expand All @@ -88,7 +88,7 @@ export interface ExternalWalletProviderRegionInfo {

// Returns a value indicating whether a wallet provider is allowed for the
// specified country code, given the supplied allow/block list.
export function isExternalWalletProviderAllowed (
export function isExternalWalletProviderAllowed(
countryCode: string,
regionInfo: ExternalWalletProviderRegionInfo | null
) {
Expand All @@ -109,8 +109,22 @@ export function isExternalWalletProviderAllowed (
return true
}

// Returns a value indicating if new connections for the wallet provider have
// been disabled.
export function isExternalWalletProviderDisabled(
regionInfo: ExternalWalletProviderRegionInfo | null
) {
if (!regionInfo) {
return false
}
// The provider is considered disabled if the server returns an allow list
// with the single element "disabled".
const { allow } = regionInfo
return allow.length === 1 && regionInfo.allow[0] === 'disabled'
}

// Returns true if the specified wallet provider is a self-custody provider.
export function isSelfCustodyProvider (provider: ExternalWalletProvider) {
export function isSelfCustodyProvider(provider: ExternalWalletProvider) {
switch (provider) {
case 'bitflyer': return false
case 'gemini': return false
Expand Down

0 comments on commit 18c32c9

Please sign in to comment.