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

[Rewards 3.0] Remove disabled wallet providers from connect modal #27113

Merged
merged 1 commit into from
Jan 13, 2025
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
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
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
Loading