Skip to content

Commit 5b8a9c5

Browse files
committed
fix: testnet chain names
1 parent 0359c86 commit 5b8a9c5

File tree

21 files changed

+397
-115
lines changed

21 files changed

+397
-115
lines changed

apps/customer/app/layout.tsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,35 @@ export const metadata: Metadata = {
2323
'Monerium issues onchain fiat – directly transferable between your wallet and bank accounts.',
2424
};
2525

26-
export default function RootLayout({
26+
const fetchThemeMode = async () => {
27+
const cookieStore = await cookies();
28+
return cookieStore?.get('themeMode')?.value || 'light';
29+
};
30+
31+
const LayoutWrapper = async ({ children }: { children: React.ReactNode }) => {
32+
const themeMode = await fetchThemeMode();
33+
34+
return <Layout themeMode={themeMode}>{children}</Layout>;
35+
};
36+
37+
const Layout = ({
2738
children,
28-
}: Readonly<{
39+
themeMode,
40+
}: {
2941
children: React.ReactNode;
30-
}>) {
31-
const cookieStore = cookies();
32-
const themeMode = cookieStore?.get('themeMode')?.value || 'light';
42+
themeMode: string;
43+
}) => {
3344
return (
3445
<html lang="en" data-mui-color-scheme={themeMode}>
35-
<body className={`${geistSans.variable} ${geistMono.variable}`}>
46+
<body>
47+
{' '}
3648
<Providers>
3749
<ThemeModeToggle />
3850
{children}
3951
</Providers>
4052
</body>
4153
</html>
4254
);
43-
}
55+
};
56+
57+
export default LayoutWrapper;

apps/customer/app/test/page.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import {
3535
useTokens,
3636
} from '@monerium/sdk-react-provider';
3737
export default function Test() {
38+
// https://punkwallet.io/pk#0xc3dba5f61acf6675aee27b7141db8decf7d4e7514afafdd6b764e02138c53cac
39+
const COUNTERPART_ADDRESS = '0x28Bd09f59A40A0B42dAC69Ef43ef7Ffa37F12Ead';
3840
/**
3941
* Wagmi
4042
*/
@@ -542,9 +544,9 @@ export default function Test() {
542544
</select>
543545
<Input
544546
name="counterpart-identifier-address"
545-
defaultValue="0x1f77Bdedb8751C525E5C4223eA86C32972FB2c68"
547+
defaultValue={COUNTERPART_ADDRESS}
546548
/>
547-
<Input name="counterpart-identifier-chain" defaultValue="polygon" />
549+
<Input name="counterpart-identifier-chain" defaultValue="amoy" />
548550
<Input name="counterpart-details-first-name" defaultValue="John" />
549551
<Input name="counterpart-details-last-name" defaultValue="Doe" />
550552
<Input name="counterpart-details-country" defaultValue="IS" />

apps/customer/components/App/Providers/Providers.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function Providers({ children }: { children: React.ReactNode }) {
3333
<QueryClientProvider client={queryClient}>
3434
<RainbowKitProvider>
3535
<MoneriumProvider
36-
clientId="f99e629b-6dca-11ee-8aa6-5273f65ed05b"
36+
clientId="9ee602d1-cc19-11ef-92b5-aae55502171d"
3737
redirectUri={`${baseUrl}/dashboard`}
3838
environment="sandbox"
3939
debug={true}

apps/customer/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
"build": "next build",
88
"start": "next start",
99
"lint": "next lint --fix",
10-
"lint:style": "stylelint --fix '**/*.{css,scss}'"
10+
"lint:style": "stylelint --fix '**/*.{css,scss}'",
11+
"clean": "rm -rf .next node_modules .turbo"
1112
},
1213
"dependencies": {
1314
"@emotion/cache": "^11.11.0",
1415
"@emotion/react": "^11.11.4",
1516
"@emotion/styled": "^11.11.5",
16-
"@monerium/sdk": "workspace:latest",
17-
"@monerium/sdk-react-provider": "workspace:latest",
17+
"@monerium/sdk": "workspace:*",
18+
"@monerium/sdk-react-provider": "workspace:*",
1819
"@mui/icons-material": "^5.15.19",
1920
"@mui/material": "^5.15.19",
2021
"@mui/material-nextjs": "^5.15.11",

apps/developer/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"serve": "docusaurus serve",
1313
"write-translations": "docusaurus write-translations",
1414
"write-heading-ids": "docusaurus write-heading-ids",
15-
"typecheck": "tsc"
15+
"typecheck": "tsc",
16+
"clean": "rm -rf build node_modules .turbo"
1617
},
1718
"dependencies": {
1819
"@docusaurus/core": "3.5.2",
@@ -27,7 +28,7 @@
2728
"@docusaurus/module-type-aliases": "3.5.2",
2829
"@docusaurus/tsconfig": "3.5.2",
2930
"@docusaurus/types": "3.5.2",
30-
"docusaurus-plugin-typedoc": "^1.0.4",
31+
"docusaurus-plugin-typedoc": "1.0.4",
3132
"typescript": "~5.2.2"
3233
},
3334
"browserslist": {

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
"lint:style": "turbo lint:style",
1313
"pub:pre": "turbo pub:pre",
1414
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
15-
"clean": "pnpm run clean:build && pnpm run clean:npm",
16-
"clean:build": "rm -rf apps/customer/.next packages/sdk-react-provider/dist packages/sdk/dist",
17-
"clean:npm": "rm -rf node_modules pnpm-lock.yaml packages/sdk-react-provider/node_modules apps/customer/node_modules",
15+
"clean": "rm -rf node_modules pnpm-lock.yaml .turbo && turbo clean",
1816
"prepare": "husky"
1917
},
2018
"dependencies": {
@@ -37,8 +35,8 @@
3735
"ts-jest": "^29.1.4",
3836
"tsup": "^8.1.0",
3937
"turbo": "^2.0.14",
40-
"typedoc": "^0.26.4",
41-
"typedoc-plugin-markdown": "^4.2.5"
38+
"typedoc": "0.26.11",
39+
"typedoc-plugin-markdown": "4.2.5"
4240
},
4341
"packageManager": "pnpm@9.4.0",
4442
"engines": {

packages/sdk-react-provider/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@
3535
"pub:pre": "pnpm publish --no-git-checks --dry-run",
3636
"test": "jest",
3737
"test:watch": "jest --watch",
38-
"type-map": "tsc --emitDeclarationOnly --declaration"
38+
"type-map": "tsc --emitDeclarationOnly --declaration",
39+
"clean": "rm -rf dist node_modules .turbo"
3940
},
4041
"dependencies": {
41-
"@monerium/sdk": "workspace:latest"
42+
"@monerium/sdk": "workspace:*"
4243
},
4344
"peerDependencies": {
4445
"@tanstack/react-query": ">=5.0.0",

packages/sdk/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"lint": "eslint . --fix",
3535
"pub:pre": "pnpm publish --no-git-checks --dry-run",
3636
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
37-
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
37+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch",
38+
"clean": "rm -rf dist node_modules .turbo"
3839
},
3940
"dependencies": {
4041
"crypto-js": "^4.2.0"

packages/sdk/src/client.ts

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ import type {
5252
SupportingDoc,
5353
Token,
5454
} from './types';
55-
import { mapChainIdToChain, parseChain, urlEncoded } from './utils';
55+
import {
56+
mapChainIdToChain,
57+
parseChainBackwardsCompatible,
58+
urlEncoded,
59+
} from './utils';
5660

5761
// import pjson from "../package.json";
5862
const { STORAGE_CODE_VERIFIER, STORAGE_ACCESS_TOKEN, STORAGE_ACCESS_EXPIRY } =
@@ -167,7 +171,7 @@ export class MoneriumClient {
167171
throw new Error('Missing ClientId');
168172
}
169173

170-
const authFlowUrl = getAuthFlowUrlAndStoreCodeVerifier(this.#env.api, {
174+
const authFlowUrl = getAuthFlowUrlAndStoreCodeVerifier(this.#env, {
171175
client_id: clientId,
172176
redirect_uri: redirectUri,
173177
address: params?.address,
@@ -408,7 +412,7 @@ export class MoneriumClient {
408412
* @see {@link https://monerium.dev/api-docs-v2#tag/addresses/operation/addresses | API Documentation}
409413
*/
410414
getAddresses(params?: AddressesQueryParams): Promise<AddressesResponse> {
411-
params = mapChainIdToChain(params);
415+
params = mapChainIdToChain(this.#env.name, params);
412416
const searchParams = params
413417
? urlEncoded(params as unknown as Record<string, string>)
414418
: undefined;
@@ -431,9 +435,11 @@ export class MoneriumClient {
431435
? `currency=${currencies}`
432436
: '';
433437

438+
const chainParam = parseChainBackwardsCompatible(this.#env.name, chain);
439+
434440
return this.#api<Balances>(
435441
'get',
436-
`balances/${parseChain(chain)}/${address}${currencyParams ? `?${currencyParams}` : ''}`
442+
`balances/${chainParam}/${address}${currencyParams ? `?${currencyParams}` : ''}`
437443
);
438444
}
439445

@@ -456,7 +462,7 @@ export class MoneriumClient {
456462
const { profile, chain } = queryParameters || {};
457463
const params = queryParams({
458464
profile,
459-
chain: chain ? parseChain(chain) : '',
465+
chain: chain ? parseChainBackwardsCompatible(this.#env.name, chain) : '',
460466
});
461467
return this.#api<IBANsResponse>('get', `ibans${params}`);
462468
}
@@ -490,7 +496,7 @@ export class MoneriumClient {
490496
* @see {@link https://monerium.dev/api-docs-v2#tag/addresses/operation/link-address | API Documentation}
491497
*/
492498
linkAddress(payload: LinkAddress): Promise<LinkedAddress> {
493-
payload = mapChainIdToChain(payload);
499+
payload = mapChainIdToChain(this.#env.name, payload);
494500
return this.#api<LinkedAddress>(
495501
'post',
496502
`addresses`,
@@ -506,10 +512,13 @@ export class MoneriumClient {
506512
placeOrder(order: NewOrder): Promise<Order> {
507513
const body = {
508514
kind: 'redeem',
509-
...mapChainIdToChain(order),
515+
...mapChainIdToChain(this.#env.name, order),
510516
counterpart: {
511517
...order.counterpart,
512-
identifier: mapChainIdToChain(order.counterpart.identifier),
518+
identifier: mapChainIdToChain(
519+
this.#env.name,
520+
order.counterpart.identifier
521+
),
513522
},
514523
};
515524

@@ -529,7 +538,10 @@ export class MoneriumClient {
529538
return this.#api<ResponseStatus>(
530539
'patch',
531540
`ibans/${iban}`,
532-
JSON.stringify({ address, chain: parseChain(chain) })
541+
JSON.stringify({
542+
address,
543+
chain: parseChainBackwardsCompatible(this.#env.name, chain),
544+
})
533545
);
534546
}
535547

@@ -546,7 +558,11 @@ export class MoneriumClient {
546558
return this.#api<ResponseStatus>(
547559
'post',
548560
`ibans`,
549-
JSON.stringify({ address, chain: parseChain(chain), emailNotifications })
561+
JSON.stringify({
562+
address,
563+
chain: parseChainBackwardsCompatible(this.#env.name, chain),
564+
emailNotifications,
565+
})
550566
);
551567
}
552568

@@ -776,7 +792,10 @@ export class MoneriumClient {
776792
* @hidden
777793
*/
778794
getAuthFlowURI = (args: PKCERequestArgs): string => {
779-
const url = getAuthFlowUrlAndStoreCodeVerifier(this.#env.api, args);
795+
const url = getAuthFlowUrlAndStoreCodeVerifier(
796+
this.#env,
797+
mapChainIdToChain(this.#env.name, args)
798+
);
780799
return url;
781800
};
782801
}

packages/sdk/src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import type { Config } from './types';
33
const MONERIUM_CONFIG: Config = {
44
environments: {
55
production: {
6+
name: 'production',
67
api: 'https://api.monerium.app',
78
web: 'https://monerium.app',
89
wss: 'wss://api.monerium.app',
910
},
1011
sandbox: {
12+
name: 'sandbox',
1113
api: 'https://api.monerium.dev',
1214
web: 'https://sandbox.monerium.dev',
1315
wss: 'wss://api.monerium.dev',

packages/sdk/src/helpers/auth.helpers.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import {
66
AuthArgs,
77
AuthCodePayload,
88
ClientCredentialsPayload,
9+
Environment,
910
PKCERequest,
1011
PKCERequestArgs,
1112
RefreshTokenPayload,
1213
} from '../types';
13-
import { parseChain, urlEncoded } from '../utils';
14+
import { mapChainIdToChain, urlEncoded } from '../utils';
1415

1516
/** Structure the Auth Flow params */
1617
export const getAuthFlowParams = (
@@ -33,7 +34,7 @@ export const getAuthFlowParams = (
3334
? {
3435
address: address,
3536
...(signature !== undefined ? { signature: signature } : {}),
36-
...(chain !== undefined ? { chain: parseChain(chain) } : {}),
37+
...(chain !== undefined ? { chain: chain } : {}),
3738
}
3839
: {};
3940

@@ -82,15 +83,15 @@ export const generateCodeChallenge = (codeVerifier: string) => {
8283
* Constructs the Auth Flow URL and stores the code verifier in the local storage
8384
*/
8485
export const getAuthFlowUrlAndStoreCodeVerifier = (
85-
baseUrl: string,
86+
environment: Environment,
8687
args: PKCERequestArgs
8788
): string => {
8889
const codeVerifier = generateRandomString();
8990
const codeChallenge = generateCodeChallenge(codeVerifier);
9091

9192
localStorage.setItem(constants.STORAGE_CODE_VERIFIER, codeVerifier || '');
9293

93-
return `${baseUrl}/auth?${getAuthFlowParams(args, codeChallenge)}`;
94+
return `${environment.api}/auth?${getAuthFlowParams(mapChainIdToChain(environment.name, args), codeChallenge)}`;
9495
};
9596

9697
/**

packages/sdk/src/types.ts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
11
// --- Config --- //
22

3-
export type Environment = { api: string; web: string; wss: string };
3+
export type Environment = { name: ENV; api: string; web: string; wss: string };
44

55
export type Config = {
66
environments: { production: Environment; sandbox: Environment };
77
};
88

99
export type ENV = 'sandbox' | 'production';
1010

11-
export type Chain = 'ethereum' | 'gnosis' | 'polygon' | 'arbitrum' | 'noble';
11+
export type SandboxChain =
12+
| 'sepolia'
13+
| 'chiado'
14+
| 'amoy'
15+
| 'arbitrumsepolia'
16+
| 'lineasepolia'
17+
| 'grand';
18+
19+
export type ProductionChain =
20+
| 'ethereum'
21+
| 'gnosis'
22+
| 'polygon'
23+
| 'arbitrum'
24+
| 'linea'
25+
| 'noble';
26+
27+
export type Chain = string | ProductionChain | SandboxChain;
1228

1329
export type EvmChainId =
1430
| number
15-
| 1
16-
| 11155111
17-
| 100
18-
| 137
19-
| 10200
20-
| 80002
21-
| 42161
22-
| 421614;
31+
| 1 // ethereum mainnet
32+
| 11155111 // ethereum sepolia
33+
| 100 // gnosis
34+
| 10200 // gnosis chiado
35+
| 137 // polygon
36+
| 80002 // polygon amoy
37+
| 42161 // arbitrum
38+
| 421614 // arbitrum sepolia
39+
| 59141 // linea sepolia
40+
| 59144; // linea
2341

2442
export type ChainId = EvmChainId | CosmosChainId;
2543

0 commit comments

Comments
 (0)