@swapkit/helpers 1.0.0-rc.64 → 1.0.0-rc.66
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +9 -4
- package/dist/index.es.js +235 -230
- package/dist/index.es.js.map +1 -1
- package/package.json +4 -4
- package/src/modules/__tests__/assetValue.test.ts +19 -0
- package/src/modules/assetValue.ts +9 -2
- package/src/modules/swapKitError.ts +11 -4
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"author": "swapkit-oss-team",
|
|
3
3
|
"description": "SwapKit Lib swapkit-helpers",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@swapkit/api": "1.0.0-rc.
|
|
5
|
+
"@swapkit/api": "1.0.0-rc.35"
|
|
6
6
|
},
|
|
7
7
|
"devDependencies": {
|
|
8
8
|
"@vitest/coverage-istanbul": "1.2.1",
|
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|
"vitest": "1.2.1",
|
|
11
11
|
"@internal/config": "0.0.2-rc.0",
|
|
12
12
|
"@swapkit/tokens": "1.0.0-rc.33",
|
|
13
|
-
"@swapkit/types": "1.0.0-rc.
|
|
13
|
+
"@swapkit/types": "1.0.0-rc.34"
|
|
14
14
|
},
|
|
15
15
|
"eslintConfig": {
|
|
16
16
|
"extends": "../../../internal/eslint-config"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"@swapkit/tokens": "1.0.0-rc.33",
|
|
20
|
-
"@swapkit/types": "1.0.0-rc.
|
|
20
|
+
"@swapkit/types": "1.0.0-rc.34"
|
|
21
21
|
},
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"type": "module",
|
|
44
44
|
"types": "./dist/index.d.ts",
|
|
45
|
-
"version": "1.0.0-rc.
|
|
45
|
+
"version": "1.0.0-rc.66",
|
|
46
46
|
"scripts": {
|
|
47
47
|
"build": "vite build",
|
|
48
48
|
"clean": "rm -rf dist vite.config.ts.* .turbo node_modules",
|
|
@@ -254,6 +254,25 @@ describe('AssetValue', () => {
|
|
|
254
254
|
}),
|
|
255
255
|
);
|
|
256
256
|
});
|
|
257
|
+
|
|
258
|
+
test('returns proper avax string with address from `@swapkit/tokens` lists', async () => {
|
|
259
|
+
await AssetValue.loadStaticAssets();
|
|
260
|
+
const avaxBTCb = 'AVAX.BTC.b-0x152b9d0fdc40c096757f570a51e494bd4b943e50';
|
|
261
|
+
const AvaxBTCb = AssetValue.fromStringSync(avaxBTCb);
|
|
262
|
+
|
|
263
|
+
expect(AvaxBTCb).toBeDefined();
|
|
264
|
+
expect(AvaxBTCb).toEqual(
|
|
265
|
+
expect.objectContaining({
|
|
266
|
+
address: '0x152b9d0fdc40c096757f570a51e494bd4b943e50',
|
|
267
|
+
chain: Chain.Avalanche,
|
|
268
|
+
decimal: 8,
|
|
269
|
+
isGasAsset: false,
|
|
270
|
+
isSynthetic: false,
|
|
271
|
+
symbol: 'BTC.b-0x152b9d0fdc40c096757f570a51e494bd4b943e50',
|
|
272
|
+
ticker: 'BTC.b',
|
|
273
|
+
}),
|
|
274
|
+
);
|
|
275
|
+
});
|
|
257
276
|
});
|
|
258
277
|
|
|
259
278
|
describe('fromChainOrSignature', () => {
|
|
@@ -108,6 +108,7 @@ export class AssetValue extends BigIntArithmetics {
|
|
|
108
108
|
decimal: BaseDecimal[chain],
|
|
109
109
|
identifier: assetString,
|
|
110
110
|
};
|
|
111
|
+
|
|
111
112
|
return new AssetValue({
|
|
112
113
|
tax,
|
|
113
114
|
value: safeValue(value, decimal),
|
|
@@ -231,8 +232,10 @@ function safeValue(value: NumberPrimitives, decimal: number) {
|
|
|
231
232
|
: value;
|
|
232
233
|
}
|
|
233
234
|
|
|
235
|
+
// TODO refactor & split into smaller functions
|
|
234
236
|
function getAssetInfo(identifier: string) {
|
|
235
237
|
const isSynthetic = identifier.slice(0, 14).includes('/');
|
|
238
|
+
|
|
236
239
|
const [synthChain, synthSymbol] =
|
|
237
240
|
identifier.split('.')[0].toUpperCase() === Chain.THORChain
|
|
238
241
|
? identifier.split('.').slice(1)!.join().split('/')
|
|
@@ -243,8 +246,12 @@ function getAssetInfo(identifier: string) {
|
|
|
243
246
|
const adjustedIdentifier =
|
|
244
247
|
identifier.includes('.') && !isSynthetic ? identifier : `${Chain.THORChain}.${synthSymbol}`;
|
|
245
248
|
|
|
246
|
-
const [chain,
|
|
247
|
-
const [ticker, address] = (isSynthetic ? synthSymbol :
|
|
249
|
+
const [chain, ...rest] = adjustedIdentifier.split('.') as [Chain, string];
|
|
250
|
+
const [ticker, address] = (isSynthetic ? synthSymbol : rest.join('.')).split('-') as [
|
|
251
|
+
string,
|
|
252
|
+
string?,
|
|
253
|
+
];
|
|
254
|
+
const symbol = isSynthetic ? synthSymbol : rest.join('.');
|
|
248
255
|
|
|
249
256
|
return {
|
|
250
257
|
address: address?.toLowerCase(),
|
|
@@ -47,12 +47,17 @@ const errorMessages = {
|
|
|
47
47
|
core_transaction_deposit_insufficient_funds_error: 10311,
|
|
48
48
|
core_transaction_deposit_gas_error: 10312,
|
|
49
49
|
core_transaction_invalid_sender_address: 10313,
|
|
50
|
-
core_transaction_deposit_server_error:
|
|
50
|
+
core_transaction_deposit_server_error: 10314,
|
|
51
|
+
core_transaction_user_rejected: 10315,
|
|
51
52
|
|
|
52
53
|
/**
|
|
53
54
|
* Wallets
|
|
54
55
|
*/
|
|
55
56
|
wallet_ledger_connection_error: 20001,
|
|
57
|
+
wallet_ledger_connection_claimed: 20002,
|
|
58
|
+
wallet_ledger_get_address_error: 20003,
|
|
59
|
+
wallet_ledger_device_not_found: 20004,
|
|
60
|
+
wallet_ledger_device_locked: 20005,
|
|
56
61
|
|
|
57
62
|
/**
|
|
58
63
|
* Helpers
|
|
@@ -60,11 +65,13 @@ const errorMessages = {
|
|
|
60
65
|
helpers_number_different_decimals: 99101,
|
|
61
66
|
} as const;
|
|
62
67
|
|
|
63
|
-
export type
|
|
68
|
+
export type ErrorKeys = keyof typeof errorMessages;
|
|
64
69
|
|
|
65
70
|
export class SwapKitError extends Error {
|
|
66
|
-
constructor(errorKey:
|
|
67
|
-
|
|
71
|
+
constructor(errorKey: ErrorKeys, sourceError?: any) {
|
|
72
|
+
if (sourceError) {
|
|
73
|
+
console.error(sourceError, { stack: sourceError?.stack, message: sourceError?.message });
|
|
74
|
+
}
|
|
68
75
|
|
|
69
76
|
super(errorKey, { cause: { code: errorMessages[errorKey], message: errorKey } });
|
|
70
77
|
Object.setPrototypeOf(this, SwapKitError.prototype);
|