@swapkit/core 1.0.0-rc.101 → 1.0.0-rc.103
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.es.js +4 -2
- package/dist/index.es.js.map +1 -1
- package/package.json +11 -11
- package/src/__tests__/helpers.test.ts +63 -58
- package/src/helpers/explorerUrls.ts +2 -0
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "swapkit-oss",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@swapkit/helpers": "1.0.0-rc.
|
|
5
|
-
"@swapkit/types": "1.0.0-rc.
|
|
4
|
+
"@swapkit/helpers": "1.0.0-rc.74",
|
|
5
|
+
"@swapkit/types": "1.0.0-rc.40"
|
|
6
6
|
},
|
|
7
7
|
"description": "SwapKit Lib core",
|
|
8
8
|
"devDependencies": {
|
|
@@ -10,17 +10,17 @@
|
|
|
10
10
|
"vite": "5.1.3",
|
|
11
11
|
"vitest": "1.3.1",
|
|
12
12
|
"@swapkit/tokens": "1.0.0-rc.36",
|
|
13
|
-
"@swapkit/toolbox-cosmos": "1.0.0-rc.
|
|
14
|
-
"@swapkit/toolbox-evm": "1.0.0-rc.
|
|
15
|
-
"@swapkit/toolbox-substrate": "1.0.0-rc.
|
|
16
|
-
"@swapkit/toolbox-utxo": "1.0.0-rc.
|
|
13
|
+
"@swapkit/toolbox-cosmos": "1.0.0-rc.85",
|
|
14
|
+
"@swapkit/toolbox-evm": "1.0.0-rc.80",
|
|
15
|
+
"@swapkit/toolbox-substrate": "1.0.0-rc.9",
|
|
16
|
+
"@swapkit/toolbox-utxo": "1.0.0-rc.80"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"@swapkit/tokens": "1.0.0-rc.36",
|
|
20
|
-
"@swapkit/toolbox-cosmos": "1.0.0-rc.
|
|
21
|
-
"@swapkit/toolbox-evm": "1.0.0-rc.
|
|
22
|
-
"@swapkit/toolbox-substrate": "1.0.0-rc.
|
|
23
|
-
"@swapkit/toolbox-utxo": "1.0.0-rc.
|
|
20
|
+
"@swapkit/toolbox-cosmos": "1.0.0-rc.85",
|
|
21
|
+
"@swapkit/toolbox-evm": "1.0.0-rc.80",
|
|
22
|
+
"@swapkit/toolbox-substrate": "1.0.0-rc.9",
|
|
23
|
+
"@swapkit/toolbox-utxo": "1.0.0-rc.80"
|
|
24
24
|
},
|
|
25
25
|
"exports": {
|
|
26
26
|
".": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"type": "module",
|
|
47
47
|
"types": "./dist/index.d.ts",
|
|
48
|
-
"version": "1.0.0-rc.
|
|
48
|
+
"version": "1.0.0-rc.103",
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "NODE_OPTIONS=--max_old_space_size=16384 vite build",
|
|
51
51
|
"clean": "rm -rf dist vite.config.ts.* node_modules",
|
|
@@ -1,79 +1,84 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Chain,
|
|
3
|
+
ChainToExplorerUrl,
|
|
4
|
+
CosmosChains,
|
|
5
|
+
EVMChains,
|
|
6
|
+
SubstrateChains,
|
|
7
|
+
UTXOChains,
|
|
8
|
+
} from "@swapkit/types";
|
|
2
9
|
import { describe, expect, test } from "vitest";
|
|
3
10
|
import { getExplorerAddressUrl, getExplorerTxUrl } from "../helpers/explorerUrls.ts";
|
|
4
11
|
|
|
5
12
|
describe("Explorer URLs", () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
describe("CosmosChains", () => {
|
|
14
|
+
for (const chain of CosmosChains.filter((c) => c !== Chain.Cosmos)) {
|
|
15
|
+
test(`getExplorerTxUrl returns correct URL for ${chain}`, () => {
|
|
16
|
+
expect(getExplorerTxUrl({ chain, txHash: "0x123456789" })).toBe(
|
|
17
|
+
`${ChainToExplorerUrl[chain]}/tx/123456789`,
|
|
18
|
+
);
|
|
11
19
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
expect(getExplorerAddressUrl({ chain, address: "asdfg" })).toBe(
|
|
21
|
+
`${ChainToExplorerUrl[chain]}/address/asdfg`,
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
17
25
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
`${ChainToExplorerUrl[chain]}/tx/0x123456789`,
|
|
26
|
+
test(`getExplorerTxUrl returns correct URL for ${Chain.Cosmos}`, () => {
|
|
27
|
+
expect(getExplorerTxUrl({ chain: Chain.Cosmos, txHash: "0x123456789" })).toBe(
|
|
28
|
+
`${ChainToExplorerUrl[Chain.Cosmos]}/transactions/0x123456789`,
|
|
22
29
|
);
|
|
23
30
|
|
|
24
|
-
expect(getExplorerAddressUrl({ chain, address: "asdfg" })).toBe(
|
|
25
|
-
`${ChainToExplorerUrl[
|
|
31
|
+
expect(getExplorerAddressUrl({ chain: Chain.Cosmos, address: "asdfg" })).toBe(
|
|
32
|
+
`${ChainToExplorerUrl[Chain.Cosmos]}/account/asdfg`,
|
|
26
33
|
);
|
|
27
34
|
});
|
|
28
|
-
}
|
|
35
|
+
});
|
|
29
36
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
describe("EVMChains & SubstrateChains", () => {
|
|
38
|
+
for (const chain of [...EVMChains, Chain.Polkadot]) {
|
|
39
|
+
test(`getExplorerTxUrl returns correct URL for ${chain}`, () => {
|
|
40
|
+
expect(getExplorerTxUrl({ chain, txHash: "0x123456789" })).toBe(
|
|
41
|
+
`${ChainToExplorerUrl[chain]}/tx/0x123456789`,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
expect(getExplorerAddressUrl({ chain, address: "asdfg" })).toBe(
|
|
45
|
+
`${ChainToExplorerUrl[chain]}/address/asdfg`,
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
35
49
|
|
|
36
|
-
|
|
37
|
-
|
|
50
|
+
test("getExplorerTxUrl adds 0x for EVM like chains", () => {
|
|
51
|
+
expect(getExplorerTxUrl({ chain: Chain.Ethereum, txHash: "12345" })).toBe(
|
|
52
|
+
"https://etherscan.io/tx/0x12345",
|
|
38
53
|
);
|
|
39
54
|
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
test(`getExplorerTxUrl returns correct URL for ${Chain.Cosmos}`, () => {
|
|
43
|
-
expect(getExplorerTxUrl({ chain: Chain.Cosmos, txHash: "0x123456789" })).toBe(
|
|
44
|
-
`${ChainToExplorerUrl[Chain.Cosmos]}/transactions/0x123456789`,
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
expect(getExplorerAddressUrl({ chain: Chain.Cosmos, address: "asdfg" })).toBe(
|
|
48
|
-
`${ChainToExplorerUrl[Chain.Cosmos]}/account/asdfg`,
|
|
49
|
-
);
|
|
50
55
|
});
|
|
51
56
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
getExplorerTxUrl
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
describe("UTXOChains", () => {
|
|
58
|
+
for (const chain of UTXOChains.filter((c) => c !== Chain.Dash)) {
|
|
59
|
+
test(`getExplorerTxUrl returns correct URL for ${chain}`, () => {
|
|
60
|
+
expect(getExplorerTxUrl({ chain, txHash: "0x123456789" })).toBe(
|
|
61
|
+
`${ChainToExplorerUrl[chain]}/transaction/0x123456789`,
|
|
62
|
+
);
|
|
57
63
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
test("getExplorerTxUrl adds 0x for EVM like chains", () => {
|
|
64
|
-
expect(getExplorerTxUrl({ chain: Chain.Ethereum, txHash: "12345" })).toBe(
|
|
65
|
-
"https://etherscan.io/tx/0x12345",
|
|
66
|
-
);
|
|
64
|
+
expect(getExplorerAddressUrl({ chain, address: "asdfg" })).toBe(
|
|
65
|
+
`${ChainToExplorerUrl[chain]}/address/asdfg`,
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
67
69
|
});
|
|
68
70
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
describe("Unsupported chains", () => {
|
|
72
|
+
test("getExplorerTxUrl throws Error for unsupported Chain", () => {
|
|
73
|
+
expect(() =>
|
|
74
|
+
getExplorerTxUrl({ chain: "unsupported" as Chain, txHash: "0x12345" }),
|
|
75
|
+
).toThrowError("Unsupported chain: unsupported");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("getExplorerAddressUrl throws Error for unsupported Chain", () => {
|
|
79
|
+
expect(() =>
|
|
80
|
+
getExplorerAddressUrl({ chain: "unsupported" as Chain, address: "asdfg" }),
|
|
81
|
+
).toThrowError("Unsupported chain: unsupported");
|
|
82
|
+
});
|
|
78
83
|
});
|
|
79
84
|
});
|
|
@@ -15,6 +15,7 @@ export const getExplorerTxUrl = ({ chain, txHash }: { txHash: string; chain: Cha
|
|
|
15
15
|
case Chain.BinanceSmartChain:
|
|
16
16
|
case Chain.Ethereum:
|
|
17
17
|
case Chain.Optimism:
|
|
18
|
+
case Chain.Polkadot:
|
|
18
19
|
case Chain.Polygon:
|
|
19
20
|
return `${baseUrl}/tx/${txHash.startsWith("0x") ? txHash : `0x${txHash}`}`;
|
|
20
21
|
|
|
@@ -48,6 +49,7 @@ export const getExplorerAddressUrl = ({ chain, address }: { address: string; cha
|
|
|
48
49
|
case Chain.Litecoin:
|
|
49
50
|
case Chain.Maya:
|
|
50
51
|
case Chain.Optimism:
|
|
52
|
+
case Chain.Polkadot:
|
|
51
53
|
case Chain.Polygon:
|
|
52
54
|
case Chain.THORChain:
|
|
53
55
|
return `${baseUrl}/address/${address}`;
|