@subwallet/extension-base 1.3.22-0 → 1.3.23-0
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/background/KoniTypes.d.ts +75 -2
- package/background/KoniTypes.js +2 -0
- package/cjs/background/KoniTypes.js +2 -0
- package/cjs/constants/environment.js +4 -2
- package/cjs/constants/signing.js +6 -2
- package/cjs/core/logic-validation/recipientAddress.js +9 -1
- package/cjs/core/logic-validation/transfer.js +35 -29
- package/cjs/core/types.js +1 -0
- package/cjs/core/utils.js +12 -1
- package/cjs/defaults.js +1 -1
- package/cjs/koni/api/dotsama/crowdloan.js +1 -1
- package/cjs/koni/api/nft/index.js +9 -16
- package/cjs/koni/api/staking/index.js +3 -4
- package/cjs/koni/background/handlers/Extension.js +234 -96
- package/cjs/koni/background/handlers/State.js +15 -0
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/cardano/consts.js +11 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/index.js +63 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/types.js +1 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/utils.js +74 -0
- package/cjs/services/balance-service/helpers/subscribe/index.js +21 -7
- package/cjs/services/balance-service/helpers/subscribe/ton/utils.js +2 -2
- package/cjs/services/balance-service/index.js +4 -2
- package/cjs/services/balance-service/transfer/cardano-transfer.js +122 -0
- package/cjs/services/balance-service/transfer/token.js +4 -4
- package/cjs/services/chain-service/handler/CardanoApi.js +176 -0
- package/cjs/services/chain-service/handler/CardanoChainHandler.js +83 -0
- package/cjs/services/chain-service/handler/TonApi.js +2 -5
- package/cjs/services/chain-service/index.js +29 -7
- package/cjs/services/chain-service/utils/index.js +40 -11
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost-manta.js +1 -1
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +1 -1
- package/cjs/services/earning-service/service.js +6 -12
- package/cjs/services/fee-service/service.js +19 -8
- package/cjs/services/history-service/index.js +4 -6
- package/cjs/services/inapp-notification-service/index.js +12 -4
- package/cjs/services/keyring-service/context/account-context.js +17 -2
- package/cjs/services/keyring-service/context/handlers/Derive.js +10 -7
- package/cjs/services/keyring-service/context/handlers/Migration.js +268 -0
- package/cjs/services/keyring-service/context/handlers/Mnemonic.js +2 -2
- package/cjs/services/keyring-service/context/handlers/Secret.js +1 -1
- package/cjs/services/keyring-service/utils.js +18 -0
- package/cjs/services/request-service/handler/CardanoRequestHandler.js +172 -0
- package/cjs/services/request-service/handler/EvmRequestHandler.js +1 -1
- package/cjs/services/request-service/index.js +20 -2
- package/cjs/services/setting-service/constants.js +10 -1
- package/cjs/services/storage-service/DatabaseService.js +3 -0
- package/cjs/services/storage-service/db-stores/InappNotification.js +6 -0
- package/cjs/services/swap-service/handler/asset-hub/handler.js +0 -59
- package/cjs/services/swap-service/handler/chainflip-handler.js +33 -281
- package/cjs/services/swap-service/handler/hydradx-handler.js +23 -190
- package/cjs/services/swap-service/handler/simpleswap-handler.js +1 -222
- package/cjs/services/swap-service/handler/uniswap-handler.js +331 -0
- package/cjs/services/swap-service/index.js +31 -22
- package/cjs/services/swap-service/utils.js +21 -38
- package/cjs/services/transaction-service/helpers/index.js +6 -1
- package/cjs/services/transaction-service/index.js +278 -21
- package/cjs/services/transaction-service/utils.js +5 -1
- package/cjs/types/account/info/keyring.js +12 -1
- package/cjs/types/fee/cardano.js +1 -0
- package/cjs/types/swap/index.js +7 -2
- package/cjs/utils/account/analyze.js +2 -1
- package/cjs/utils/account/common.js +29 -20
- package/cjs/utils/account/derive/info/solo.js +9 -4
- package/cjs/utils/account/derive/validate.js +36 -2
- package/cjs/utils/account/transform.js +38 -13
- package/cjs/utils/fee/transfer.js +40 -7
- package/cjs/utils/index.js +2 -2
- package/cjs/utils/staticData/index.js +7 -2
- package/constants/environment.d.ts +1 -0
- package/constants/environment.js +2 -1
- package/constants/signing.js +6 -2
- package/core/logic-validation/recipientAddress.js +11 -3
- package/core/logic-validation/transfer.js +9 -3
- package/core/substrate/xcm-parser.d.ts +1 -1
- package/core/types.d.ts +1 -0
- package/core/types.js +1 -0
- package/core/utils.d.ts +1 -0
- package/core/utils.js +13 -3
- package/defaults.d.ts +1 -1
- package/defaults.js +1 -1
- package/koni/api/dotsama/crowdloan.js +3 -3
- package/koni/api/nft/index.js +10 -16
- package/koni/api/nft/story_odyssey_nft/index.d.ts +1 -1
- package/koni/api/staking/index.js +4 -5
- package/koni/background/handlers/Extension.d.ts +9 -0
- package/koni/background/handlers/Extension.js +144 -8
- package/koni/background/handlers/State.d.ts +5 -1
- package/koni/background/handlers/State.js +16 -1
- package/package.json +71 -9
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/cardano/consts.d.ts +1 -0
- package/services/balance-service/helpers/subscribe/cardano/consts.js +4 -0
- package/services/balance-service/helpers/subscribe/cardano/index.d.ts +2 -0
- package/services/balance-service/helpers/subscribe/cardano/index.js +57 -0
- package/services/balance-service/helpers/subscribe/cardano/types.d.ts +34 -0
- package/services/balance-service/helpers/subscribe/cardano/types.js +1 -0
- package/services/balance-service/helpers/subscribe/cardano/utils.d.ts +15 -0
- package/services/balance-service/helpers/subscribe/cardano/utils.js +62 -0
- package/services/balance-service/helpers/subscribe/index.d.ts +2 -2
- package/services/balance-service/helpers/subscribe/index.js +23 -9
- package/services/balance-service/helpers/subscribe/ton/utils.d.ts +1 -1
- package/services/balance-service/helpers/subscribe/ton/utils.js +1 -1
- package/services/balance-service/index.js +4 -2
- package/services/balance-service/transfer/cardano-transfer.d.ts +24 -0
- package/services/balance-service/transfer/cardano-transfer.js +114 -0
- package/services/balance-service/transfer/token.d.ts +1 -1
- package/services/balance-service/transfer/token.js +2 -2
- package/services/chain-service/handler/CardanoApi.d.ts +38 -0
- package/services/chain-service/handler/CardanoApi.js +167 -0
- package/services/chain-service/handler/CardanoChainHandler.d.ts +17 -0
- package/services/chain-service/handler/CardanoChainHandler.js +75 -0
- package/services/chain-service/handler/TonApi.js +3 -6
- package/services/chain-service/handler/types.d.ts +1 -0
- package/services/chain-service/index.d.ts +3 -1
- package/services/chain-service/index.js +29 -7
- package/services/chain-service/types.d.ts +9 -1
- package/services/chain-service/utils/index.d.ts +4 -0
- package/services/chain-service/utils/index.js +32 -11
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/handlers/liquid-staking/bifrost-manta.js +1 -1
- package/services/earning-service/handlers/liquid-staking/bifrost.js +1 -1
- package/services/earning-service/service.js +8 -14
- package/services/fee-service/service.js +19 -8
- package/services/history-service/index.js +6 -8
- package/services/inapp-notification-service/index.d.ts +3 -4
- package/services/inapp-notification-service/index.js +14 -6
- package/services/keyring-service/context/account-context.d.ts +6 -2
- package/services/keyring-service/context/account-context.js +17 -2
- package/services/keyring-service/context/handlers/Derive.d.ts +1 -1
- package/services/keyring-service/context/handlers/Derive.js +10 -8
- package/services/keyring-service/context/handlers/Migration.d.ts +17 -0
- package/services/keyring-service/context/handlers/Migration.js +258 -0
- package/services/keyring-service/context/handlers/Mnemonic.js +2 -2
- package/services/keyring-service/context/handlers/Secret.js +2 -2
- package/services/keyring-service/utils.d.ts +2 -0
- package/services/keyring-service/utils.js +11 -0
- package/services/request-service/handler/CardanoRequestHandler.d.ts +16 -0
- package/services/request-service/handler/CardanoRequestHandler.js +163 -0
- package/services/request-service/handler/EvmRequestHandler.js +1 -1
- package/services/request-service/index.d.ts +6 -3
- package/services/request-service/index.js +19 -5
- package/services/setting-service/constants.d.ts +3 -0
- package/services/setting-service/constants.js +6 -0
- package/services/storage-service/DatabaseService.d.ts +1 -0
- package/services/storage-service/DatabaseService.js +3 -0
- package/services/storage-service/db-stores/InappNotification.d.ts +1 -0
- package/services/storage-service/db-stores/InappNotification.js +6 -0
- package/services/swap-service/handler/asset-hub/handler.d.ts +1 -4
- package/services/swap-service/handler/asset-hub/handler.js +2 -61
- package/services/swap-service/handler/base-handler.d.ts +1 -4
- package/services/swap-service/handler/chainflip-handler.d.ts +2 -9
- package/services/swap-service/handler/chainflip-handler.js +31 -280
- package/services/swap-service/handler/hydradx-handler.d.ts +1 -6
- package/services/swap-service/handler/hydradx-handler.js +13 -180
- package/services/swap-service/handler/simpleswap-handler.d.ts +1 -4
- package/services/swap-service/handler/simpleswap-handler.js +5 -226
- package/services/swap-service/handler/uniswap-handler.d.ts +41 -0
- package/services/swap-service/handler/uniswap-handler.js +323 -0
- package/services/swap-service/index.js +30 -22
- package/services/swap-service/utils.d.ts +1 -5
- package/services/swap-service/utils.js +7 -21
- package/services/transaction-service/helpers/index.d.ts +2 -0
- package/services/transaction-service/helpers/index.js +4 -0
- package/services/transaction-service/index.d.ts +8 -2
- package/services/transaction-service/index.js +263 -10
- package/services/transaction-service/types.d.ts +7 -0
- package/services/transaction-service/utils.js +7 -2
- package/types/account/info/keyring.d.ts +4 -1
- package/types/account/info/keyring.js +9 -0
- package/types/account/info/proxy.d.ts +2 -0
- package/types/balance/index.d.ts +4 -1
- package/types/fee/base.d.ts +1 -1
- package/types/fee/cardano.d.ts +18 -0
- package/types/fee/cardano.js +1 -0
- package/types/fee/subscription.d.ts +4 -3
- package/types/swap/index.d.ts +11 -3
- package/types/swap/index.js +7 -2
- package/utils/account/analyze.js +2 -1
- package/utils/account/common.d.ts +11 -6
- package/utils/account/common.js +28 -19
- package/utils/account/derive/info/solo.js +10 -5
- package/utils/account/derive/validate.d.ts +1 -0
- package/utils/account/derive/validate.js +34 -1
- package/utils/account/transform.d.ts +2 -1
- package/utils/account/transform.js +37 -13
- package/utils/fee/transfer.d.ts +2 -1
- package/utils/fee/transfer.js +44 -11
- package/utils/index.js +4 -4
- package/utils/staticData/index.d.ts +4 -1
- package/utils/staticData/index.js +5 -1
- package/utils/staticData/oldChainPrefix.json +1 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { cborToBytes, retryCardanoTxStatus } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/cardano/utils';
|
|
5
|
+
import { _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
|
|
6
|
+
import { createPromiseHandler } from '@subwallet/extension-base/utils';
|
|
7
|
+
import { BehaviorSubject } from 'rxjs';
|
|
8
|
+
import { hexAddPrefix, isHex } from '@polkadot/util';
|
|
9
|
+
export const API_KEY = {
|
|
10
|
+
mainnet: process.env.BLOCKFROST_API_KEY_MAIN || '',
|
|
11
|
+
testnet: process.env.BLOCKFROST_API_KEY_PREP || ''
|
|
12
|
+
};
|
|
13
|
+
export class CardanoApi {
|
|
14
|
+
// private api: BlockFrostAPI;
|
|
15
|
+
|
|
16
|
+
apiRetry = 0;
|
|
17
|
+
isApiConnectedSubject = new BehaviorSubject(false);
|
|
18
|
+
connectionStatusSubject = new BehaviorSubject(_ChainConnectionStatus.DISCONNECTED);
|
|
19
|
+
isApiReady = false;
|
|
20
|
+
isApiReadyOnce = false;
|
|
21
|
+
constructor(chainSlug, apiUrl, {
|
|
22
|
+
isTestnet,
|
|
23
|
+
providerName
|
|
24
|
+
}) {
|
|
25
|
+
this.chainSlug = chainSlug;
|
|
26
|
+
this.apiUrl = apiUrl;
|
|
27
|
+
this.isTestnet = isTestnet !== null && isTestnet !== void 0 ? isTestnet : true;
|
|
28
|
+
this.projectId = isTestnet ? API_KEY.testnet : API_KEY.mainnet;
|
|
29
|
+
this.providerName = providerName || 'unknown';
|
|
30
|
+
// this.api = this.createProvider(isTestnet);
|
|
31
|
+
this.isReadyHandler = createPromiseHandler();
|
|
32
|
+
this.connect();
|
|
33
|
+
}
|
|
34
|
+
get isApiConnected() {
|
|
35
|
+
return this.isApiConnectedSubject.getValue();
|
|
36
|
+
}
|
|
37
|
+
get connectionStatus() {
|
|
38
|
+
return this.connectionStatusSubject.getValue();
|
|
39
|
+
}
|
|
40
|
+
updateConnectionStatus(status) {
|
|
41
|
+
const isConnected = status === _ChainConnectionStatus.CONNECTED;
|
|
42
|
+
if (isConnected !== this.isApiConnectedSubject.value) {
|
|
43
|
+
this.isApiConnectedSubject.next(isConnected);
|
|
44
|
+
}
|
|
45
|
+
if (status !== this.connectionStatusSubject.value) {
|
|
46
|
+
this.connectionStatusSubject.next(status);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
get isReady() {
|
|
50
|
+
return this.isReadyHandler.promise;
|
|
51
|
+
}
|
|
52
|
+
async updateApiUrl(apiUrl) {
|
|
53
|
+
if (this.apiUrl === apiUrl) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
await this.disconnect();
|
|
57
|
+
this.apiUrl = apiUrl;
|
|
58
|
+
// this.api = this.createProvider();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async recoverConnect() {
|
|
62
|
+
await this.disconnect();
|
|
63
|
+
this.connect();
|
|
64
|
+
await this.isReadyHandler.promise;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// private createProvider (isTestnet = true): BlockFrostAPI {
|
|
68
|
+
// const projectId = isTestnet ? API_KEY.testnet : API_KEY.mainnet;
|
|
69
|
+
//
|
|
70
|
+
// return new BlockFrostAPI({
|
|
71
|
+
// projectId
|
|
72
|
+
// });
|
|
73
|
+
// }
|
|
74
|
+
|
|
75
|
+
connect() {
|
|
76
|
+
this.updateConnectionStatus(_ChainConnectionStatus.CONNECTING);
|
|
77
|
+
// There isn't a persistent network connection underlying TonClient. Cant check connection status.
|
|
78
|
+
// this.isApiReadyOnce = true;
|
|
79
|
+
this.onConnect();
|
|
80
|
+
}
|
|
81
|
+
async disconnect() {
|
|
82
|
+
this.onDisconnect();
|
|
83
|
+
this.updateConnectionStatus(_ChainConnectionStatus.DISCONNECTED);
|
|
84
|
+
return Promise.resolve();
|
|
85
|
+
}
|
|
86
|
+
destroy() {
|
|
87
|
+
// Todo: implement this in the future
|
|
88
|
+
return this.disconnect();
|
|
89
|
+
}
|
|
90
|
+
onConnect() {
|
|
91
|
+
if (!this.isApiConnected) {
|
|
92
|
+
console.log(`Connected to ${this.chainSlug} at ${this.apiUrl}`);
|
|
93
|
+
this.isApiReady = true;
|
|
94
|
+
if (this.isApiReadyOnce) {
|
|
95
|
+
this.isReadyHandler.resolve(this);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
this.updateConnectionStatus(_ChainConnectionStatus.CONNECTED);
|
|
99
|
+
}
|
|
100
|
+
onDisconnect() {
|
|
101
|
+
this.updateConnectionStatus(_ChainConnectionStatus.DISCONNECTED);
|
|
102
|
+
if (this.isApiConnected) {
|
|
103
|
+
console.warn(`Disconnected from ${this.chainSlug} of ${this.apiUrl}`);
|
|
104
|
+
this.isApiReady = false;
|
|
105
|
+
this.isReadyHandler = createPromiseHandler();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async getBalanceMap(address) {
|
|
109
|
+
try {
|
|
110
|
+
const url = this.isTestnet ? `https://cardano-preprod.blockfrost.io/api/v0/addresses/${address}` : `https://cardano-mainnet.blockfrost.io/api/v0/addresses/${address}`;
|
|
111
|
+
const response = await fetch(url, {
|
|
112
|
+
method: 'GET',
|
|
113
|
+
headers: {
|
|
114
|
+
Project_id: this.projectId
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
const addressBalance = await response.json();
|
|
118
|
+
return addressBalance.amount;
|
|
119
|
+
} catch (e) {
|
|
120
|
+
console.error('Error on getting account balance', e);
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async sendCardanoTxReturnHash(tx) {
|
|
125
|
+
try {
|
|
126
|
+
const url = this.isTestnet ? 'https://cardano-preprod.blockfrost.io/api/v0/tx/submit' : 'https://cardano-mainnet.blockfrost.io/api/v0/tx/submit';
|
|
127
|
+
const response = await fetch(url, {
|
|
128
|
+
method: 'POST',
|
|
129
|
+
headers: {
|
|
130
|
+
Project_id: this.projectId,
|
|
131
|
+
'Content-Type': 'application/cbor'
|
|
132
|
+
},
|
|
133
|
+
body: cborToBytes(tx)
|
|
134
|
+
});
|
|
135
|
+
const hash = (await response.text()).replace(/^"|"$/g, '');
|
|
136
|
+
if (isHex(hexAddPrefix(hash))) {
|
|
137
|
+
return hash;
|
|
138
|
+
} else {
|
|
139
|
+
console.error('Error on submitting cardano tx');
|
|
140
|
+
return '';
|
|
141
|
+
}
|
|
142
|
+
} catch (e) {
|
|
143
|
+
console.error('Error on submitting cardano tx', e);
|
|
144
|
+
return '';
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
async getStatusByTxHash(txHash, ttl) {
|
|
148
|
+
const cronTime = 30000;
|
|
149
|
+
return retryCardanoTxStatus(async () => {
|
|
150
|
+
const url = this.isTestnet ? `https://cardano-preprod.blockfrost.io/api/v0/txs/${txHash}` : `https://cardano-mainnet.blockfrost.io/api/v0/txs/${txHash}`;
|
|
151
|
+
const response = await fetch(url, {
|
|
152
|
+
method: 'GET',
|
|
153
|
+
headers: {
|
|
154
|
+
Project_id: this.projectId
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
const txInfo = await response.json();
|
|
158
|
+
if (txInfo.block && txInfo.hash && txInfo.index >= 0) {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
throw new Error('Transaction not found');
|
|
162
|
+
}, {
|
|
163
|
+
retries: ttl / cronTime,
|
|
164
|
+
delay: cronTime
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
2
|
+
import { AbstractChainHandler } from '@subwallet/extension-base/services/chain-service/handler/AbstractChainHandler';
|
|
3
|
+
import { CardanoApi } from '@subwallet/extension-base/services/chain-service/handler/CardanoApi';
|
|
4
|
+
import { _ApiOptions } from '@subwallet/extension-base/services/chain-service/handler/types';
|
|
5
|
+
export declare class CardanoChainHandler extends AbstractChainHandler {
|
|
6
|
+
private cardanoApiMap;
|
|
7
|
+
constructor(parent?: ChainService);
|
|
8
|
+
getCardanoApiMap(): Record<string, CardanoApi>;
|
|
9
|
+
getCardanoApiByChain(chain: string): CardanoApi;
|
|
10
|
+
getApiByChain(chain: string): CardanoApi;
|
|
11
|
+
setCardanoApi(chain: string, cardanoApi: CardanoApi): void;
|
|
12
|
+
initApi(chainSlug: string, apiUrl: string, { isTestnet, onUpdateStatus, providerName }?: Omit<_ApiOptions, 'metadata'>): Promise<CardanoApi>;
|
|
13
|
+
recoverApi(chain: string): Promise<void>;
|
|
14
|
+
destroyCardanoApi(chain: string): void;
|
|
15
|
+
sleep(): Promise<void>;
|
|
16
|
+
wakeUp(): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { AbstractChainHandler } from '@subwallet/extension-base/services/chain-service/handler/AbstractChainHandler';
|
|
5
|
+
import { CardanoApi } from '@subwallet/extension-base/services/chain-service/handler/CardanoApi';
|
|
6
|
+
export class CardanoChainHandler extends AbstractChainHandler {
|
|
7
|
+
cardanoApiMap = {};
|
|
8
|
+
|
|
9
|
+
// eslint-disable-next-line no-useless-constructor
|
|
10
|
+
constructor(parent) {
|
|
11
|
+
super(parent);
|
|
12
|
+
}
|
|
13
|
+
getCardanoApiMap() {
|
|
14
|
+
return this.cardanoApiMap;
|
|
15
|
+
}
|
|
16
|
+
getCardanoApiByChain(chain) {
|
|
17
|
+
return this.cardanoApiMap[chain];
|
|
18
|
+
}
|
|
19
|
+
getApiByChain(chain) {
|
|
20
|
+
return this.getCardanoApiByChain(chain);
|
|
21
|
+
}
|
|
22
|
+
setCardanoApi(chain, cardanoApi) {
|
|
23
|
+
this.cardanoApiMap[chain] = cardanoApi;
|
|
24
|
+
}
|
|
25
|
+
async initApi(chainSlug, apiUrl, {
|
|
26
|
+
isTestnet,
|
|
27
|
+
onUpdateStatus,
|
|
28
|
+
providerName
|
|
29
|
+
} = {}) {
|
|
30
|
+
const existed = this.getCardanoApiByChain(chainSlug);
|
|
31
|
+
if (existed) {
|
|
32
|
+
existed.connect();
|
|
33
|
+
if (apiUrl !== existed.apiUrl) {
|
|
34
|
+
existed.updateApiUrl(apiUrl).catch(console.error);
|
|
35
|
+
}
|
|
36
|
+
return existed;
|
|
37
|
+
}
|
|
38
|
+
const apiObject = new CardanoApi(chainSlug, apiUrl, {
|
|
39
|
+
isTestnet,
|
|
40
|
+
providerName
|
|
41
|
+
});
|
|
42
|
+
apiObject.connectionStatusSubject.subscribe(this.handleConnection.bind(this, chainSlug));
|
|
43
|
+
apiObject.connectionStatusSubject.subscribe(onUpdateStatus);
|
|
44
|
+
return Promise.resolve(apiObject);
|
|
45
|
+
}
|
|
46
|
+
async recoverApi(chain) {
|
|
47
|
+
const existed = this.getCardanoApiByChain(chain);
|
|
48
|
+
if (existed && !existed.isApiReadyOnce) {
|
|
49
|
+
console.log(`Reconnect ${existed.providerName || existed.chainSlug} at ${existed.apiUrl}`);
|
|
50
|
+
return existed.recoverConnect();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
destroyCardanoApi(chain) {
|
|
54
|
+
const cardanoApi = this.getCardanoApiByChain(chain);
|
|
55
|
+
cardanoApi === null || cardanoApi === void 0 ? void 0 : cardanoApi.destroy().catch(console.error);
|
|
56
|
+
}
|
|
57
|
+
async sleep() {
|
|
58
|
+
this.isSleeping = true;
|
|
59
|
+
this.cancelAllRecover();
|
|
60
|
+
await Promise.all(Object.values(this.getCardanoApiMap()).map(cardanoApi => {
|
|
61
|
+
return cardanoApi.disconnect().catch(console.error);
|
|
62
|
+
}));
|
|
63
|
+
return Promise.resolve();
|
|
64
|
+
}
|
|
65
|
+
wakeUp() {
|
|
66
|
+
var _this$parent;
|
|
67
|
+
this.isSleeping = false;
|
|
68
|
+
const activeChains = ((_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.getActiveChains()) || [];
|
|
69
|
+
for (const chain of activeChains) {
|
|
70
|
+
const cardanoApi = this.getCardanoApiByChain(chain);
|
|
71
|
+
cardanoApi === null || cardanoApi === void 0 ? void 0 : cardanoApi.connect();
|
|
72
|
+
}
|
|
73
|
+
return Promise.resolve();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
5
|
import { TON_CENTER_API_KEY, TON_OPCODES } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/consts';
|
|
6
|
-
import { getJettonTxStatus,
|
|
6
|
+
import { getJettonTxStatus, retryTonTxStatus } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/utils';
|
|
7
7
|
import { _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
|
|
8
8
|
import { createPromiseHandler } from '@subwallet/extension-base/utils';
|
|
9
9
|
import { TonClient } from '@ton/ton';
|
|
@@ -50,10 +50,7 @@ export class TonApi {
|
|
|
50
50
|
|
|
51
51
|
// Create new provider and api
|
|
52
52
|
this.apiUrl = apiUrl;
|
|
53
|
-
this.api =
|
|
54
|
-
endpoint: this.getJsonRpc(this.apiUrl),
|
|
55
|
-
apiKey: TON_CENTER_API_KEY
|
|
56
|
-
});
|
|
53
|
+
this.api = this.createProvider(apiUrl);
|
|
57
54
|
}
|
|
58
55
|
async recoverConnect() {
|
|
59
56
|
await this.disconnect();
|
|
@@ -155,7 +152,7 @@ export class TonApi {
|
|
|
155
152
|
return await resp.json();
|
|
156
153
|
}
|
|
157
154
|
async getStatusByExtMsgHash(extMsgHash, extrinsicType) {
|
|
158
|
-
return
|
|
155
|
+
return retryTonTxStatus(async () => {
|
|
159
156
|
var _externalTxInfo$out_m, _externalTxInfo$out_m2;
|
|
160
157
|
// retry many times to get transaction status and transaction hex
|
|
161
158
|
const externalTxInfoRaw = await this.getTxByInMsg(extMsgHash);
|
|
@@ -22,6 +22,7 @@ export interface _ApiOptions {
|
|
|
22
22
|
metadata?: MetadataItem;
|
|
23
23
|
onUpdateStatus?: (status: _ChainConnectionStatus) => void;
|
|
24
24
|
externalApiPromise?: ApiPromise;
|
|
25
|
+
isTestnet?: boolean;
|
|
25
26
|
}
|
|
26
27
|
export declare enum _CHAIN_VALIDATION_ERROR {
|
|
27
28
|
INVALID_INFO_TYPE = "invalidInfoType",
|
|
@@ -17,6 +17,7 @@ export declare class ChainService {
|
|
|
17
17
|
private substrateChainHandler;
|
|
18
18
|
private evmChainHandler;
|
|
19
19
|
private tonChainHandler;
|
|
20
|
+
private cardanoChainHandler;
|
|
20
21
|
private mantaChainHandler;
|
|
21
22
|
refreshLatestChainDataTimeOut: NodeJS.Timer | undefined;
|
|
22
23
|
get mantaPay(): MantaPrivateHandler | undefined;
|
|
@@ -54,6 +55,8 @@ export declare class ChainService {
|
|
|
54
55
|
getSubstrateApiMap(): Record<string, _SubstrateApi>;
|
|
55
56
|
getTonApi(slug: string): import("./handler/TonApi").TonApi;
|
|
56
57
|
getTonApiMap(): Record<string, import("./handler/TonApi").TonApi>;
|
|
58
|
+
getCardanoApi(slug: string): import("./handler/CardanoApi").CardanoApi;
|
|
59
|
+
getCardanoApiMap(): Record<string, import("./handler/CardanoApi").CardanoApi>;
|
|
57
60
|
getChainCurrentProviderByKey(slug: string): {
|
|
58
61
|
endpoint: string;
|
|
59
62
|
providerName: string;
|
|
@@ -142,7 +145,6 @@ export declare class ChainService {
|
|
|
142
145
|
private generateSlugForNativeToken;
|
|
143
146
|
refreshSubstrateApi(slug: string): void;
|
|
144
147
|
refreshEvmApi(slug: string): void;
|
|
145
|
-
refreshTonApi(slug: string): void;
|
|
146
148
|
stopAllChainApis(): Promise<void>;
|
|
147
149
|
resumeAllChainApis(): Promise<void>;
|
|
148
150
|
initAssetSettings(): Promise<void>;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { AssetLogoMap, AssetRefMap, ChainAssetMap, ChainInfoMap, ChainLogoMap, MultiChainAssetMap } from '@subwallet/chain-list';
|
|
5
5
|
import { _AssetRefPath, _AssetType, _ChainStatus, _SubstrateChainType } from '@subwallet/chain-list/types';
|
|
6
6
|
import { _DEFAULT_ACTIVE_CHAINS, _ZK_ASSET_PREFIX, LATEST_CHAIN_DATA_FETCHING_INTERVAL } from '@subwallet/extension-base/services/chain-service/constants';
|
|
7
|
+
import { CardanoChainHandler } from '@subwallet/extension-base/services/chain-service/handler/CardanoChainHandler';
|
|
7
8
|
import { EvmChainHandler } from '@subwallet/extension-base/services/chain-service/handler/EvmChainHandler';
|
|
8
9
|
import { MantaPrivateHandler } from '@subwallet/extension-base/services/chain-service/handler/manta/MantaPrivateHandler';
|
|
9
10
|
import { SubstrateChainHandler } from '@subwallet/extension-base/services/chain-service/handler/SubstrateChainHandler';
|
|
@@ -68,6 +69,7 @@ export class ChainService {
|
|
|
68
69
|
this.substrateChainHandler = new SubstrateChainHandler(this);
|
|
69
70
|
this.evmChainHandler = new EvmChainHandler(this);
|
|
70
71
|
this.tonChainHandler = new TonChainHandler(this);
|
|
72
|
+
this.cardanoChainHandler = new CardanoChainHandler(this);
|
|
71
73
|
this.logger = createLogger('chain-service');
|
|
72
74
|
}
|
|
73
75
|
get value() {
|
|
@@ -141,6 +143,12 @@ export class ChainService {
|
|
|
141
143
|
getTonApiMap() {
|
|
142
144
|
return this.tonChainHandler.getTonApiMap();
|
|
143
145
|
}
|
|
146
|
+
getCardanoApi(slug) {
|
|
147
|
+
return this.cardanoChainHandler.getCardanoApiByChain(slug);
|
|
148
|
+
}
|
|
149
|
+
getCardanoApiMap() {
|
|
150
|
+
return this.cardanoChainHandler.getCardanoApiMap();
|
|
151
|
+
}
|
|
144
152
|
getChainCurrentProviderByKey(slug) {
|
|
145
153
|
const providerName = this.getChainStateByKey(slug).currentProvider;
|
|
146
154
|
const providerMap = this.getChainInfoByKey(slug).providers;
|
|
@@ -719,6 +727,15 @@ export class ChainService {
|
|
|
719
727
|
});
|
|
720
728
|
this.tonChainHandler.setTonApi(chainInfo.slug, chainApi);
|
|
721
729
|
}
|
|
730
|
+
if (chainInfo.cardanoInfo !== null && chainInfo.cardanoInfo !== undefined) {
|
|
731
|
+
const isTestnet = chainInfo.isTestnet;
|
|
732
|
+
const chainApi = await this.cardanoChainHandler.initApi(chainInfo.slug, endpoint, {
|
|
733
|
+
isTestnet,
|
|
734
|
+
providerName,
|
|
735
|
+
onUpdateStatus
|
|
736
|
+
});
|
|
737
|
+
this.cardanoChainHandler.setCardanoApi(chainInfo.slug, chainApi);
|
|
738
|
+
}
|
|
722
739
|
}
|
|
723
740
|
destroyApiForChain(chainInfo) {
|
|
724
741
|
if (chainInfo.substrateInfo !== null) {
|
|
@@ -730,6 +747,9 @@ export class ChainService {
|
|
|
730
747
|
if (chainInfo.tonInfo !== null) {
|
|
731
748
|
this.tonChainHandler.destroyTonApi(chainInfo.slug);
|
|
732
749
|
}
|
|
750
|
+
if (chainInfo.cardanoInfo !== null) {
|
|
751
|
+
this.cardanoChainHandler.destroyCardanoApi(chainInfo.slug);
|
|
752
|
+
}
|
|
733
753
|
}
|
|
734
754
|
async enableChain(chainSlug) {
|
|
735
755
|
const chainInfo = this.getChainInfoByKey(chainSlug);
|
|
@@ -1000,7 +1020,7 @@ export class ChainService {
|
|
|
1000
1020
|
deprecatedChainMap[storedSlug] = duplicatedDefaultSlug;
|
|
1001
1021
|
deprecatedChains.push(storedSlug);
|
|
1002
1022
|
} else {
|
|
1003
|
-
var _storedChainInfo$bitc;
|
|
1023
|
+
var _storedChainInfo$bitc, _storedChainInfo$card;
|
|
1004
1024
|
mergedChainInfoMap[storedSlug] = {
|
|
1005
1025
|
slug: storedSlug,
|
|
1006
1026
|
name: storedChainInfo.name,
|
|
@@ -1010,6 +1030,7 @@ export class ChainService {
|
|
|
1010
1030
|
substrateInfo: storedChainInfo.substrateInfo,
|
|
1011
1031
|
bitcoinInfo: (_storedChainInfo$bitc = storedChainInfo.bitcoinInfo) !== null && _storedChainInfo$bitc !== void 0 ? _storedChainInfo$bitc : null,
|
|
1012
1032
|
tonInfo: storedChainInfo.tonInfo,
|
|
1033
|
+
cardanoInfo: (_storedChainInfo$card = storedChainInfo.cardanoInfo) !== null && _storedChainInfo$card !== void 0 ? _storedChainInfo$card : null,
|
|
1013
1034
|
isTestnet: storedChainInfo.isTestnet,
|
|
1014
1035
|
chainStatus: storedChainInfo.chainStatus,
|
|
1015
1036
|
icon: storedChainInfo.icon,
|
|
@@ -1028,7 +1049,7 @@ export class ChainService {
|
|
|
1028
1049
|
this.updateChainConnectionStatus(storedSlug, _ChainConnectionStatus.DISCONNECTED);
|
|
1029
1050
|
}
|
|
1030
1051
|
} else {
|
|
1031
|
-
var _storedChainInfo$bitc2;
|
|
1052
|
+
var _storedChainInfo$bitc2, _storedChainInfo$card2;
|
|
1032
1053
|
// added chain from patch
|
|
1033
1054
|
mergedChainInfoMap[storedSlug] = {
|
|
1034
1055
|
slug: storedSlug,
|
|
@@ -1038,6 +1059,7 @@ export class ChainService {
|
|
|
1038
1059
|
substrateInfo: storedChainInfo.substrateInfo,
|
|
1039
1060
|
bitcoinInfo: (_storedChainInfo$bitc2 = storedChainInfo.bitcoinInfo) !== null && _storedChainInfo$bitc2 !== void 0 ? _storedChainInfo$bitc2 : null,
|
|
1040
1061
|
tonInfo: storedChainInfo.tonInfo,
|
|
1062
|
+
cardanoInfo: (_storedChainInfo$card2 = storedChainInfo.cardanoInfo) !== null && _storedChainInfo$card2 !== void 0 ? _storedChainInfo$card2 : null,
|
|
1041
1063
|
isTestnet: storedChainInfo.isTestnet,
|
|
1042
1064
|
chainStatus: storedChainInfo.chainStatus,
|
|
1043
1065
|
icon: storedChainInfo.icon,
|
|
@@ -1207,6 +1229,7 @@ export class ChainService {
|
|
|
1207
1229
|
let substrateInfo = null;
|
|
1208
1230
|
let evmInfo = null;
|
|
1209
1231
|
const tonInfo = null;
|
|
1232
|
+
const cardanoInfo = null;
|
|
1210
1233
|
if (params.chainSpec.genesisHash !== '') {
|
|
1211
1234
|
substrateInfo = {
|
|
1212
1235
|
crowdloanFunds: params.chainSpec.crowdloanFunds || null,
|
|
@@ -1245,6 +1268,7 @@ export class ChainService {
|
|
|
1245
1268
|
evmInfo,
|
|
1246
1269
|
bitcoinInfo: null,
|
|
1247
1270
|
tonInfo,
|
|
1271
|
+
cardanoInfo,
|
|
1248
1272
|
isTestnet: false,
|
|
1249
1273
|
chainStatus: _ChainStatus.ACTIVE,
|
|
1250
1274
|
icon: '',
|
|
@@ -1356,6 +1380,7 @@ export class ChainService {
|
|
|
1356
1380
|
// TODO: EVM chain might have WS provider
|
|
1357
1381
|
if (provider.startsWith('http')) {
|
|
1358
1382
|
// todo: handle validate ton provider
|
|
1383
|
+
// todo: handle validate cardano provider
|
|
1359
1384
|
|
|
1360
1385
|
// HTTP provider is EVM by default
|
|
1361
1386
|
api = await this.evmChainHandler.initApi('custom', provider);
|
|
@@ -1572,15 +1597,12 @@ export class ChainService {
|
|
|
1572
1597
|
refreshEvmApi(slug) {
|
|
1573
1598
|
this.evmChainHandler.recoverApi(slug).catch(console.error);
|
|
1574
1599
|
}
|
|
1575
|
-
refreshTonApi(slug) {
|
|
1576
|
-
this.tonChainHandler.recoverApi(slug).catch(console.error);
|
|
1577
|
-
}
|
|
1578
1600
|
async stopAllChainApis() {
|
|
1579
|
-
await Promise.all([this.substrateChainHandler.sleep(), this.evmChainHandler.sleep(), this.tonChainHandler.sleep()]);
|
|
1601
|
+
await Promise.all([this.substrateChainHandler.sleep(), this.evmChainHandler.sleep(), this.tonChainHandler.sleep(), this.cardanoChainHandler.sleep()]);
|
|
1580
1602
|
this.stopCheckLatestChainData();
|
|
1581
1603
|
}
|
|
1582
1604
|
async resumeAllChainApis() {
|
|
1583
|
-
await Promise.all([this.substrateChainHandler.wakeUp(), this.evmChainHandler.wakeUp(), this.tonChainHandler.wakeUp()]);
|
|
1605
|
+
await Promise.all([this.substrateChainHandler.wakeUp(), this.evmChainHandler.wakeUp(), this.tonChainHandler.wakeUp(), this.cardanoChainHandler.wakeUp()]);
|
|
1584
1606
|
this.checkLatestData();
|
|
1585
1607
|
}
|
|
1586
1608
|
async initAssetSettings() {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
|
2
2
|
import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _CrowdloanFund } from '@subwallet/chain-list/types';
|
|
3
|
+
import { CardanoBalanceItem } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/cardano/types';
|
|
3
4
|
import { AccountState, TxByMsgResponse } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/types';
|
|
4
5
|
import { _CHAIN_VALIDATION_ERROR } from '@subwallet/extension-base/services/chain-service/handler/types';
|
|
5
6
|
import { TonWalletContract } from '@subwallet/keyring/types';
|
|
@@ -107,7 +108,7 @@ export interface _EvmApi extends _ChainBaseApi {
|
|
|
107
108
|
export interface _TonApi extends _ChainBaseApi, _TonUtilsApi {
|
|
108
109
|
isReady: Promise<_TonApi>;
|
|
109
110
|
}
|
|
110
|
-
|
|
111
|
+
interface _TonUtilsApi {
|
|
111
112
|
getBalance(address: Address): Promise<bigint>;
|
|
112
113
|
open<T extends Contract>(src: T): OpenedContract<T>;
|
|
113
114
|
estimateExternalMessageFee(walletContract: TonWalletContract, body: Cell, isInit: boolean, ignoreSignature?: boolean): Promise<EstimateExternalMessageFee>;
|
|
@@ -116,6 +117,12 @@ export interface _TonUtilsApi {
|
|
|
116
117
|
getStatusByExtMsgHash(extMsgHash: string): Promise<[boolean, string]>;
|
|
117
118
|
getAccountState(address: string): Promise<AccountState>;
|
|
118
119
|
}
|
|
120
|
+
export interface _CardanoApi extends _ChainBaseApi, _CardanoUtilsApi {
|
|
121
|
+
isReady: Promise<_CardanoApi>;
|
|
122
|
+
}
|
|
123
|
+
interface _CardanoUtilsApi {
|
|
124
|
+
getBalanceMap(address: string): Promise<CardanoBalanceItem[]>;
|
|
125
|
+
}
|
|
119
126
|
export interface EstimateExternalMessageFee {
|
|
120
127
|
source_fees: {
|
|
121
128
|
in_fwd_fee: number;
|
|
@@ -179,3 +186,4 @@ export interface _ValidateCustomAssetResponse extends _SmartContractTokenInfo {
|
|
|
179
186
|
export declare const _FUNGIBLE_CONTRACT_STANDARDS: _AssetType[];
|
|
180
187
|
export declare const _NFT_CONTRACT_STANDARDS: _AssetType[];
|
|
181
188
|
export declare const _SMART_CONTRACT_STANDARDS: _AssetType[];
|
|
189
|
+
export {};
|
|
@@ -11,6 +11,7 @@ export declare function _isEqualSmartContractAsset(asset1: _ChainAsset, asset2:
|
|
|
11
11
|
export declare function _isPureEvmChain(chainInfo: _ChainInfo): boolean;
|
|
12
12
|
export declare function _isPureSubstrateChain(chainInfo: _ChainInfo): boolean;
|
|
13
13
|
export declare function _isPureTonChain(chainInfo: _ChainInfo): boolean;
|
|
14
|
+
export declare function _isPureCardanoChain(chainInfo: _ChainInfo): boolean;
|
|
14
15
|
export declare function _getOriginChainOfAsset(assetSlug: string): string;
|
|
15
16
|
export declare function _getContractAddressOfToken(tokenInfo: _ChainAsset): string;
|
|
16
17
|
/**
|
|
@@ -30,6 +31,7 @@ export declare function _isTokenTransferredByEvm(tokenInfo: _ChainAsset): boolea
|
|
|
30
31
|
export declare function _checkSmartContractSupportByChain(chainInfo: _ChainInfo, contractType: _AssetType): boolean;
|
|
31
32
|
export declare function _isJettonToken(tokenInfo: _ChainAsset): boolean;
|
|
32
33
|
export declare function _isTokenTransferredByTon(tokenInfo: _ChainAsset): boolean;
|
|
34
|
+
export declare function _isTokenTransferredByCardano(tokenInfo: _ChainAsset): boolean;
|
|
33
35
|
export declare function _getTokenOnChainAssetId(tokenInfo: _ChainAsset): string;
|
|
34
36
|
export declare function _getTokenOnChainInfo(tokenInfo: _ChainAsset): Record<string, any>;
|
|
35
37
|
export declare function _isBridgedToken(tokenInfo: _ChainAsset): boolean;
|
|
@@ -37,6 +39,7 @@ export declare function _getTokenMinAmount(tokenInfo: _ChainAsset): string;
|
|
|
37
39
|
export declare function _isChainEvmCompatible(chainInfo: _ChainInfo): boolean;
|
|
38
40
|
export declare function _isChainBitcoinCompatible(chainInfo: _ChainInfo): boolean;
|
|
39
41
|
export declare function _isChainTonCompatible(chainInfo: _ChainInfo): boolean;
|
|
42
|
+
export declare function _isChainCardanoCompatible(chainInfo: _ChainInfo): boolean;
|
|
40
43
|
export declare function _isNativeToken(tokenInfo: _ChainAsset): boolean;
|
|
41
44
|
export declare function _isNativeTokenBySlug(tokenSlug: string): boolean;
|
|
42
45
|
export declare function _isSmartContractToken(tokenInfo: _ChainAsset): boolean;
|
|
@@ -65,6 +68,7 @@ export declare function _getChainNativeTokenSlug(chainInfo: _ChainInfo): string;
|
|
|
65
68
|
export declare function _isLocalToken(tokenInfo: _ChainAsset): boolean;
|
|
66
69
|
export declare function _isTokenEvmSmartContract(tokenInfo: _ChainAsset): boolean;
|
|
67
70
|
export declare function _isTokenTonSmartContract(tokenInfo: _ChainAsset): boolean;
|
|
71
|
+
export declare function _isCIP26Token(tokenInfo: _ChainAsset): boolean;
|
|
68
72
|
export declare function _isTokenWasmSmartContract(tokenInfo: _ChainAsset): boolean;
|
|
69
73
|
export declare function _isAssetSmartContractNft(assetInfo: _ChainAsset): boolean;
|
|
70
74
|
export declare function _isTokenGearSmartContract(tokenInfo: _ChainAsset): boolean;
|
|
@@ -48,13 +48,16 @@ export function _isEqualSmartContractAsset(asset1, asset2) {
|
|
|
48
48
|
return false;
|
|
49
49
|
}
|
|
50
50
|
export function _isPureEvmChain(chainInfo) {
|
|
51
|
-
return !!chainInfo.evmInfo && !chainInfo.substrateInfo && !chainInfo.tonInfo;
|
|
51
|
+
return !!chainInfo.evmInfo && !chainInfo.substrateInfo && !chainInfo.tonInfo && !chainInfo.cardanoInfo;
|
|
52
52
|
}
|
|
53
53
|
export function _isPureSubstrateChain(chainInfo) {
|
|
54
|
-
return !chainInfo.evmInfo && !!chainInfo.substrateInfo && !chainInfo.tonInfo;
|
|
54
|
+
return !chainInfo.evmInfo && !!chainInfo.substrateInfo && !chainInfo.tonInfo && !chainInfo.cardanoInfo;
|
|
55
55
|
}
|
|
56
56
|
export function _isPureTonChain(chainInfo) {
|
|
57
|
-
return !chainInfo.evmInfo && !chainInfo.substrateInfo && !!chainInfo.tonInfo;
|
|
57
|
+
return !chainInfo.evmInfo && !chainInfo.substrateInfo && !!chainInfo.tonInfo && !chainInfo.cardanoInfo;
|
|
58
|
+
}
|
|
59
|
+
export function _isPureCardanoChain(chainInfo) {
|
|
60
|
+
return !chainInfo.evmInfo && !chainInfo.substrateInfo && !chainInfo.tonInfo && !!chainInfo.cardanoInfo;
|
|
58
61
|
}
|
|
59
62
|
export function _getOriginChainOfAsset(assetSlug) {
|
|
60
63
|
if (assetSlug.startsWith(_CUSTOM_PREFIX)) {
|
|
@@ -107,6 +110,9 @@ export function _isJettonToken(tokenInfo) {
|
|
|
107
110
|
export function _isTokenTransferredByTon(tokenInfo) {
|
|
108
111
|
return _isJettonToken(tokenInfo) || _isNativeToken(tokenInfo);
|
|
109
112
|
}
|
|
113
|
+
export function _isTokenTransferredByCardano(tokenInfo) {
|
|
114
|
+
return _isCIP26Token(tokenInfo) || _isNativeToken(tokenInfo);
|
|
115
|
+
}
|
|
110
116
|
|
|
111
117
|
// Utils for balance functions
|
|
112
118
|
export function _getTokenOnChainAssetId(tokenInfo) {
|
|
@@ -133,6 +139,9 @@ export function _isChainBitcoinCompatible(chainInfo) {
|
|
|
133
139
|
export function _isChainTonCompatible(chainInfo) {
|
|
134
140
|
return !!chainInfo.tonInfo;
|
|
135
141
|
}
|
|
142
|
+
export function _isChainCardanoCompatible(chainInfo) {
|
|
143
|
+
return !!chainInfo.cardanoInfo;
|
|
144
|
+
}
|
|
136
145
|
export function _isNativeToken(tokenInfo) {
|
|
137
146
|
return tokenInfo.assetType === _AssetType.NATIVE;
|
|
138
147
|
}
|
|
@@ -252,11 +261,12 @@ export function _getTokenTypesSupportedByChain(chainInfo) {
|
|
|
252
261
|
return result;
|
|
253
262
|
}
|
|
254
263
|
export function _getChainNativeTokenBasicInfo(chainInfo) {
|
|
264
|
+
const defaultTokenInfo = {
|
|
265
|
+
symbol: '',
|
|
266
|
+
decimals: -1
|
|
267
|
+
};
|
|
255
268
|
if (!chainInfo) {
|
|
256
|
-
return
|
|
257
|
-
symbol: '',
|
|
258
|
-
decimals: -1
|
|
259
|
-
};
|
|
269
|
+
return defaultTokenInfo;
|
|
260
270
|
}
|
|
261
271
|
if (chainInfo.substrateInfo) {
|
|
262
272
|
// substrate by default
|
|
@@ -274,11 +284,13 @@ export function _getChainNativeTokenBasicInfo(chainInfo) {
|
|
|
274
284
|
symbol: chainInfo.tonInfo.symbol,
|
|
275
285
|
decimals: chainInfo.tonInfo.decimals
|
|
276
286
|
};
|
|
287
|
+
} else if (chainInfo.cardanoInfo) {
|
|
288
|
+
return {
|
|
289
|
+
symbol: chainInfo.cardanoInfo.symbol,
|
|
290
|
+
decimals: chainInfo.cardanoInfo.decimals
|
|
291
|
+
};
|
|
277
292
|
}
|
|
278
|
-
return
|
|
279
|
-
symbol: '',
|
|
280
|
-
decimals: -1
|
|
281
|
-
};
|
|
293
|
+
return defaultTokenInfo;
|
|
282
294
|
}
|
|
283
295
|
export function _getChainNativeTokenSlug(chainInfo) {
|
|
284
296
|
if (_isCustomChain(chainInfo.slug)) {
|
|
@@ -296,6 +308,9 @@ export function _isTokenTonSmartContract(tokenInfo) {
|
|
|
296
308
|
return [_AssetType.TEP74].includes(tokenInfo.assetType); // add TEP-62 when supporting
|
|
297
309
|
}
|
|
298
310
|
|
|
311
|
+
export function _isCIP26Token(tokenInfo) {
|
|
312
|
+
return [_AssetType.CIP26].includes(tokenInfo.assetType);
|
|
313
|
+
}
|
|
299
314
|
export function _isTokenWasmSmartContract(tokenInfo) {
|
|
300
315
|
return [_AssetType.PSP22, _AssetType.PSP34].includes(tokenInfo.assetType);
|
|
301
316
|
}
|
|
@@ -384,6 +399,9 @@ export function _getBlockExplorerFromChain(chainInfo) {
|
|
|
384
399
|
if (_isPureEvmChain(chainInfo)) {
|
|
385
400
|
var _chainInfo$evmInfo5;
|
|
386
401
|
blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo5 = chainInfo.evmInfo) === null || _chainInfo$evmInfo5 === void 0 ? void 0 : _chainInfo$evmInfo5.blockExplorer;
|
|
402
|
+
} else if (_isPureCardanoChain(chainInfo)) {
|
|
403
|
+
var _chainInfo$cardanoInf;
|
|
404
|
+
blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$cardanoInf = chainInfo.cardanoInfo) === null || _chainInfo$cardanoInf === void 0 ? void 0 : _chainInfo$cardanoInf.blockExplorer;
|
|
387
405
|
} else {
|
|
388
406
|
var _chainInfo$substrateI18;
|
|
389
407
|
blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI18 = chainInfo.substrateInfo) === null || _chainInfo$substrateI18 === void 0 ? void 0 : _chainInfo$substrateI18.blockExplorer;
|
|
@@ -551,6 +569,9 @@ export const _chainInfoToChainType = chainInfo => {
|
|
|
551
569
|
if (_isChainTonCompatible(chainInfo)) {
|
|
552
570
|
return AccountChainType.TON;
|
|
553
571
|
}
|
|
572
|
+
if (_isChainCardanoCompatible(chainInfo)) {
|
|
573
|
+
return AccountChainType.CARDANO;
|
|
574
|
+
}
|
|
554
575
|
if (_isChainBitcoinCompatible(chainInfo)) {
|
|
555
576
|
return AccountChainType.BITCOIN;
|
|
556
577
|
}
|
|
@@ -5,7 +5,7 @@ const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
|
|
|
5
5
|
const branchName = process.env.BRANCH_NAME || 'subwallet-dev';
|
|
6
6
|
const fetchDomain = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'https://chain-list-assets.subwallet.app' : 'https://dev.sw-chain-list-assets.pages.dev';
|
|
7
7
|
const fetchFile = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'list.json' : 'preview.json';
|
|
8
|
-
const ChainListVersion = '0.2.
|
|
8
|
+
const ChainListVersion = '0.2.101'; // update this when build chainlist
|
|
9
9
|
|
|
10
10
|
// todo: move this interface to chainlist
|
|
11
11
|
|
|
@@ -124,7 +124,7 @@ export default class BifrostMantaLiquidStakingPoolHandler extends BifrostLiquidS
|
|
|
124
124
|
const chainApi = await this.substrateApi.isReady;
|
|
125
125
|
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
126
126
|
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
127
|
-
const extrinsic = chainApi.api.tx.vtokenMinting.redeem(_getTokenOnChainInfo(derivativeTokenInfo), amount);
|
|
127
|
+
const extrinsic = chainApi.api.tx.vtokenMinting.redeem(null, _getTokenOnChainInfo(derivativeTokenInfo), amount);
|
|
128
128
|
return [ExtrinsicType.UNSTAKE_VMANTA, extrinsic];
|
|
129
129
|
}
|
|
130
130
|
|
|
@@ -286,7 +286,7 @@ export default class BifrostLiquidStakingPoolHandler extends BaseLiquidStakingPo
|
|
|
286
286
|
const chainApi = await this.substrateApi.isReady;
|
|
287
287
|
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
288
288
|
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
289
|
-
const extrinsic = chainApi.api.tx.vtokenMinting.redeem(_getTokenOnChainInfo(derivativeTokenInfo), amount);
|
|
289
|
+
const extrinsic = chainApi.api.tx.vtokenMinting.redeem(null, _getTokenOnChainInfo(derivativeTokenInfo), amount);
|
|
290
290
|
return [ExtrinsicType.UNSTAKE_VDOT, extrinsic];
|
|
291
291
|
}
|
|
292
292
|
|