Skip to content

Commit f72f1bf

Browse files
authored
fix: initial multichain core (#1317)
* fix: add initial implementation of the multichain building-block * fix: useUnknownInCatchVariables in tsconfig to allow err in catch to be any not unknown * fix: add error handling and rpcClient coverage * fix: add test coverage * fix: improve tests for multichain init * fix: improve testing coverage * fix: remove empty lines * fix: remove biome lint err * fix: add missing jsdom pkg * fix: code + test improvements * fix: session upgrade test * fix: using provider before its defined in sdk constructor * fix: testing against wrong expect
1 parent 30f9d30 commit f72f1bf

33 files changed

+2688
-64
lines changed

packages/sdk-multichain/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ src/
1919
│ ├── events/ # Event-driven communication
2020
│ ├── platform/ # Platform detection utilities
2121
│ └── store/ # Storage abstractions
22+
├── multichain/ # Concrete implementations
23+
└── store/ # Storage implementations
2224
```

packages/sdk-multichain/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@react-native-async-storage/async-storage": "^1.19.6",
3535
"@vitest/coverage-v8": "^3.2.4",
3636
"esbuild-plugin-umd-wrapper": "^3.0.0",
37+
"jsdom": "^26.1.0",
3738
"nock": "^14.0.4",
3839
"prettier": "^3.3.3",
3940
"tsup": "^8.5.0",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { ErrorCodes } from "./types";
2+
3+
export abstract class BaseErr<C extends string, T extends ErrorCodes> extends Error {
4+
constructor(
5+
public readonly message: `${C}Err${T}: ${string}`,
6+
public readonly code: T,
7+
) {
8+
super(message);
9+
}
10+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './rpc'
2+
export * from './types';
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
import { BaseErr } from "./base";
3+
import type { RPCErrorCodes } from "./types";
4+
5+
export class RPCHttpErr extends BaseErr<'RPC', RPCErrorCodes> {
6+
static readonly code = 50;
7+
constructor(
8+
readonly rpcEndpoint: string,
9+
readonly method: string,
10+
readonly httpStatus: number,
11+
) {
12+
super(
13+
`RPCErr${RPCHttpErr.code}: ${httpStatus} on ${rpcEndpoint} for method ${method}`,
14+
RPCHttpErr.code
15+
);
16+
}
17+
}
18+
19+
export class RPCReadonlyResponseErr extends BaseErr<'RPC', RPCErrorCodes> {
20+
static readonly code = 51;
21+
constructor(
22+
public readonly reason: string,
23+
) {
24+
super(
25+
`RPCErr${RPCReadonlyResponseErr.code}: RPC Client response reason ${reason}`,
26+
RPCReadonlyResponseErr.code
27+
);
28+
}
29+
}
30+
31+
export class RPCReadonlyRequestErr extends BaseErr<'RPC', RPCErrorCodes> {
32+
static readonly code = 52;
33+
constructor(
34+
public readonly reason: string,
35+
) {
36+
super(
37+
`RPCErr${RPCReadonlyRequestErr.code}: RPC Client fetch reason ${reason}`,
38+
RPCReadonlyRequestErr.code
39+
);
40+
}
41+
}
42+
43+
export class RPCInvokeMethodErr extends BaseErr<'RPC', RPCErrorCodes> {
44+
static readonly code = 53;
45+
constructor(
46+
public readonly reason: string,
47+
) {
48+
super(
49+
`RPCErr${RPCInvokeMethodErr.code}: RPC Client invoke method reason ${reason}`,
50+
RPCInvokeMethodErr.code
51+
);
52+
}
53+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
import { BaseErr } from "./base";
3+
import type { StorageErrorCodes } from "./types";
4+
5+
export class StorageGetErr extends BaseErr<'Storage', StorageErrorCodes> {
6+
static readonly code = 60;
7+
constructor(
8+
public readonly platform: 'web' | 'rn' | 'node',
9+
public readonly key: string,
10+
public readonly reason: string,
11+
) {
12+
super(
13+
`StorageErr${StorageGetErr.code}: ${platform} storage get error in key: ${key} - ${reason}`,
14+
StorageGetErr.code
15+
);
16+
}
17+
}
18+
19+
export class StorageSetErr extends BaseErr<'Storage', StorageErrorCodes> {
20+
static readonly code = 61;
21+
constructor(
22+
public readonly platform: 'web' | 'rn' | 'node',
23+
public readonly key: string,
24+
public readonly reason: string,
25+
) {
26+
super(
27+
`StorageErr${StorageSetErr.code}: ${platform} storage set error in key: ${key} - ${reason}`,
28+
StorageSetErr.code
29+
);
30+
}
31+
}
32+
33+
export class StorageDeleteErr extends BaseErr<'Storage', StorageErrorCodes> {
34+
static readonly code = 62;
35+
constructor(
36+
public readonly platform: 'web' | 'rn' | 'node',
37+
public readonly key: string,
38+
public readonly reason: string,
39+
) {
40+
super(
41+
`StorageErr${StorageDeleteErr.code}: ${platform} storage delete error in key: ${key} - ${reason}`,
42+
StorageDeleteErr.code
43+
);
44+
}
45+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N
2+
? Acc[number]
3+
: Enumerate<N, [...Acc, Acc['length']]>;
4+
5+
export type ErrorCodeRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
6+
7+
export type DomainErrorCodes = ErrorCodeRange<1, 50>;
8+
export type RPCErrorCodes = ErrorCodeRange<50, 60>;
9+
export type StorageErrorCodes = ErrorCodeRange<60, 70>;
10+
11+
export type ErrorCodes =
12+
| DomainErrorCodes
13+
| RPCErrorCodes
14+
| StorageErrorCodes;

packages/sdk-multichain/src/domain/index.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import * as t from 'vitest'
44
import Bowser from 'bowser';
55

6-
import { EventEmitter,ExtensionEvents, SDKEvents, getPlatformType, PlatformType, createLogger, enableDebug, isEnabled } from './';
7-
8-
6+
import { EventEmitter,type ExtensionEvents, type SDKEvents, getPlatformType, PlatformType, createLogger, enableDebug, isEnabled } from './';
97

108

119
const parseMock = t.vi.fn();

packages/sdk-multichain/src/domain/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from './errors';
12
export * from './platform';
23
export * from './multichain';
34
export * from './events';

packages/sdk-multichain/src/domain/multichain/api/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* c8 ignore start */
2-
import { RPC_URLS_MAP } from "./types";
2+
import type { RPC_URLS_MAP } from "./types";
33

44
export const infuraRpcUrls: RPC_URLS_MAP = {
55
// ###### Ethereum ######

0 commit comments

Comments
 (0)