Skip to content

Commit e7f48e2

Browse files
authored
add basic wallet test suite (#672)
- downgrade trpc for chrome extension usage - remove trpc patch - update vite - replace vitest watch for run - replace api for create fn to await Next headers for context - seperate storage module from keystore - use wxt chrome storage - add vitest config - stub chrome runtime - stub browser - test add, import and get wallet methods closes status-im/status-website#1564
1 parent 4500418 commit e7f48e2

File tree

27 files changed

+423
-711
lines changed

27 files changed

+423
-711
lines changed

apps/api/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
},
1717
"dependencies": {
1818
"@status-im/wallet": "workspace:*",
19-
"@trpc/client": "11.1.0",
20-
"@trpc/server": "11.1.0",
21-
"@trpc/next": "11.1.0",
19+
"@trpc/client": "10.45.2",
20+
"@trpc/server": "10.45.2",
21+
"@trpc/next": "10.45.2",
2222
"react": "^19.0.0",
2323
"react-dom": "^19.0.0",
2424
"next": "15.3.0",

apps/portfolio/src/app/[address]/@detail/assets/[ticker]/page.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { notFound } from 'next/navigation'
88
import { MDXRemote } from 'next-mdx-remote/rsc'
99
import { ErrorBoundary } from 'react-error-boundary'
1010

11-
import { api } from '../../../../..//data/api'
11+
import { getAPIClient } from '../../../../..//data/api'
1212
import { Balance } from '../../../../_components/balance'
1313
import { BuyCryptoDrawer } from '../../../../_components/buy-crypto-drawer'
1414
import { portfolioComponents } from '../../../../_components/content'
@@ -77,16 +77,18 @@ async function Token({
7777
networks: NetworkType[]
7878
keyHash: string
7979
}) {
80+
const apiClient = await getAPIClient()
81+
8082
let token: ApiOutput['assets']['token'] | ApiOutput['assets']['nativeToken']
8183

8284
if (slug.startsWith('0x')) {
83-
token = await api.assets.token({
85+
token = await apiClient.assets.token({
8486
address: address,
8587
networks: networks as NetworkType[],
8688
contract: slug,
8789
})
8890
} else if (slug.toUpperCase() === 'ETH') {
89-
token = await api.assets.nativeToken({
91+
token = await apiClient.assets.nativeToken({
9092
address,
9193
networks: networks as NetworkType[],
9294
symbol: slug.toUpperCase(),
@@ -325,25 +327,27 @@ async function AssetChart({
325327
| ApiOutput['assets']['nativeTokenPriceChart']
326328
let balanceChart: ApiOutput['assets']['tokenBalanceChart']
327329

330+
const apiClient = await getAPIClient()
331+
328332
if (slug.startsWith('0x')) {
329-
priceChart = await api.assets.tokenPriceChart({
333+
priceChart = await apiClient.assets.tokenPriceChart({
330334
symbol,
331335
days: '1',
332336
})
333337

334-
balanceChart = await api.assets.tokenBalanceChart({
338+
balanceChart = await apiClient.assets.tokenBalanceChart({
335339
address,
336340
networks: ['ethereum', 'optimism', 'arbitrum', 'base', 'polygon', 'bsc'],
337341
contract: slug,
338342
days: '30',
339343
})
340344
} else if (slug.toUpperCase() === 'ETH') {
341-
priceChart = await api.assets.nativeTokenPriceChart({
345+
priceChart = await apiClient.assets.nativeTokenPriceChart({
342346
symbol: slug.toUpperCase(),
343347
days: '1',
344348
})
345349

346-
balanceChart = await api.assets.nativeTokenBalanceChart({
350+
balanceChart = await apiClient.assets.nativeTokenBalanceChart({
347351
address,
348352
networks: ['ethereum', 'optimism', 'arbitrum', 'base', 'polygon', 'bsc'],
349353
days: '30',

apps/portfolio/src/app/[address]/@detail/collectibles/[network]/[contract]/[id]/page.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Button } from '@status-im/components'
44
import { ExternalIcon, OptionsIcon, SadIcon } from '@status-im/icons/20'
55
import { OpenseaIcon } from '@status-im/icons/social'
66

7-
import { api } from '../../../../../../../data/api'
7+
import { getAPIClient } from '../../../../../../../data/api'
88
import { CurrencyAmount } from '../../../../../../_components/currency-amount'
99
import { NetworkLogo } from '../../../../../../_components/network-logo'
1010
import { ImageLightbox } from './_components/image-lightbox'
@@ -60,7 +60,9 @@ async function Collectible({
6060
contract: string
6161
id: string
6262
}) {
63-
const collectible = await api.collectibles.collectible({
63+
const apiClient = await getAPIClient()
64+
65+
const collectible = await apiClient.collectibles.collectible({
6466
contract,
6567
tokenId: id,
6668
network,

apps/portfolio/src/app/[address]/@list/@balance/default.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { api } from '../../../../data/api'
1+
import { getAPIClient } from '../../../../data/api'
22
import { Balance } from '../../../_components/balance'
33

44
import type { NetworkType } from '@status-im/wallet/data'
@@ -23,7 +23,9 @@ export default async function TotalBalance({ params, searchParams }: Props) {
2323
'bsc',
2424
]
2525

26-
const { summary } = await api.assets.all({
26+
const apiClient = await getAPIClient()
27+
28+
const { summary } = await apiClient.assets.all({
2729
address,
2830
networks: networks as NetworkType[],
2931
})

apps/portfolio/src/app/[address]/@list/@summary/default.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Address } from 'src/app/_components/address'
22

3-
import { api } from '../../../../data/api'
3+
import { getAPIClient } from '../../../../data/api'
44

55
import type { NetworkType } from '@status-im/wallet/data'
66

@@ -24,7 +24,9 @@ export default async function Summary({ params, searchParams }: Props) {
2424
'bsc',
2525
]
2626

27-
const { summary } = await api.assets.all({
27+
const apiClient = await getAPIClient()
28+
29+
const { summary } = await apiClient.assets.all({
2830
address,
2931
networks: networks as NetworkType[],
3032
})

apps/portfolio/src/app/[address]/@list/assets/page.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { api } from '../../../../data/api'
1+
import { getAPIClient } from '../../../../data/api'
22
import { AssetsTable } from './_components/assets-table'
33

44
import type { NetworkType } from '@status-im/wallet/data'
@@ -25,7 +25,9 @@ export default async function AssetsList(props: Props) {
2525
'bsc',
2626
]
2727

28-
const all = await api.assets.all({
28+
const apiClient = await getAPIClient()
29+
30+
const all = await apiClient.assets.all({
2931
address: address,
3032
networks: networks as NetworkType[],
3133
})

apps/portfolio/src/app/[address]/@list/collectibles/_actions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use server'
22

3-
import { api } from '../../../../data/api'
3+
import { getAPIClient } from '../../../../data/api'
44

55
import type { Collectible, NetworkType } from '@status-im/wallet/data'
66

@@ -26,7 +26,9 @@ export async function getCollectibles(
2626
): Promise<GetCollectiblesResponse> {
2727
const { address, networks, limit = 20, offset = 0, search, sort } = props
2828

29-
const response = await api.collectibles.page({
29+
const apiClient = await getAPIClient()
30+
31+
const response = await apiClient.collectibles.page({
3032
address,
3133
networks,
3234
limit,

apps/portfolio/src/app/[address]/@list/collectibles/page.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Button } from '@status-im/components'
22
import { ExternalIcon } from '@status-im/icons/20'
33

4-
import { api } from '../../../../data/api'
4+
import { getAPIClient } from '../../../../data/api'
55
import { Image } from '../../../_components/assets'
66
import { DEFAULT_SORT } from '../../../_constants'
77
import { getCollectibles } from './_actions'
@@ -42,7 +42,9 @@ export default async function CollectiblesPage(props: Props) {
4242
direction: sortParam[1] as 'asc' | 'desc',
4343
}
4444

45-
const { collectibles, hasMore } = await api.collectibles.page({
45+
const apiClient = await getAPIClient()
46+
47+
const { collectibles, hasMore } = await apiClient.collectibles.page({
4648
address,
4749
networks: networks as NetworkType[],
4850
limit: 20,

apps/portfolio/src/app/_actions.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import crypto from 'crypto'
44
import { match } from 'ts-pattern'
55

66
import { serverEnv } from '../config/env.server.mjs'
7-
import { api } from '../data/api'
7+
import { getAPIClient } from '../data/api'
88

99
import type { NetworkType } from '@status-im/wallet/data'
1010

@@ -181,12 +181,16 @@ export async function getAccountsData(
181181
throw new Error('No addresses provided')
182182
}
183183
const results = await Promise.all(
184-
addresses.map(address =>
185-
api.assets.all({
184+
addresses.map(async address => {
185+
const apiClient = await getAPIClient()
186+
187+
const result = await apiClient.assets.all({
186188
address,
187189
networks,
188190
})
189-
)
191+
192+
return result
193+
})
190194
)
191195

192196
return Object.fromEntries(

apps/portfolio/src/data/api.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
import 'server-only'
22

3-
export { api } from '@status-im/wallet/data'
3+
import { createAPI } from '@status-im/wallet/data'
4+
5+
let apiClient: Awaited<ReturnType<typeof createAPI>> | undefined
6+
7+
export async function getAPIClient() {
8+
if (!apiClient) {
9+
apiClient = await createAPI()
10+
}
11+
12+
return apiClient
13+
}

0 commit comments

Comments
 (0)