From ee403567e6fb19ffb41e77fe9b292a029be5e7bf Mon Sep 17 00:00:00 2001 From: Jonathan Tzeng Date: Sat, 31 Oct 2026 21:18:33 -0700 Subject: [PATCH 1/2] Generalize BestRateBadge into BurstBadge Takes the label as a prop to let the same burst carry other short labels. No visual change. --- src/components/cards/PaymentOptionCard.tsx | 6 ++++-- .../icons/{BestRateBadge.tsx => BurstBadge.tsx} | 14 ++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) rename src/components/icons/{BestRateBadge.tsx => BurstBadge.tsx} (91%) diff --git a/src/components/cards/PaymentOptionCard.tsx b/src/components/cards/PaymentOptionCard.tsx index d3bd23d34b1..bad67e00fd5 100644 --- a/src/components/cards/PaymentOptionCard.tsx +++ b/src/components/cards/PaymentOptionCard.tsx @@ -6,7 +6,7 @@ import { lstrings } from '../../locales/strings' import type { ImageProp } from '../../types/Theme' import { PillButton } from '../buttons/PillButton' import { EdgeCard } from '../cards/EdgeCard' -import { BestRateBadge } from '../icons/BestRateBadge' +import { BurstBadge } from '../icons/BurstBadge' import { cacheStyles, useTheme } from '../services/ThemeContext' import { EdgeText } from '../themed/EdgeText' @@ -48,7 +48,9 @@ export const PaymentOptionCard: React.FC = (props: Props) => { {props.title} - {props.isBestOption === true ? : null} + {props.isBestOption === true ? ( + + ) : null} {props.totalAmount} diff --git a/src/components/icons/BestRateBadge.tsx b/src/components/icons/BurstBadge.tsx similarity index 91% rename from src/components/icons/BestRateBadge.tsx rename to src/components/icons/BurstBadge.tsx index 54b6010df90..8c9c2a93332 100644 --- a/src/components/icons/BestRateBadge.tsx +++ b/src/components/icons/BurstBadge.tsx @@ -2,12 +2,16 @@ import * as React from 'react' import { type LayoutChangeEvent, StyleSheet, View } from 'react-native' import Svg, { Polygon } from 'react-native-svg' -import { lstrings } from '../../locales/strings' import { cacheStyles, useTheme } from '../services/ThemeContext' import { EdgeText } from '../themed/EdgeText' -// TODO: Render a badge icon -export const BestRateBadge: React.FC = () => { +interface Props { + label: string +} + +/** A short label inside a star-shaped burst. */ +export const BurstBadge: React.FC = props => { + const { label } = props const theme = useTheme() const [dimensions, setDimensions] = React.useState({ width: 0, height: 0 }) @@ -71,9 +75,7 @@ export const BestRateBadge: React.FC = () => { strokeWidth={2} /> - - {lstrings.string_best_rate_badge_text} - + {label} ) } From d80f0032f2c992a5fb56b2cc6430459470a96fb4 Mon Sep 17 00:00:00 2001 From: Jonathan Tzeng Date: Sat, 31 Oct 2026 21:22:35 -0700 Subject: [PATCH 2/2] Badge new ramp payment methods The info server lists payment types per direction with an endIsoDate, and the quote card shows a "New" burst until that date. Best Rate keeps the slot when both apply. --- CHANGELOG.md | 1 + .../actions/ExchangeInfoActions.test.ts | 116 +++++++++++++++++- src/__tests__/components/Services.test.tsx | 98 +++++++++++++++ .../__snapshots__/RootReducer.test.ts.snap | 4 +- src/actions/ExchangeInfoActions.ts | 36 +++++- src/components/cards/PaymentOptionCard.tsx | 4 + .../scenes/RampSelectOptionScene.tsx | 9 ++ src/components/services/Services.tsx | 9 +- src/locales/en_US.ts | 1 + src/locales/strings/enUS.json | 1 + src/reducers/ExchangeInfoReducer.ts | 6 +- 11 files changed, 272 insertions(+), 13 deletions(-) create mode 100644 src/__tests__/components/Services.test.tsx diff --git a/CHANGELOG.md b/CHANGELOG.md index d103ba1b038..acad34a3a97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ## 4.53.0 (staging) +- added: "New" badge on ramp payment methods, configured from the info server with an expiry date - added: `AGENT_TEST_MODE` config setting and iOS debug-build `EdgeTestAnimations` switch that quiet the app for automated UI tests - changed: Blur on iOS now uses `expo-blur`, the same backend as Android 12+, so `rn-id-blurview` (an old-architecture view manager with no new-architecture support) is no longer a dependency. - changed: Stealth Swap works with Houdini switched off in the exchange settings, as Stealth Send already does diff --git a/src/__tests__/actions/ExchangeInfoActions.test.ts b/src/__tests__/actions/ExchangeInfoActions.test.ts index 8e87e96a72f..7fd85ad254d 100644 --- a/src/__tests__/actions/ExchangeInfoActions.test.ts +++ b/src/__tests__/actions/ExchangeInfoActions.test.ts @@ -6,8 +6,10 @@ import { type DisableAsset, getDisabledSwapPlugins, isAssetDisabled, + isPaymentTypeNew, updateExchangeInfo } from '../../actions/ExchangeInfoActions' +import { initialState } from '../../reducers/ExchangeInfoReducer' import type { Dispatch, RootState } from '../../types/reduxTypes' import { infoServerData } from '../../util/network' @@ -97,6 +99,76 @@ describe('asExchangeInfo disableAssetsByPlugin', () => { }) }) +describe('asExchangeInfo newPaymentTypes', () => { + const disablePlugins = { pix: true as const } + + test('defaults to an empty map', () => { + expect(asExchangeInfo({}).buy.newPaymentTypes).toEqual({}) + expect( + asExchangeInfo({ sell: { disablePlugins } }).sell.newPaymentTypes + ).toEqual({}) + }) + + test('a malformed map keeps disablePlugins', () => { + const { buy } = asExchangeInfo({ + buy: { disablePlugins, newPaymentTypes: 'bad' } + }) + expect(buy).toEqual({ disablePlugins, newPaymentTypes: {} }) + }) + + test('a malformed entry badges nothing and keeps the others', () => { + const { buy } = asExchangeInfo({ + buy: { + disablePlugins, + newPaymentTypes: { + cashapp: { endIsoDate: '2026-12-01T00:00:00.000Z' }, + pix: { endIsoDate: 'not a date' }, + venmo: {} + } + } + }) + const now = new Date('2026-11-01T00:00:00.000Z') + expect(buy.disablePlugins).toEqual(disablePlugins) + expect(isPaymentTypeNew(buy.newPaymentTypes, 'cashapp', now)).toBe(true) + expect(isPaymentTypeNew(buy.newPaymentTypes, 'pix', now)).toBe(false) + expect(isPaymentTypeNew(buy.newPaymentTypes, 'venmo', now)).toBe(false) + }) + + test('directions are independent', () => { + const { buy, sell } = asExchangeInfo({ + buy: { + disablePlugins, + newPaymentTypes: { cashapp: { endIsoDate: '2026-12-01T00:00:00.000Z' } } + }, + sell: { disablePlugins } + }) + const now = new Date('2026-11-01T00:00:00.000Z') + expect(isPaymentTypeNew(buy.newPaymentTypes, 'cashapp', now)).toBe(true) + expect(isPaymentTypeNew(sell.newPaymentTypes, 'cashapp', now)).toBe(false) + }) +}) + +describe('isPaymentTypeNew', () => { + const endIsoDate = new Date('2026-12-01T00:00:00.000Z') + const newPaymentTypes = { cashapp: { endIsoDate } } + + test('true before endIsoDate', () => { + const now = new Date(endIsoDate.valueOf() - 1) + expect(isPaymentTypeNew(newPaymentTypes, 'cashapp', now)).toBe(true) + }) + + test('false from endIsoDate on', () => { + expect(isPaymentTypeNew(newPaymentTypes, 'cashapp', endIsoDate)).toBe(false) + const later = new Date(endIsoDate.valueOf() + 1) + expect(isPaymentTypeNew(newPaymentTypes, 'cashapp', later)).toBe(false) + }) + + test('false for an unlisted payment type', () => { + const now = new Date('2026-11-01T00:00:00.000Z') + expect(isPaymentTypeNew(newPaymentTypes, 'pix', now)).toBe(false) + }) +}) + describe('getDisabledSwapPlugins', () => { const request = { fromWallet: { currencyInfo: { pluginId: 'bitcoin' } }, @@ -143,6 +215,25 @@ describe('getDisabledSwapPlugins', () => { }) describe('updateExchangeInfo', () => { + const run = async ( + current: ReturnType + ): Promise => { + const dispatch = jest.fn() + await updateExchangeInfo()( + dispatch as unknown as Dispatch, + () => ({ ui: { exchangeInfo: current } } as unknown as RootState) + ) + return dispatch + } + const newApplePay = (endIsoDate: string): unknown => ({ + exchangeInfo: { + buy: { + disablePlugins: {}, + newPaymentTypes: { applepay: { endIsoDate } } + } + } + }) + test('keeps disableAssetsByPlugin from the raw rollup', async () => { infoServerData.rollupRaw = { exchangeInfo: { @@ -153,11 +244,7 @@ describe('updateExchangeInfo', () => { } } } - const dispatch = jest.fn() - await updateExchangeInfo()( - dispatch as unknown as Dispatch, - () => ({} as unknown as RootState) - ) + const dispatch = await run(initialState) const action = dispatch.mock.calls[0][0] as { data: ReturnType } @@ -165,4 +252,23 @@ describe('updateExchangeInfo', () => { lifi: { source: [{ pluginId: 'bitcoin' }], destination: [] } }) }) + + test('leaves state alone when the rollup carries the same info', async () => { + infoServerData.rollupRaw = newApplePay('2030-01-01T00:00:00.000Z') + const current = asExchangeInfo( + (infoServerData.rollupRaw as { exchangeInfo: unknown }).exchangeInfo + ) + const dispatch = await run(current) + expect(dispatch).not.toHaveBeenCalled() + }) + + test('picks up a changed expiry date', async () => { + infoServerData.rollupRaw = newApplePay('2030-01-01T00:00:00.000Z') + const current = asExchangeInfo( + (infoServerData.rollupRaw as { exchangeInfo: unknown }).exchangeInfo + ) + infoServerData.rollupRaw = newApplePay('2031-01-01T00:00:00.000Z') + const dispatch = await run(current) + expect(dispatch).toHaveBeenCalledTimes(1) + }) }) diff --git a/src/__tests__/components/Services.test.tsx b/src/__tests__/components/Services.test.tsx new file mode 100644 index 00000000000..5208847911a --- /dev/null +++ b/src/__tests__/components/Services.test.tsx @@ -0,0 +1,98 @@ +import { describe, expect, it, jest } from '@jest/globals' +import { act, render } from '@testing-library/react-native' +import * as React from 'react' +import { Text } from 'react-native' + +import { Services } from '../../components/services/Services' +import { useSelector } from '../../types/reactRedux' +import { FakeProviders } from '../../util/fake/FakeProviders' +import { fakeNavigation } from '../../util/fake/fakeSceneProps' +import { infoServerData, notifyInfoRollup } from '../../util/network' + +jest.mock('react-native-device-info', () => ({ + getVersion: () => '1.0.0', + usePowerState: () => ({}) +})) + +// Only the rollup wiring is under test, so the child services render nothing: +jest.mock('../../components/services/AccountCallbackManager', () => ({ + AccountCallbackManager: () => null +})) +jest.mock('../../components/services/ActionQueueService', () => ({ + ActionQueueService: () => null +})) +jest.mock('../../components/services/AutoLogout', () => ({ + AutoLogout: () => null +})) +jest.mock('../../components/services/FioService', () => ({ + FioService: () => null +})) +jest.mock('../../components/services/LoanManagerService', () => ({ + LoanManagerService: () => null +})) +jest.mock('../../components/services/NotificationService', () => ({ + NotificationService: () => null +})) +jest.mock('../../components/services/SortedWalletList', () => ({ + SortedWalletList: () => null +})) +jest.mock('../../components/services/WalletConnectService', () => ({ + WalletConnectService: () => null +})) +jest.mock('../../components/services/ContactsLoader', () => ({ + ContactsLoader: () => null +})) +jest.mock('../../components/services/EdgeContextCallbackManager', () => ({ + EdgeContextCallbackManager: () => null +})) +jest.mock('../../components/services/NetworkActivity', () => ({ + NetworkActivity: () => null +})) +jest.mock('../../components/services/PasswordReminderService', () => ({ + PasswordReminderService: () => null +})) +jest.mock('../../components/services/PermissionsManager', () => ({ + PermissionsManager: () => null +})) +jest.mock('../../components/services/WalletLifecycle', () => ({ + WalletLifecycle: () => null +})) +jest.mock('../../components/services/WipeLogsService', () => ({ + WipeLogsService: () => null +})) + +const NewPaymentTypes: React.FC = () => { + const types = useSelector(state => state.ui.exchangeInfo.buy.newPaymentTypes) + return {Object.keys(types).join(',')} +} + +describe('Services', () => { + it('loads exchange info from a rollup that lands after mount', async () => { + infoServerData.rollupRaw = undefined + const rendered = render( + + + + + ) + expect(rendered.queryByText('applepay')).toBeNull() + + infoServerData.rollupRaw = { + exchangeInfo: { + buy: { + disablePlugins: {}, + newPaymentTypes: { + applepay: { endIsoDate: '2030-01-01T00:00:00.000Z' } + } + } + } + } + await act(async () => { + notifyInfoRollup() + await Promise.resolve() + }) + + expect(rendered.getByText('applepay')).toBeTruthy() + rendered.unmount() + }) +}) diff --git a/src/__tests__/reducers/__snapshots__/RootReducer.test.ts.snap b/src/__tests__/reducers/__snapshots__/RootReducer.test.ts.snap index 39e12c78f31..ba1a9f278d6 100644 --- a/src/__tests__/reducers/__snapshots__/RootReducer.test.ts.snap +++ b/src/__tests__/reducers/__snapshots__/RootReducer.test.ts.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing +// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`initialState 1`] = ` { @@ -72,9 +72,11 @@ exports[`initialState 1`] = ` "exchangeInfo": { "buy": { "disablePlugins": {}, + "newPaymentTypes": {}, }, "sell": { "disablePlugins": {}, + "newPaymentTypes": {}, }, "swap": { "disableAssets": { diff --git a/src/actions/ExchangeInfoActions.ts b/src/actions/ExchangeInfoActions.ts index 9d4d736dd68..41558c80bcc 100644 --- a/src/actions/ExchangeInfoActions.ts +++ b/src/actions/ExchangeInfoActions.ts @@ -1,5 +1,6 @@ import { asArray, + asDate, asEither, asMaybe, asObject, @@ -34,16 +35,25 @@ export const asNestedDisableMap: Cleaner = asObject( ) const asFiatDirectionInfo = asObject({ - disablePlugins: asNestedDisableMap + disablePlugins: asNestedDisableMap, + // Payment types to badge as "New" until `endIsoDate`. Each entry is cleaned on + // its own: a malformed one badges nothing and leaves everything else in place, + // `disablePlugins` included. + newPaymentTypes: asMaybe( + asObject(asMaybe(asObject({ endIsoDate: asDate }))), + () => ({}) + ) }) type FiatDirectionInfo = ReturnType export const asExchangeInfo = asObject({ buy: asMaybe(asFiatDirectionInfo, () => ({ - disablePlugins: {} + disablePlugins: {}, + newPaymentTypes: {} })), sell: asMaybe(asFiatDirectionInfo, () => ({ - disablePlugins: {} + disablePlugins: {}, + newPaymentTypes: {} })), swap: asMaybe( asObject({ @@ -132,6 +142,20 @@ export const getDisabledSwapPlugins = ( return out } +/** + * True while the info server lists the payment type as new. The badge follows + * the payment type across providers, and the date check expires it with no app + * or server change. + */ +export const isPaymentTypeNew = ( + newPaymentTypes: FiatDirectionInfo['newPaymentTypes'], + paymentType: string, + now: Date +): boolean => { + const entry = newPaymentTypes[paymentType] + return entry != null && now.valueOf() < entry.endIsoDate.valueOf() +} + export function updateExchangeInfo(): ThunkAction> { return async (dispatch, getState) => { try { @@ -143,6 +167,12 @@ export function updateExchangeInfo(): ThunkAction> { | { exchangeInfo?: unknown } | undefined const data = asExchangeInfo(rollup?.exchangeInfo) + // This runs on every rollup, and the Send scene re-quotes when these + // objects change identity, so an identical payload must not replace + // them. JSON rather than `matchJson`, which sees all Dates as equal: + const unchanged = + JSON.stringify(data) === JSON.stringify(getState().ui.exchangeInfo) + if (unchanged) return dispatch({ type: 'UPDATE_EXCHANGE_INFO', data }) } catch (e: any) { console.warn(`Failed to get info server exchangeInfo: ${e.message}`) diff --git a/src/components/cards/PaymentOptionCard.tsx b/src/components/cards/PaymentOptionCard.tsx index bad67e00fd5..55b7251f928 100644 --- a/src/components/cards/PaymentOptionCard.tsx +++ b/src/components/cards/PaymentOptionCard.tsx @@ -23,6 +23,8 @@ interface Props { } /** Show "Best Rate" badge */ isBestOption?: boolean + /** Show "New" badge, unless the card already shows "Best Rate" */ + isNew?: boolean /** Applied to the partner pill, which opens the provider picker */ providerTestID?: string @@ -50,6 +52,8 @@ export const PaymentOptionCard: React.FC = (props: Props) => { {props.isBestOption === true ? ( + ) : props.isNew === true ? ( + ) : null} diff --git a/src/components/scenes/RampSelectOptionScene.tsx b/src/components/scenes/RampSelectOptionScene.tsx index 2db8a8e1cdc..7b86d6303de 100644 --- a/src/components/scenes/RampSelectOptionScene.tsx +++ b/src/components/scenes/RampSelectOptionScene.tsx @@ -2,6 +2,7 @@ import * as React from 'react' import { ActivityIndicator, Image, View } from 'react-native' import { sprintf } from 'sprintf-js' +import { isPaymentTypeNew } from '../../actions/ExchangeInfoActions' import paymentTypeLogoApplePay from '../../assets/images/paymentTypes/paymentTypeLogoApplePay.png' import { CONFIG } from '../../config' import { COUNTRY_CODES } from '../../constants/CountryConstants' @@ -351,6 +352,7 @@ const QuoteResult: React.FC<{ }> = ({ providerQuotes, onPress, bestQuoteOverall, isApprovingQuote }) => { const theme = useTheme() const styles = getStyles(theme) + const exchangeInfo = useSelector(state => state.ui.exchangeInfo) // State for the which provider quote for this payment type to be displayed const [providerQuoteIndex, setProviderQuoteIndex] = React.useState(0) @@ -433,6 +435,12 @@ const QuoteResult: React.FC<{ providerQuote.paymentType === bestQuoteOverall.paymentType && providerQuote.fiatAmount === bestQuoteOverall.fiatAmount + const isNew = isPaymentTypeNew( + exchangeInfo[providerQuote.direction].newPaymentTypes, + providerQuote.paymentType, + new Date() + ) + const fiatCurrencyCode = providerQuote.fiatCurrencyCode.replace('iso:', '') const formattedSelectedFiatAmount = hasSelectedAmounts ? formatNumber(providerQuote.fiatAmount, { toFixed: 2 }) @@ -492,6 +500,7 @@ const QuoteResult: React.FC<{ icon: { uri: providerQuote.partnerIcon } }} isBestOption={isBestOption} + isNew={isNew} providerTestID={`providerPill_${providerQuote.paymentType}`} onPress={handlePress} onProviderPress={handleProviderPress} diff --git a/src/components/services/Services.tsx b/src/components/services/Services.tsx index 8aad5aac860..8752f4cc8f1 100644 --- a/src/components/services/Services.tsx +++ b/src/components/services/Services.tsx @@ -49,6 +49,7 @@ import { WalletLifecycle } from './WalletLifecycle' import { WipeLogsService } from './WipeLogsService' interface Props { + // TODO: Replace NavigationBase with useNavigation() or callbacks. Requires v7 navigation migration. navigation: NavigationBase } @@ -74,11 +75,15 @@ export const Services: React.FC = props => { }, []) // The refresher below runs at mount, which can beat the launch rollup. - // Reload Houdini's list whenever a rollup lands, so Stealth shows as soon - // as the list arrives rather than on the next refresher tick: + // Reload what the rollup feeds whenever one lands, so Stealth and the ramp + // "New" badges show as soon as it arrives rather than on the next refresher + // tick: React.useEffect( () => onInfoRollup(() => { + dispatch(updateExchangeInfo()).catch((error: unknown) => { + console.warn(error) + }) dispatch(updateHoudiniChains()).catch((error: unknown) => { console.warn(error) }) diff --git a/src/locales/en_US.ts b/src/locales/en_US.ts index f42a645459a..bac54516b13 100644 --- a/src/locales/en_US.ts +++ b/src/locales/en_US.ts @@ -1561,6 +1561,7 @@ const strings = { string_report_sent: 'The report has been sent successfully.', string_show_error: 'Show Error', string_best_rate_badge_text: 'Best\nRate', + string_new_badge_text: 'New', step_prefix_s: 'Step %s:', scan_as_in_scan_barcode: 'Scan', diff --git a/src/locales/strings/enUS.json b/src/locales/strings/enUS.json index 910bf57a7a3..52803a3118b 100644 --- a/src/locales/strings/enUS.json +++ b/src/locales/strings/enUS.json @@ -1226,6 +1226,7 @@ "string_report_sent": "The report has been sent successfully.", "string_show_error": "Show Error", "string_best_rate_badge_text": "Best\nRate", + "string_new_badge_text": "New", "step_prefix_s": "Step %s:", "scan_as_in_scan_barcode": "Scan", "enter_as_in_enter_address_with_keyboard": "Enter", diff --git a/src/reducers/ExchangeInfoReducer.ts b/src/reducers/ExchangeInfoReducer.ts index 4522e5f3ed7..4195ee3b0aa 100644 --- a/src/reducers/ExchangeInfoReducer.ts +++ b/src/reducers/ExchangeInfoReducer.ts @@ -3,10 +3,12 @@ import type { Action } from '../types/reduxTypes' export const initialState: ExchangeInfo = { buy: { - disablePlugins: {} + disablePlugins: {}, + newPaymentTypes: {} }, sell: { - disablePlugins: {} + disablePlugins: {}, + newPaymentTypes: {} }, swap: { disableAssets: {