Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
116 changes: 111 additions & 5 deletions src/__tests__/actions/ExchangeInfoActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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' } },
Expand Down Expand Up @@ -143,6 +215,25 @@ describe('getDisabledSwapPlugins', () => {
})

describe('updateExchangeInfo', () => {
const run = async (
current: ReturnType<typeof asExchangeInfo>
): Promise<jest.Mock> => {
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: {
Expand All @@ -153,16 +244,31 @@ 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<typeof asExchangeInfo>
}
expect(action.data.swap.disableAssetsByPlugin).toEqual({
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)
})
})
98 changes: 98 additions & 0 deletions src/__tests__/components/Services.test.tsx
Original file line number Diff line number Diff line change
@@ -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 <Text>{Object.keys(types).join(',')}</Text>
}

describe('Services', () => {
it('loads exchange info from a rollup that lands after mount', async () => {
infoServerData.rollupRaw = undefined
const rendered = render(
<FakeProviders>
<Services navigation={fakeNavigation as any} />
<NewPaymentTypes />
</FakeProviders>
)
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()
})
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`initialState 1`] = `
{
Expand Down Expand Up @@ -72,9 +72,11 @@ exports[`initialState 1`] = `
"exchangeInfo": {
"buy": {
"disablePlugins": {},
"newPaymentTypes": {},
},
"sell": {
"disablePlugins": {},
"newPaymentTypes": {},
},
"swap": {
"disableAssets": {
Expand Down
36 changes: 33 additions & 3 deletions src/actions/ExchangeInfoActions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
asArray,
asDate,
asEither,
asMaybe,
asObject,
Expand Down Expand Up @@ -34,16 +35,25 @@ export const asNestedDisableMap: Cleaner<NestedDisableMap> = 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<typeof asFiatDirectionInfo>

export const asExchangeInfo = asObject({
buy: asMaybe<FiatDirectionInfo>(asFiatDirectionInfo, () => ({
disablePlugins: {}
disablePlugins: {},
newPaymentTypes: {}
})),
sell: asMaybe<FiatDirectionInfo>(asFiatDirectionInfo, () => ({
disablePlugins: {}
disablePlugins: {},
newPaymentTypes: {}
})),
swap: asMaybe(
asObject({
Expand Down Expand Up @@ -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<Promise<void>> {
return async (dispatch, getState) => {
try {
Expand All @@ -143,6 +167,12 @@ export function updateExchangeInfo(): ThunkAction<Promise<void>> {
| { 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}`)
Expand Down
10 changes: 8 additions & 2 deletions src/components/cards/PaymentOptionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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

Expand All @@ -48,7 +50,11 @@ export const PaymentOptionCard: React.FC<Props> = (props: Props) => {
{props.title}
</EdgeText>
</View>
{props.isBestOption === true ? <BestRateBadge /> : null}
{props.isBestOption === true ? (
<BurstBadge label={lstrings.string_best_rate_badge_text} />
) : props.isNew === true ? (
<BurstBadge label={lstrings.string_new_badge_text} />
) : null}
</View>
<View style={styles.subtitleView}>
<EdgeText style={styles.totalAmountText}>{props.totalAmount}</EdgeText>
Expand Down
Loading
Loading