@subwallet/extension-base 1.0.2-1b → 1.0.2-2
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 +34 -16
- package/background/KoniTypes.js +7 -6
- package/background/errors/TransactionError.js +1 -21
- package/cjs/background/KoniTypes.js +7 -6
- package/cjs/background/errors/TransactionError.js +0 -20
- package/cjs/constants/index.js +26 -8
- package/cjs/koni/api/dotsama/balance.js +224 -49
- package/cjs/koni/api/dotsama/transfer.js +29 -30
- package/cjs/koni/api/nft/acala_nft/index.js +1 -4
- package/cjs/koni/api/nft/bit.country/index.js +1 -4
- package/cjs/koni/api/nft/evm_nft/index.js +3 -7
- package/cjs/koni/api/nft/index.js +6 -3
- package/cjs/koni/api/nft/karura_nft/index.js +1 -4
- package/cjs/koni/api/nft/rmrk_nft/index.js +1 -8
- package/cjs/koni/api/nft/statemine_nft/index.js +1 -4
- package/cjs/koni/api/nft/unique_nft/index.js +1 -6
- package/cjs/koni/api/nft/wasm_nft/index.js +111 -169
- package/cjs/koni/api/nft/wasm_nft/utils.js +7 -11
- package/cjs/koni/api/staking/bonding/amplitude.js +9 -13
- package/cjs/koni/api/staking/bonding/astar.js +13 -15
- package/cjs/koni/api/staking/bonding/index.js +10 -22
- package/cjs/koni/api/staking/bonding/paraChain.js +2 -85
- package/cjs/koni/api/staking/bonding/relayChain.js +16 -119
- package/cjs/koni/api/staking/bonding/utils.js +8 -27
- package/cjs/koni/api/tokens/wasm/index.js +4 -5
- package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
- package/cjs/koni/api/xcm/utils.js +13 -18
- package/cjs/koni/api/xcm/xTokens.js +1 -1
- package/cjs/koni/api/xcm/xcmPallet.js +6 -9
- package/cjs/koni/background/cron.js +47 -150
- package/cjs/koni/background/handlers/Extension.js +64 -106
- package/cjs/koni/background/handlers/State.js +21 -19
- package/cjs/koni/background/handlers/Tabs.js +1 -8
- package/cjs/koni/background/subscription.js +29 -32
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +8 -13
- package/cjs/services/chain-service/handler/light-client/index.js +0 -2
- package/cjs/services/chain-service/index.js +7 -6
- package/cjs/services/event-service/index.js +1 -5
- package/cjs/services/event-service/types.js +1 -11
- package/cjs/services/history-service/index.js +10 -16
- package/cjs/services/history-service/subsquid-multi-chain-history.js +9 -12
- package/cjs/services/price-service/coingecko.js +1 -0
- package/cjs/services/price-service/index.js +3 -2
- package/cjs/services/request-service/handler/AuthRequestHandler.js +2 -6
- package/cjs/services/storage-service/DatabaseService.js +33 -52
- package/cjs/services/storage-service/db-stores/Nft.js +17 -4
- package/cjs/services/transaction-service/event-parser/index.js +48 -20
- package/cjs/services/transaction-service/index.js +14 -23
- package/cjs/utils/index.js +14 -7
- package/constants/index.d.ts +13 -7
- package/constants/index.js +13 -7
- package/koni/api/dotsama/balance.d.ts +1 -0
- package/koni/api/dotsama/balance.js +197 -22
- package/koni/api/dotsama/transfer.js +4 -5
- package/koni/api/nft/acala_nft/index.js +1 -3
- package/koni/api/nft/bit.country/index.js +1 -3
- package/koni/api/nft/evm_nft/index.js +3 -6
- package/koni/api/nft/index.d.ts +2 -1
- package/koni/api/nft/index.js +6 -3
- package/koni/api/nft/karura_nft/index.js +1 -3
- package/koni/api/nft/nft.d.ts +0 -1
- package/koni/api/nft/rmrk_nft/index.js +1 -8
- package/koni/api/nft/statemine_nft/index.js +1 -3
- package/koni/api/nft/unique_nft/index.js +1 -5
- package/koni/api/nft/wasm_nft/index.d.ts +2 -0
- package/koni/api/nft/wasm_nft/index.js +109 -167
- package/koni/api/nft/wasm_nft/utils.d.ts +5 -7
- package/koni/api/nft/wasm_nft/utils.js +5 -7
- package/koni/api/staking/bonding/amplitude.d.ts +1 -0
- package/koni/api/staking/bonding/amplitude.js +10 -15
- package/koni/api/staking/bonding/astar.js +6 -8
- package/koni/api/staking/bonding/index.d.ts +1 -4
- package/koni/api/staking/bonding/index.js +13 -23
- package/koni/api/staking/bonding/paraChain.d.ts +0 -3
- package/koni/api/staking/bonding/paraChain.js +5 -86
- package/koni/api/staking/bonding/relayChain.d.ts +1 -5
- package/koni/api/staking/bonding/relayChain.js +18 -118
- package/koni/api/staking/bonding/utils.d.ts +2 -3
- package/koni/api/staking/bonding/utils.js +9 -27
- package/koni/api/tokens/wasm/index.js +4 -5
- package/koni/api/xcm/polkadotXcm.js +2 -2
- package/koni/api/xcm/utils.d.ts +6 -5
- package/koni/api/xcm/utils.js +10 -15
- package/koni/api/xcm/xTokens.js +2 -2
- package/koni/api/xcm/xcmPallet.js +9 -10
- package/koni/background/cron.d.ts +1 -6
- package/koni/background/cron.js +48 -151
- package/koni/background/handlers/Extension.d.ts +2 -2
- package/koni/background/handlers/Extension.js +67 -108
- package/koni/background/handlers/State.d.ts +6 -5
- package/koni/background/handlers/State.js +21 -19
- package/koni/background/handlers/Tabs.js +1 -8
- package/koni/background/subscription.js +30 -31
- package/package.json +8 -13
- package/packageInfo.js +1 -1
- package/services/chain-service/handler/SubstrateChainHandler.js +9 -14
- package/services/chain-service/handler/light-client/index.d.ts +1 -17
- package/services/chain-service/handler/light-client/index.js +1 -1
- package/services/chain-service/helper/psp22_abi.json +881 -1041
- package/services/chain-service/helper/psp34_abi.json +1808 -2964
- package/services/chain-service/index.js +7 -6
- package/services/event-service/index.js +1 -5
- package/services/event-service/types.d.ts +9 -5
- package/services/event-service/types.js +1 -4
- package/services/history-service/index.d.ts +1 -1
- package/services/history-service/index.js +10 -16
- package/services/history-service/subsquid-multi-chain-history.js +11 -15
- package/services/price-service/coingecko.js +1 -0
- package/services/price-service/index.js +3 -2
- package/services/request-service/handler/AuthRequestHandler.js +2 -6
- package/services/storage-service/DatabaseService.d.ts +0 -1
- package/services/storage-service/DatabaseService.js +33 -52
- package/services/storage-service/db-stores/Nft.d.ts +2 -1
- package/services/storage-service/db-stores/Nft.js +16 -4
- package/services/transaction-service/event-parser/index.js +49 -21
- package/services/transaction-service/index.js +14 -23
- package/utils/index.d.ts +1 -1
- package/utils/index.js +12 -6
- package/cjs/koni/api/tokens/wasm/utils.js +0 -63
- package/koni/api/tokens/wasm/utils.d.ts +0 -6
- package/koni/api/tokens/wasm/utils.js +0 -54
|
@@ -3,44 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
import { _AssetType } from '@subwallet/chain-list/types';
|
|
5
5
|
import { BaseNftApi } from '@subwallet/extension-base/koni/api/nft/nft';
|
|
6
|
-
import { ART_ZERO_COLLECTION_API, ART_ZERO_EXTERNAL_URL, ART_ZERO_IMAGE_API, ART_ZERO_IPFS_API
|
|
6
|
+
import { ART_ZERO_COLLECTION_API, ART_ZERO_CONTRACTS, ART_ZERO_EXTERNAL_URL, ART_ZERO_IMAGE_API, ART_ZERO_IPFS_API } from '@subwallet/extension-base/koni/api/nft/wasm_nft/utils';
|
|
7
7
|
import { getPSP34ContractPromise } from '@subwallet/extension-base/koni/api/tokens/wasm';
|
|
8
|
-
import { getDefaultWeightV2 } from '@subwallet/extension-base/koni/api/tokens/wasm/utils';
|
|
9
8
|
import { _getContractAddressOfToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
10
|
-
import axios from 'axios';
|
|
11
9
|
import fetch from 'cross-fetch';
|
|
12
10
|
import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
13
|
-
|
|
14
|
-
// interface CollectionAttributes {
|
|
15
|
-
// storedOnChain: boolean,
|
|
16
|
-
// attributeList: string[] // list of attribute names
|
|
17
|
-
// }
|
|
18
|
-
|
|
19
|
-
async function isArtZeroFeaturedCollection(networkKey, contractAddress) {
|
|
20
|
-
const timeout = new Promise(resolve => {
|
|
21
|
-
const id = setTimeout(() => {
|
|
22
|
-
clearTimeout(id);
|
|
23
|
-
resolve(null);
|
|
24
|
-
}, 3000);
|
|
25
|
-
});
|
|
26
|
-
const urlencoded = new URLSearchParams();
|
|
27
|
-
urlencoded.append('collection_address', contractAddress);
|
|
28
|
-
const collectionInfoPromise = new Promise(function (resolve) {
|
|
29
|
-
fetch(`${networkKey === 'alephTest' ? ART_ZERO_TESTNET_COLLECTION_API : ART_ZERO_COLLECTION_API}`, {
|
|
30
|
-
method: 'POST',
|
|
31
|
-
headers: {
|
|
32
|
-
'Content-Type': 'application/x-www-form-urlencoded'
|
|
33
|
-
},
|
|
34
|
-
body: urlencoded
|
|
35
|
-
}).then(resp => {
|
|
36
|
-
resolve(resp.json());
|
|
37
|
-
}).catch(console.error);
|
|
38
|
-
});
|
|
39
|
-
const collectionInfo = await Promise.race([timeout, collectionInfoPromise]);
|
|
40
|
-
|
|
41
|
-
// @ts-ignore
|
|
42
|
-
return collectionInfo !== null && (collectionInfo === null || collectionInfo === void 0 ? void 0 : collectionInfo.status) !== 'FAILED';
|
|
43
|
-
}
|
|
44
11
|
export class WasmNftApi extends BaseNftApi {
|
|
45
12
|
wasmContracts = [];
|
|
46
13
|
constructor(api, addresses, chain) {
|
|
@@ -53,40 +20,31 @@ export class WasmNftApi extends BaseNftApi {
|
|
|
53
20
|
if (!tokenUri || tokenUri.length === 0) {
|
|
54
21
|
return undefined;
|
|
55
22
|
}
|
|
56
|
-
if (tokenUri.startsWith('/ipfs/')) {
|
|
57
|
-
return tokenUri;
|
|
58
|
-
}
|
|
59
|
-
if (tokenUri.startsWith('ipfs://')) {
|
|
60
|
-
return `/ipfs/${tokenUri.split('ipfs://')[1]}`;
|
|
61
|
-
}
|
|
62
23
|
if (!tokenUri.includes('ipfs://') && !tokenUri.includes('ipfs://ipfs/')) {
|
|
63
|
-
return
|
|
24
|
+
return `ipfs://${tokenUri}`;
|
|
64
25
|
}
|
|
65
26
|
if (tokenUri.includes('ipfs://ipfs/')) {
|
|
66
|
-
return
|
|
27
|
+
return `ipfs://${tokenUri}`;
|
|
67
28
|
}
|
|
68
29
|
return tokenUri;
|
|
69
30
|
}
|
|
70
|
-
|
|
31
|
+
parseFeaturedNftImage(tokenUri) {
|
|
71
32
|
const parsedTokenUri = this.parseFeaturedTokenUri(tokenUri);
|
|
72
33
|
if (!parsedTokenUri) {
|
|
73
34
|
return undefined;
|
|
74
35
|
}
|
|
75
|
-
|
|
76
|
-
const collectionImageUrl = await axios(nftItemImageSrc, {
|
|
77
|
-
method: 'GET'
|
|
78
|
-
});
|
|
79
|
-
return collectionImageUrl.data;
|
|
36
|
+
return `${ART_ZERO_IMAGE_API}?input=${parsedTokenUri}&size=500`;
|
|
80
37
|
}
|
|
81
38
|
async parseFeaturedCollectionImage(smartContract) {
|
|
82
|
-
const
|
|
83
|
-
urlencoded.append('collection_address', smartContract);
|
|
84
|
-
const resp = await fetch(this.chain === 'alephTest' ? ART_ZERO_TESTNET_COLLECTION_API : ART_ZERO_COLLECTION_API, {
|
|
39
|
+
const resp = await fetch(ART_ZERO_COLLECTION_API, {
|
|
85
40
|
method: 'POST',
|
|
86
41
|
headers: {
|
|
87
|
-
|
|
42
|
+
Accept: 'application/json',
|
|
43
|
+
'Content-Type': 'application/json'
|
|
88
44
|
},
|
|
89
|
-
body:
|
|
45
|
+
body: JSON.stringify({
|
|
46
|
+
collection_address: smartContract
|
|
47
|
+
})
|
|
90
48
|
});
|
|
91
49
|
const result = resp && resp.ok && (await resp.json());
|
|
92
50
|
if (!result) {
|
|
@@ -100,91 +58,82 @@ export class WasmNftApi extends BaseNftApi {
|
|
|
100
58
|
if (!parsedCollectionImage) {
|
|
101
59
|
return;
|
|
102
60
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
61
|
+
return `${ART_ZERO_IMAGE_API}?input=${parsedCollectionImage}`;
|
|
62
|
+
}
|
|
63
|
+
async getCollectionAttributes(contractPromise) {
|
|
64
|
+
const _onChainAttributeCount = await contractPromise.query['psp34Traits::getAttributeCount'](this.addresses[0], {
|
|
65
|
+
gasLimit: -1
|
|
106
66
|
});
|
|
107
|
-
|
|
67
|
+
const onChainAttributeCount = _onChainAttributeCount.output ? _onChainAttributeCount.output.toString() : '0';
|
|
68
|
+
if (parseInt(onChainAttributeCount) === 0) {
|
|
69
|
+
return {
|
|
70
|
+
storedOnChain: false,
|
|
71
|
+
attributeList: []
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const attributeList = [];
|
|
75
|
+
const attributeIndexes = [];
|
|
76
|
+
for (let i = 0; i < parseInt(onChainAttributeCount); i++) {
|
|
77
|
+
attributeIndexes.push(i);
|
|
78
|
+
}
|
|
79
|
+
await Promise.all(attributeIndexes.map(async i => {
|
|
80
|
+
const _attributeByIndex = await contractPromise.query['psp34Traits::getAttributeName'](this.addresses[0], {
|
|
81
|
+
gasLimit: -1
|
|
82
|
+
}, i);
|
|
83
|
+
if (_attributeByIndex.output) {
|
|
84
|
+
const attributeName = _attributeByIndex.output.toString();
|
|
85
|
+
if (attributeName !== '') {
|
|
86
|
+
attributeList.push(attributeName);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}));
|
|
90
|
+
return {
|
|
91
|
+
storedOnChain: true,
|
|
92
|
+
attributeList
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
async processOnChainMetadata(contractPromise, address, tokenIdObj, collectionAttributes, isFeatured) {
|
|
96
|
+
const nftItem = {
|
|
97
|
+
chain: '',
|
|
98
|
+
collectionId: '',
|
|
99
|
+
id: '',
|
|
100
|
+
owner: ''
|
|
101
|
+
};
|
|
102
|
+
const _attributeValues = await contractPromise.query['psp34Traits::getAttributes'](address, {
|
|
103
|
+
gasLimit: -1
|
|
104
|
+
}, tokenIdObj, collectionAttributes);
|
|
105
|
+
if (_attributeValues.output) {
|
|
106
|
+
const attributeValues = _attributeValues.output.toHuman();
|
|
107
|
+
const attributeDict = {};
|
|
108
|
+
for (let i = 0; i < collectionAttributes.length; i++) {
|
|
109
|
+
const attributeName = collectionAttributes[i];
|
|
110
|
+
const attributeValue = attributeValues[i] ? attributeValues[i] : '';
|
|
111
|
+
if (attributeName.toLowerCase() === 'nft_name') {
|
|
112
|
+
nftItem.name = attributeValue;
|
|
113
|
+
} else if (attributeName.toLowerCase() === 'description') {
|
|
114
|
+
nftItem.description = attributeValue;
|
|
115
|
+
} else if (attributeName.toLowerCase() === 'avatar') {
|
|
116
|
+
if (isFeatured) {
|
|
117
|
+
nftItem.image = this.parseFeaturedNftImage(attributeValue);
|
|
118
|
+
} else {
|
|
119
|
+
nftItem.image = this.parseUrl(attributeValue);
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
if (attributeValue !== '') {
|
|
123
|
+
attributeDict[attributeName] = {
|
|
124
|
+
value: attributeValue
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
nftItem.properties = attributeDict;
|
|
130
|
+
}
|
|
131
|
+
if (isFeatured) {
|
|
132
|
+
nftItem.externalUrl = ART_ZERO_EXTERNAL_URL;
|
|
133
|
+
}
|
|
134
|
+
return nftItem;
|
|
108
135
|
}
|
|
109
|
-
|
|
110
|
-
// private async getCollectionAttributes (contractPromise: ContractPromise): Promise<CollectionAttributes> {
|
|
111
|
-
// const _onChainAttributeCount = await contractPromise.query['psp34Traits::getAttributeCount'](this.addresses[0], { gasLimit: getDefaultWeightV2(this.substrateApi?.api as ApiPromise) });
|
|
112
|
-
// const onChainAttributeCount = _onChainAttributeCount.output ? _onChainAttributeCount.output.toString() : '0';
|
|
113
|
-
//
|
|
114
|
-
// if (parseInt(onChainAttributeCount) === 0) {
|
|
115
|
-
// return {
|
|
116
|
-
// storedOnChain: false,
|
|
117
|
-
// attributeList: []
|
|
118
|
-
// };
|
|
119
|
-
// }
|
|
120
|
-
//
|
|
121
|
-
// const attributeList: string[] = [];
|
|
122
|
-
// const attributeIndexes: number[] = [];
|
|
123
|
-
//
|
|
124
|
-
// for (let i = 0; i < parseInt(onChainAttributeCount); i++) {
|
|
125
|
-
// attributeIndexes.push(i);
|
|
126
|
-
// }
|
|
127
|
-
//
|
|
128
|
-
// await Promise.all(attributeIndexes.map(async (i) => {
|
|
129
|
-
// const _attributeByIndex = await contractPromise.query['psp34Traits::getAttributeName'](this.addresses[0], { gasLimit: getDefaultWeightV2(this.substrateApi?.api as ApiPromise) }, i);
|
|
130
|
-
//
|
|
131
|
-
// if (_attributeByIndex.output) {
|
|
132
|
-
// const attributeName = _attributeByIndex.output.toString();
|
|
133
|
-
//
|
|
134
|
-
// if (attributeName !== '') {
|
|
135
|
-
// attributeList.push(attributeName);
|
|
136
|
-
// }
|
|
137
|
-
// }
|
|
138
|
-
// }));
|
|
139
|
-
//
|
|
140
|
-
// return {
|
|
141
|
-
// storedOnChain: true,
|
|
142
|
-
// attributeList
|
|
143
|
-
// };
|
|
144
|
-
// }
|
|
145
|
-
|
|
146
|
-
// private async processOnChainMetadata (contractPromise: ContractPromise, address: string, tokenIdObj: Record<string, string>, collectionAttributes: string[], isFeatured: boolean): Promise<NftItem> {
|
|
147
|
-
// const nftItem: NftItem = { chain: '', collectionId: '', id: '', owner: '' };
|
|
148
|
-
// const _attributeValues = await contractPromise.query['psp34Traits::getAttributes'](address, { gasLimit: getDefaultWeightV2(this.substrateApi?.api as ApiPromise) }, tokenIdObj, collectionAttributes);
|
|
149
|
-
//
|
|
150
|
-
// if (_attributeValues.output) {
|
|
151
|
-
// const attributeValues = _attributeValues.output.toHuman() as string[];
|
|
152
|
-
//
|
|
153
|
-
// const attributeDict: Record<string, any> = {};
|
|
154
|
-
//
|
|
155
|
-
// for (let i = 0; i < collectionAttributes.length; i++) {
|
|
156
|
-
// const attributeName = collectionAttributes[i];
|
|
157
|
-
// const attributeValue = attributeValues[i] ? attributeValues[i] : '';
|
|
158
|
-
//
|
|
159
|
-
// if (attributeName.toLowerCase() === 'nft_name') {
|
|
160
|
-
// nftItem.name = attributeValue;
|
|
161
|
-
// } else if (attributeName.toLowerCase() === 'description') {
|
|
162
|
-
// nftItem.description = attributeValue;
|
|
163
|
-
// } else if (attributeName.toLowerCase() === 'avatar') {
|
|
164
|
-
// if (isFeatured) {
|
|
165
|
-
// nftItem.image = await this.parseFeaturedNftImage(attributeValue);
|
|
166
|
-
// } else {
|
|
167
|
-
// nftItem.image = this.parseUrl(attributeValue);
|
|
168
|
-
// }
|
|
169
|
-
// } else {
|
|
170
|
-
// if (attributeValue !== '') {
|
|
171
|
-
// attributeDict[attributeName] = { value: attributeValue };
|
|
172
|
-
// }
|
|
173
|
-
// }
|
|
174
|
-
// }
|
|
175
|
-
//
|
|
176
|
-
// nftItem.properties = attributeDict;
|
|
177
|
-
// }
|
|
178
|
-
//
|
|
179
|
-
// if (isFeatured) {
|
|
180
|
-
// nftItem.externalUrl = ART_ZERO_EXTERNAL_URL;
|
|
181
|
-
// }
|
|
182
|
-
//
|
|
183
|
-
// return nftItem;
|
|
184
|
-
// }
|
|
185
|
-
|
|
186
136
|
async processOffChainMetadata(contractPromise, address, tokenId, isFeatured) {
|
|
187
|
-
var _this$substrateApi;
|
|
188
137
|
const nftItem = {
|
|
189
138
|
chain: '',
|
|
190
139
|
collectionId: '',
|
|
@@ -193,23 +142,19 @@ export class WasmNftApi extends BaseNftApi {
|
|
|
193
142
|
name: tokenId
|
|
194
143
|
};
|
|
195
144
|
const _tokenUri = await contractPromise.query['psp34Traits::tokenUri'](address, {
|
|
196
|
-
gasLimit:
|
|
145
|
+
gasLimit: -1
|
|
197
146
|
}, tokenId);
|
|
198
147
|
if (_tokenUri.output) {
|
|
199
148
|
let itemDetail = false;
|
|
200
|
-
|
|
201
|
-
const _tokenUriObj = _tokenUri.output.toJSON();
|
|
202
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
203
|
-
const tokenUri = _tokenUriObj.Ok || _tokenUriObj.ok;
|
|
149
|
+
const tokenUri = _tokenUri.output.toString();
|
|
204
150
|
if (isFeatured) {
|
|
205
151
|
const parsedTokenUri = this.parseFeaturedTokenUri(tokenUri);
|
|
206
152
|
if (parsedTokenUri) {
|
|
207
|
-
const resp = await fetch(`${
|
|
153
|
+
const resp = await fetch(`${ART_ZERO_IPFS_API}?input=${parsedTokenUri}`);
|
|
208
154
|
itemDetail = resp && resp.ok && (await resp.json());
|
|
209
155
|
}
|
|
210
156
|
} else {
|
|
211
|
-
const
|
|
212
|
-
const detailUrl = this.parseUrl(parsedTokenUri);
|
|
157
|
+
const detailUrl = this.parseUrl(tokenUri);
|
|
213
158
|
if (detailUrl) {
|
|
214
159
|
const resp = await fetch(detailUrl);
|
|
215
160
|
itemDetail = resp && resp.ok && (await resp.json());
|
|
@@ -224,7 +169,7 @@ export class WasmNftApi extends BaseNftApi {
|
|
|
224
169
|
nftItem.externalUrl = itemDetail.external_url;
|
|
225
170
|
const rawImageSrc = itemDetail.image ? itemDetail.image : itemDetail.image_url;
|
|
226
171
|
if (isFeatured) {
|
|
227
|
-
nftItem.image =
|
|
172
|
+
nftItem.image = this.parseFeaturedNftImage(rawImageSrc);
|
|
228
173
|
nftItem.externalUrl = ART_ZERO_EXTERNAL_URL;
|
|
229
174
|
} else {
|
|
230
175
|
nftItem.image = this.parseUrl(rawImageSrc);
|
|
@@ -242,24 +187,20 @@ export class WasmNftApi extends BaseNftApi {
|
|
|
242
187
|
}
|
|
243
188
|
return nftItem;
|
|
244
189
|
}
|
|
245
|
-
async getItemsByCollection(contractPromise, tokenInfo, collectionName, nftParams
|
|
190
|
+
async getItemsByCollection(contractPromise, collectionAttributes, isMetadataOnchain, tokenInfo, collectionName, nftParams) {
|
|
246
191
|
let ownItem = false;
|
|
247
192
|
let collectionImage;
|
|
248
193
|
const smartContract = _getContractAddressOfToken(tokenInfo);
|
|
249
|
-
const
|
|
194
|
+
const isFeatured = ART_ZERO_CONTRACTS.includes(smartContract);
|
|
250
195
|
await Promise.all(this.addresses.map(async address => {
|
|
251
|
-
var _this$substrateApi2, _balance$output;
|
|
252
196
|
if (isEthereumAddress(address)) {
|
|
253
197
|
return;
|
|
254
198
|
}
|
|
255
199
|
const nftIds = [];
|
|
256
200
|
const _balance = await contractPromise.query['psp34::balanceOf'](address, {
|
|
257
|
-
gasLimit:
|
|
201
|
+
gasLimit: -1
|
|
258
202
|
}, address);
|
|
259
|
-
|
|
260
|
-
const balanceJson = _balance === null || _balance === void 0 ? void 0 : (_balance$output = _balance.output) === null || _balance$output === void 0 ? void 0 : _balance$output.toJSON();
|
|
261
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
262
|
-
const balance = _balance.output ? balanceJson.ok || balanceJson.Ok : '0';
|
|
203
|
+
const balance = _balance.output ? _balance.output.toString() : '0';
|
|
263
204
|
if (parseInt(balance) === 0) {
|
|
264
205
|
return;
|
|
265
206
|
}
|
|
@@ -269,17 +210,20 @@ export class WasmNftApi extends BaseNftApi {
|
|
|
269
210
|
}
|
|
270
211
|
try {
|
|
271
212
|
await Promise.all(itemIndexes.map(async i => {
|
|
272
|
-
var _this$substrateApi3;
|
|
273
213
|
const _tokenByIndexResp = await contractPromise.query['psp34Enumerable::ownersTokenByIndex'](address, {
|
|
274
|
-
gasLimit:
|
|
214
|
+
gasLimit: -1
|
|
275
215
|
}, address, i);
|
|
276
216
|
if (_tokenByIndexResp.output) {
|
|
277
217
|
const rawTokenId = _tokenByIndexResp.output.toHuman();
|
|
278
|
-
|
|
279
|
-
const
|
|
280
|
-
const tokenId = Object.values(tokenIdObj)[0].replaceAll(',', '');
|
|
218
|
+
const tokenIdObj = rawTokenId.Ok;
|
|
219
|
+
const tokenId = Object.values(tokenIdObj)[0];
|
|
281
220
|
nftIds.push(tokenId);
|
|
282
|
-
|
|
221
|
+
let nftItem;
|
|
222
|
+
if (isMetadataOnchain) {
|
|
223
|
+
nftItem = await this.processOnChainMetadata(contractPromise, address, tokenIdObj, collectionAttributes, isFeatured);
|
|
224
|
+
} else {
|
|
225
|
+
nftItem = await this.processOffChainMetadata(contractPromise, address, tokenId, isFeatured);
|
|
226
|
+
}
|
|
283
227
|
nftItem.collectionId = smartContract;
|
|
284
228
|
nftItem.chain = this.chain;
|
|
285
229
|
nftItem.type = _AssetType.PSP34;
|
|
@@ -294,8 +238,6 @@ export class WasmNftApi extends BaseNftApi {
|
|
|
294
238
|
}
|
|
295
239
|
}
|
|
296
240
|
}));
|
|
297
|
-
|
|
298
|
-
nftOwnerMap[address] = nftIds;
|
|
299
241
|
} catch (e) {
|
|
300
242
|
console.error(`error parsing item for ${this.chain} nft`, e);
|
|
301
243
|
}
|
|
@@ -315,9 +257,6 @@ export class WasmNftApi extends BaseNftApi {
|
|
|
315
257
|
originAsset: tokenInfo.slug
|
|
316
258
|
};
|
|
317
259
|
nftParams.updateCollection(this.chain, nftCollection);
|
|
318
|
-
Object.entries(nftOwnerMap).forEach(([owner, nftIds]) => {
|
|
319
|
-
nftParams.cleanUpNfts(this.chain, owner, smartContract, nftIds);
|
|
320
|
-
});
|
|
321
260
|
}
|
|
322
261
|
}
|
|
323
262
|
async fetchNfts(params) {
|
|
@@ -329,17 +268,20 @@ export class WasmNftApi extends BaseNftApi {
|
|
|
329
268
|
return 1;
|
|
330
269
|
}
|
|
331
270
|
async handleNfts(params) {
|
|
332
|
-
var _this$
|
|
271
|
+
var _this$substrateApi;
|
|
333
272
|
if (!this.wasmContracts || this.wasmContracts.length === 0) {
|
|
334
273
|
return;
|
|
335
274
|
}
|
|
336
275
|
await this.connect(); // might not be necessary
|
|
337
276
|
|
|
338
|
-
const apiPromise = (_this$
|
|
277
|
+
const apiPromise = (_this$substrateApi = this.substrateApi) === null || _this$substrateApi === void 0 ? void 0 : _this$substrateApi.api;
|
|
339
278
|
await Promise.all(this.wasmContracts.map(async tokenInfo => {
|
|
340
279
|
const contractPromise = getPSP34ContractPromise(apiPromise, _getContractAddressOfToken(tokenInfo));
|
|
341
|
-
const
|
|
342
|
-
|
|
280
|
+
const {
|
|
281
|
+
attributeList,
|
|
282
|
+
storedOnChain
|
|
283
|
+
} = await this.getCollectionAttributes(contractPromise);
|
|
284
|
+
return await this.getItemsByCollection(contractPromise, attributeList, storedOnChain, tokenInfo, tokenInfo.name, params);
|
|
343
285
|
}));
|
|
344
286
|
}
|
|
345
287
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const ART_ZERO_COLLECTION_API = "https://a0-api.artzero.io/getCollectionByAddress";
|
|
7
|
-
export declare const ART_ZERO_EXTERNAL_URL = "https://a0.artzero.io/#/marketplace";
|
|
1
|
+
export declare const ART_ZERO_CONTRACTS: string[];
|
|
2
|
+
export declare const ART_ZERO_IMAGE_API = "https://api.artzero.io/getImage";
|
|
3
|
+
export declare const ART_ZERO_IPFS_API = "https://api.artzero.io/getJSON";
|
|
4
|
+
export declare const ART_ZERO_COLLECTION_API = "https://api.artzero.io/getCollectionByAddress";
|
|
5
|
+
export declare const ART_ZERO_EXTERNAL_URL = "https://artzero.io/demotestnet/#/marketplace";
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
export const
|
|
5
|
-
export const
|
|
6
|
-
export const
|
|
7
|
-
export const
|
|
8
|
-
export const
|
|
9
|
-
export const ART_ZERO_COLLECTION_API = 'https://a0-api.artzero.io/getCollectionByAddress';
|
|
10
|
-
export const ART_ZERO_EXTERNAL_URL = 'https://a0.artzero.io/#/marketplace';
|
|
4
|
+
export const ART_ZERO_CONTRACTS = ['5Hg1xe6JAGZj92wxtj1ykAfQpwwRNqzAnvhZ3TuXZEmLU1Vw'];
|
|
5
|
+
export const ART_ZERO_IMAGE_API = 'https://api.artzero.io/getImage';
|
|
6
|
+
export const ART_ZERO_IPFS_API = 'https://api.artzero.io/getJSON';
|
|
7
|
+
export const ART_ZERO_COLLECTION_API = 'https://api.artzero.io/getCollectionByAddress';
|
|
8
|
+
export const ART_ZERO_EXTERNAL_URL = 'https://artzero.io/demotestnet/#/marketplace';
|
|
@@ -8,3 +8,4 @@ export declare function getAmplitudeBondingExtrinsic(substrateApi: _SubstrateApi
|
|
|
8
8
|
export declare function getAmplitudeUnbondingExtrinsic(substrateApi: _SubstrateApi, amount: string, nominatorMetadata: NominatorMetadata, collatorAddress: string): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
9
9
|
export declare function getAmplitudeWithdrawalExtrinsic(substrateApi: _SubstrateApi, address: string): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
10
10
|
export declare function getAmplitudeClaimRewardExtrinsic(substrateApi: _SubstrateApi): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
11
|
+
export declare function getAmplitudeCancelWithdrawalExtrinsic(substrateApi: _SubstrateApi): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { StakingStatus, StakingType, UnstakingStatus } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
|
-
import { getBondedValidators,
|
|
5
|
+
import { getBondedValidators, isUnstakeAll, parseIdentity } from '@subwallet/extension-base/koni/api/staking/bonding/utils';
|
|
6
6
|
import { _STAKING_ERA_LENGTH_MAP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
7
7
|
import { parseRawNumber, reformatAddress } from '@subwallet/extension-base/utils';
|
|
8
|
-
import { BN
|
|
8
|
+
import { BN } from '@polkadot/util';
|
|
9
9
|
import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
10
10
|
export async function getAmplitudeStakingMetadata(chain, substrateApi) {
|
|
11
11
|
const chainApi = await substrateApi.isReady;
|
|
@@ -39,31 +39,24 @@ export async function getAmplitudeNominatorMetadata(chainInfo, address, substrat
|
|
|
39
39
|
const nominationList = [];
|
|
40
40
|
const unstakingList = [];
|
|
41
41
|
const [_delegatorState, _unstakingInfo] = await Promise.all([chainApi.api.query.parachainStaking.delegatorState(address), chainApi.api.query.parachainStaking.unstaking(address)]);
|
|
42
|
-
const minDelegatorStake = chainApi.api.consts.parachainStaking.minDelegatorStake.toString();
|
|
43
42
|
const delegatorState = _delegatorState.toPrimitive();
|
|
44
43
|
const unstakingInfo = _unstakingInfo.toPrimitive();
|
|
45
|
-
console.log('unstakingInfo ampe', unstakingInfo, !!unstakingInfo);
|
|
46
44
|
if (!delegatorState && !unstakingInfo) {
|
|
47
45
|
return;
|
|
48
46
|
}
|
|
49
47
|
let activeStake = '0';
|
|
50
48
|
if (delegatorState) {
|
|
51
49
|
// delegatorState can be null while unstaking all
|
|
52
|
-
const identityInfo =
|
|
53
|
-
const identity =
|
|
50
|
+
const identityInfo = (await chainApi.api.query.identity.identityOf(delegatorState.owner)).toPrimitive();
|
|
51
|
+
const identity = parseIdentity(identityInfo);
|
|
54
52
|
activeStake = delegatorState.amount.toString();
|
|
55
|
-
const bnActiveStake = new BN(activeStake);
|
|
56
|
-
let delegationStatus = StakingStatus.NOT_EARNING;
|
|
57
|
-
if (bnActiveStake.gt(BN_ZERO) && bnActiveStake.gte(new BN(minDelegatorStake))) {
|
|
58
|
-
delegationStatus = StakingStatus.EARNING_REWARD;
|
|
59
|
-
}
|
|
60
53
|
nominationList.push({
|
|
61
|
-
status:
|
|
54
|
+
status: StakingStatus.NOT_EARNING,
|
|
62
55
|
chain,
|
|
63
56
|
validatorAddress: delegatorState.owner,
|
|
64
57
|
activeStake: delegatorState.amount.toString(),
|
|
65
58
|
validatorMinStake: '0',
|
|
66
|
-
hasUnstaking: !!unstakingInfo
|
|
59
|
+
hasUnstaking: !!unstakingInfo,
|
|
67
60
|
validatorIdentity: identity
|
|
68
61
|
});
|
|
69
62
|
}
|
|
@@ -91,11 +84,9 @@ export async function getAmplitudeNominatorMetadata(chainInfo, address, substrat
|
|
|
91
84
|
if (nominationList.length === 0 && unstakingList.length === 0) {
|
|
92
85
|
return;
|
|
93
86
|
}
|
|
94
|
-
const stakingStatus = getStakingStatusByNominations(new BN(activeStake), nominationList);
|
|
95
87
|
return {
|
|
96
88
|
chain,
|
|
97
89
|
type: StakingType.NOMINATED,
|
|
98
|
-
status: stakingStatus,
|
|
99
90
|
address: address,
|
|
100
91
|
activeStake: activeStake,
|
|
101
92
|
nominations: nominationList,
|
|
@@ -176,4 +167,8 @@ export async function getAmplitudeWithdrawalExtrinsic(substrateApi, address) {
|
|
|
176
167
|
export async function getAmplitudeClaimRewardExtrinsic(substrateApi) {
|
|
177
168
|
const chainApi = await substrateApi.isReady;
|
|
178
169
|
return chainApi.api.tx.utility.batch([chainApi.api.tx.parachainStaking.incrementDelegatorRewards(), chainApi.api.tx.parachainStaking.claimRewards()]);
|
|
170
|
+
}
|
|
171
|
+
export async function getAmplitudeCancelWithdrawalExtrinsic(substrateApi) {
|
|
172
|
+
const chainApi = await substrateApi.isReady;
|
|
173
|
+
return chainApi.api.tx.parachainStaking.cancelLeaveCandidates();
|
|
179
174
|
}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { StakingStatus, StakingType, UnstakingStatus } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
|
-
import { getStakingStatusByNominations } from '@subwallet/extension-base/koni/api/staking/bonding/utils';
|
|
6
5
|
import { _STAKING_ERA_LENGTH_MAP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
7
6
|
import { isUrl, parseRawNumber } from '@subwallet/extension-base/utils';
|
|
8
7
|
import fetch from 'cross-fetch';
|
|
@@ -61,7 +60,6 @@ export async function getAstarNominatorMetadata(chainInfo, address, substrateApi
|
|
|
61
60
|
const [_ledger, _era, _stakerInfo] = await Promise.all([chainApi.api.query.dappsStaking.ledger(address), chainApi.api.query.dappsStaking.currentEra(), chainApi.api.query.dappsStaking.generalStakerInfo.entries(address)]);
|
|
62
61
|
const ledger = _ledger.toPrimitive();
|
|
63
62
|
const currentEra = _era.toString();
|
|
64
|
-
const minDelegatorStake = chainApi.api.consts.dappsStaking.minimumStakingAmount.toString();
|
|
65
63
|
let bnTotalActiveStake = BN_ZERO;
|
|
66
64
|
if (_stakerInfo.length > 0) {
|
|
67
65
|
const dAppInfoMap = {};
|
|
@@ -78,13 +76,13 @@ export async function getAstarNominatorMetadata(chainInfo, address, substrateApi
|
|
|
78
76
|
const currentStake = stakeList.slice(-1)[0].staked.toString() || '0';
|
|
79
77
|
const bnCurrentStake = new BN(currentStake);
|
|
80
78
|
if (bnCurrentStake.gt(BN_ZERO)) {
|
|
81
|
-
const dappStakingStatus = bnCurrentStake.gt(BN_ZERO) && bnCurrentStake.gte(new BN(minDelegatorStake)) ? StakingStatus.EARNING_REWARD : StakingStatus.NOT_EARNING;
|
|
82
79
|
bnTotalActiveStake = bnTotalActiveStake.add(bnCurrentStake);
|
|
83
80
|
const dappInfo = dAppInfoMap[dappAddress];
|
|
84
81
|
nominationList.push({
|
|
85
|
-
status:
|
|
82
|
+
status: StakingStatus.NOT_EARNING,
|
|
83
|
+
// TODO
|
|
86
84
|
chain,
|
|
87
|
-
validatorAddress: dappAddress
|
|
85
|
+
validatorAddress: dappAddress,
|
|
88
86
|
activeStake: currentStake,
|
|
89
87
|
validatorMinStake: '0',
|
|
90
88
|
validatorIdentity: dappInfo === null || dappInfo === void 0 ? void 0 : dappInfo.name,
|
|
@@ -111,7 +109,6 @@ export async function getAstarNominatorMetadata(chainInfo, address, substrateApi
|
|
|
111
109
|
if (nominationList.length === 0 && unstakingList.length === 0) {
|
|
112
110
|
return;
|
|
113
111
|
}
|
|
114
|
-
const stakingStatus = getStakingStatusByNominations(bnTotalActiveStake, nominationList);
|
|
115
112
|
return {
|
|
116
113
|
chain,
|
|
117
114
|
type: StakingType.NOMINATED,
|
|
@@ -119,9 +116,10 @@ export async function getAstarNominatorMetadata(chainInfo, address, substrateApi
|
|
|
119
116
|
activeStake: bnTotalActiveStake.toString(),
|
|
120
117
|
nominations: nominationList,
|
|
121
118
|
unstakings: unstakingList,
|
|
122
|
-
status:
|
|
119
|
+
status: StakingStatus.NOT_EARNING // TODO
|
|
123
120
|
};
|
|
124
121
|
}
|
|
122
|
+
|
|
125
123
|
export async function getAstarDappsInfo(networkKey, substrateApi) {
|
|
126
124
|
const chainApi = await substrateApi.isReady;
|
|
127
125
|
const rawMaxStakerPerContract = chainApi.api.consts.dappsStaking.maxNumberOfStakersPerContract.toHuman();
|
|
@@ -159,7 +157,7 @@ export async function getAstarDappsInfo(networkKey, substrateApi) {
|
|
|
159
157
|
allDappsInfo.push({
|
|
160
158
|
commission: 0,
|
|
161
159
|
expectedReturn: 0,
|
|
162
|
-
address: dappAddress
|
|
160
|
+
address: dappAddress,
|
|
163
161
|
totalStake: totalStake,
|
|
164
162
|
ownStake: '0',
|
|
165
163
|
otherStake: totalStake.toString(),
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
-
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
3
2
|
import { ChainStakingMetadata, NominatorMetadata, StakingType, UnstakingInfo, ValidatorInfo } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
3
|
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function validateBondingCondition(chainInfo: _ChainInfo, amount: string, selectedValidators: ValidatorInfo[], address: string, chainStakingMetadata: ChainStakingMetadata, nominatorMetadata?: NominatorMetadata): TransactionError[];
|
|
7
|
-
export declare function getChainStakingMetadata(chainInfo: _ChainInfo, substrateApi: _SubstrateApi): Promise<ChainStakingMetadata>;
|
|
4
|
+
export declare function getChainStakingMetadata(chain: string, substrateApi: _SubstrateApi): Promise<ChainStakingMetadata>;
|
|
8
5
|
export declare function getNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi): Promise<NominatorMetadata | undefined>;
|
|
9
6
|
export declare function getValidatorsInfo(networkKey: string, substrateApi: _SubstrateApi, decimals: number, chainStakingMetadata: ChainStakingMetadata): Promise<ValidatorInfo[]>;
|
|
10
7
|
export declare function getNominationPoolsInfo(chain: string, substrateApi: _SubstrateApi): Promise<import("@subwallet/extension-base/background/KoniTypes").NominationPoolInfo[]>;
|
|
@@ -2,34 +2,22 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { StakingType } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
|
-
import { getAmplitudeBondingExtrinsic, getAmplitudeClaimRewardExtrinsic, getAmplitudeCollatorsInfo, getAmplitudeNominatorMetadata, getAmplitudeStakingMetadata, getAmplitudeUnbondingExtrinsic, getAmplitudeWithdrawalExtrinsic } from '@subwallet/extension-base/koni/api/staking/bonding/amplitude';
|
|
5
|
+
import { getAmplitudeBondingExtrinsic, getAmplitudeCancelWithdrawalExtrinsic, getAmplitudeClaimRewardExtrinsic, getAmplitudeCollatorsInfo, getAmplitudeNominatorMetadata, getAmplitudeStakingMetadata, getAmplitudeUnbondingExtrinsic, getAmplitudeWithdrawalExtrinsic } from '@subwallet/extension-base/koni/api/staking/bonding/amplitude';
|
|
6
6
|
import { getAstarBondingExtrinsic, getAstarClaimRewardExtrinsic, getAstarDappsInfo, getAstarNominatorMetadata, getAstarStakingMetadata, getAstarUnbondingExtrinsic, getAstarWithdrawalExtrinsic } from '@subwallet/extension-base/koni/api/staking/bonding/astar';
|
|
7
|
-
import { getParaBondingExtrinsic, getParaCancelWithdrawalExtrinsic, getParachainCollatorsInfo, getParaChainNominatorMetadata, getParaChainStakingMetadata, getParaUnbondingExtrinsic, getParaWithdrawalExtrinsic
|
|
8
|
-
import { getPoolingClaimRewardExtrinsic, getPoolingWithdrawalExtrinsic, getRelayBondingExtrinsic, getRelayCancelWithdrawalExtrinsic, getRelayChainNominatorMetadata, getRelayChainStakingMetadata, getRelayPoolsInfo, getRelayUnbondingExtrinsic, getRelayValidatorsInfo, getRelayWithdrawalExtrinsic
|
|
7
|
+
import { getParaBondingExtrinsic, getParaCancelWithdrawalExtrinsic, getParachainCollatorsInfo, getParaChainNominatorMetadata, getParaChainStakingMetadata, getParaUnbondingExtrinsic, getParaWithdrawalExtrinsic } from '@subwallet/extension-base/koni/api/staking/bonding/paraChain';
|
|
8
|
+
import { getPoolingClaimRewardExtrinsic, getPoolingWithdrawalExtrinsic, getRelayBondingExtrinsic, getRelayCancelWithdrawalExtrinsic, getRelayChainNominatorMetadata, getRelayChainStakingMetadata, getRelayPoolsInfo, getRelayUnbondingExtrinsic, getRelayValidatorsInfo, getRelayWithdrawalExtrinsic } from '@subwallet/extension-base/koni/api/staking/bonding/relayChain';
|
|
9
9
|
import { _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
10
10
|
// all addresses must be converted to its chain format
|
|
11
11
|
|
|
12
|
-
export function
|
|
13
|
-
if (_STAKING_CHAIN_GROUP.
|
|
14
|
-
return
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (_STAKING_CHAIN_GROUP.relay.includes(chainInfo.slug)) {
|
|
20
|
-
return validateRelayBondingCondition(chainInfo, amount, selectedValidators, address, chainStakingMetadata, nominatorMetadata);
|
|
21
|
-
}
|
|
22
|
-
return validateParaChainBondingCondition(chainInfo, amount, selectedValidators, address, chainStakingMetadata, nominatorMetadata);
|
|
23
|
-
}
|
|
24
|
-
export async function getChainStakingMetadata(chainInfo, substrateApi) {
|
|
25
|
-
if (_STAKING_CHAIN_GROUP.astar.includes(chainInfo.slug)) {
|
|
26
|
-
return getAstarStakingMetadata(chainInfo.slug, substrateApi);
|
|
27
|
-
} else if (_STAKING_CHAIN_GROUP.para.includes(chainInfo.slug)) {
|
|
28
|
-
return getParaChainStakingMetadata(chainInfo.slug, substrateApi);
|
|
29
|
-
} else if (_STAKING_CHAIN_GROUP.amplitude.includes(chainInfo.slug)) {
|
|
30
|
-
return getAmplitudeStakingMetadata(chainInfo.slug, substrateApi);
|
|
12
|
+
export async function getChainStakingMetadata(chain, substrateApi) {
|
|
13
|
+
if (_STAKING_CHAIN_GROUP.astar.includes(chain)) {
|
|
14
|
+
return getAstarStakingMetadata(chain, substrateApi);
|
|
15
|
+
} else if (_STAKING_CHAIN_GROUP.para.includes(chain)) {
|
|
16
|
+
return getParaChainStakingMetadata(chain, substrateApi);
|
|
17
|
+
} else if (_STAKING_CHAIN_GROUP.amplitude.includes(chain)) {
|
|
18
|
+
return getAmplitudeStakingMetadata(chain, substrateApi);
|
|
31
19
|
}
|
|
32
|
-
return getRelayChainStakingMetadata(
|
|
20
|
+
return getRelayChainStakingMetadata(chain, substrateApi);
|
|
33
21
|
}
|
|
34
22
|
export async function getNominatorMetadata(chainInfo, address, substrateApi) {
|
|
35
23
|
if (_STAKING_CHAIN_GROUP.astar.includes(chainInfo.slug)) {
|
|
@@ -98,6 +86,8 @@ export async function getClaimRewardExtrinsic(substrateApi, chain, address, stak
|
|
|
98
86
|
export async function getCancelWithdrawalExtrinsic(substrateApi, chain, selectedUnstaking) {
|
|
99
87
|
if (_STAKING_CHAIN_GROUP.para.includes(chain)) {
|
|
100
88
|
return getParaCancelWithdrawalExtrinsic(substrateApi, selectedUnstaking);
|
|
89
|
+
} else if (_STAKING_CHAIN_GROUP.amplitude.includes(chain)) {
|
|
90
|
+
return getAmplitudeCancelWithdrawalExtrinsic(substrateApi);
|
|
101
91
|
}
|
|
102
92
|
return getRelayCancelWithdrawalExtrinsic(substrateApi, selectedUnstaking);
|
|
103
93
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
-
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
3
2
|
import { ChainStakingMetadata, NominatorMetadata, UnstakingInfo, ValidatorInfo } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
3
|
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
5
|
-
export declare function validateParaChainUnbondingCondition(amount: string, nominatorMetadata: NominatorMetadata, chainStakingMetadata: ChainStakingMetadata, selectedCollator: string): TransactionError[];
|
|
6
|
-
export declare function validateParaChainBondingCondition(chainInfo: _ChainInfo, amount: string, selectedCollators: ValidatorInfo[], address: string, chainStakingMetadata: ChainStakingMetadata, nominatorMetadata?: NominatorMetadata): TransactionError[];
|
|
7
4
|
export declare function getParaChainStakingMetadata(chain: string, substrateApi: _SubstrateApi): Promise<ChainStakingMetadata>;
|
|
8
5
|
export declare function getParaChainNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi): Promise<NominatorMetadata | undefined>;
|
|
9
6
|
export declare function getParachainCollatorsInfo(chain: string, substrateApi: _SubstrateApi): Promise<ValidatorInfo[]>;
|