From 7787b2a218ff56d05c5a9e0b9acf9f070d5b050c Mon Sep 17 00:00:00 2001 From: brave-builds Date: Mon, 8 Jan 2024 15:01:00 +0000 Subject: [PATCH] Uplift of #21472 (squashed) to beta --- .../page/components/provider_redirect_modal.tsx | 12 +++++++----- components/brave_rewards/resources/page/lib/types.ts | 1 + .../resources/page/reducers/default_state.ts | 1 + .../resources/page/reducers/rewards_reducer.ts | 2 ++ .../resources/page/stories/redux_state.ts | 1 + 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/components/brave_rewards/resources/page/components/provider_redirect_modal.tsx b/components/brave_rewards/resources/page/components/provider_redirect_modal.tsx index d6bacb965978..0d3c06216e26 100644 --- a/components/brave_rewards/resources/page/components/provider_redirect_modal.tsx +++ b/components/brave_rewards/resources/page/components/provider_redirect_modal.tsx @@ -6,7 +6,7 @@ import * as React from 'react' import { useActions, useRewardsData } from '../lib/redux_hooks' -import { lookupExternalWalletProviderName } from '../../shared/lib/external_wallet' +import { externalWalletProviderFromString, getExternalWalletProviderName } from '../../shared/lib/external_wallet' import { LocaleContext } from '../../shared/lib/locale_context' import { ModalRedirect } from '../../ui/components' import * as mojom from '../../shared/lib/mojom' @@ -14,13 +14,15 @@ import * as mojom from '../../shared/lib/mojom' export function ProviderRedirectModal () { const { getString } = React.useContext(LocaleContext) const actions = useActions() - const { externalWallet, modalRedirect } = useRewardsData((data) => ({ - externalWallet: data.externalWallet, + const { modalRedirectProvider, modalRedirect } = useRewardsData((data) => ({ + modalRedirectProvider: data.ui.modalRedirectProvider, modalRedirect: data.ui.modalRedirect })) - const walletType = externalWallet ? externalWallet.type : '' - const providerName = lookupExternalWalletProviderName(walletType) + const walletType = + externalWalletProviderFromString(modalRedirectProvider) || undefined + const providerName = + walletType ? getExternalWalletProviderName(walletType) : '' const onClickRetry = () => { actions.hideRedirectModal() diff --git a/components/brave_rewards/resources/page/lib/types.ts b/components/brave_rewards/resources/page/lib/types.ts index c91af9c45585..5e8d660039f1 100644 --- a/components/brave_rewards/resources/page/lib/types.ts +++ b/components/brave_rewards/resources/page/lib/types.ts @@ -61,6 +61,7 @@ export interface State { | 'error' | 'hide' | 'show' + modalRedirectProvider: string modalReset: boolean modalAdsHistory: boolean adsSettings: boolean diff --git a/components/brave_rewards/resources/page/reducers/default_state.ts b/components/brave_rewards/resources/page/reducers/default_state.ts index 2e417b329678..3ca6b7dd3049 100644 --- a/components/brave_rewards/resources/page/reducers/default_state.ts +++ b/components/brave_rewards/resources/page/reducers/default_state.ts @@ -20,6 +20,7 @@ export function defaultState (): Rewards.State { ui: { modalConnect: false, modalRedirect: 'hide', + modalRedirectProvider: '', modalReset: false, modalAdsHistory: false, adsSettings: false, diff --git a/components/brave_rewards/resources/page/reducers/rewards_reducer.ts b/components/brave_rewards/resources/page/reducers/rewards_reducer.ts index 958101543f8c..e136775cfe74 100644 --- a/components/brave_rewards/resources/page/reducers/rewards_reducer.ts +++ b/components/brave_rewards/resources/page/reducers/rewards_reducer.ts @@ -324,6 +324,8 @@ const rewardsReducer: Reducer = (state: Rewards.State chrome.send('brave_rewards.connectExternalWallet', [path, query]) ui.modalRedirect = 'show' + // The first non-empty path segment contains the wallet provider type. + ui.modalRedirectProvider = path.replace(/^\//, '').split('/')[0] || '' state = { ...state, ui } break diff --git a/components/brave_rewards/resources/page/stories/redux_state.ts b/components/brave_rewards/resources/page/stories/redux_state.ts index a42013af1f31..870705ec4c3b 100644 --- a/components/brave_rewards/resources/page/stories/redux_state.ts +++ b/components/brave_rewards/resources/page/stories/redux_state.ts @@ -20,6 +20,7 @@ export const reduxState: Rewards.ApplicationState = { ui: { modalConnect: false, modalRedirect: 'hide', + modalRedirectProvider: '', modalReset: false, modalAdsHistory: false, adsSettings: false,