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