@subwallet/extension-base 1.0.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 +25 -36
- package/background/KoniTypes.js +12 -7
- package/background/errors/TransactionError.js +21 -1
- package/cjs/background/KoniTypes.js +14 -8
- package/cjs/background/errors/TransactionError.js +20 -0
- package/cjs/constants/index.js +13 -28
- package/cjs/koni/api/dotsama/balance.js +60 -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 +18 -10
- package/cjs/koni/api/staking/bonding/astar.js +37 -238
- package/cjs/koni/api/staking/bonding/index.js +26 -14
- package/cjs/koni/api/staking/bonding/paraChain.js +100 -11
- package/cjs/koni/api/staking/bonding/relayChain.js +174 -16
- package/cjs/koni/api/staking/bonding/utils.js +55 -10
- 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/index.js +0 -111
- package/cjs/koni/api/xcm/polkadotXcm.js +2 -2
- package/cjs/koni/api/xcm/utils.js +18 -13
- package/cjs/koni/api/xcm/xTokens.js +3 -5
- package/cjs/koni/api/xcm/xcmPallet.js +9 -6
- package/cjs/koni/background/cron.js +179 -77
- package/cjs/koni/background/handlers/Extension.js +231 -195
- package/cjs/koni/background/handlers/State.js +147 -111
- package/cjs/koni/background/handlers/Tabs.js +48 -39
- package/cjs/koni/background/subscription.js +64 -56
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/index.js +5 -0
- package/cjs/services/chain-service/constants.js +1 -11
- 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 +39 -6
- package/cjs/services/chain-service/utils.js +4 -0
- package/cjs/services/event-service/index.js +75 -0
- package/cjs/services/event-service/types.js +11 -0
- package/cjs/services/history-service/index.js +46 -21
- package/cjs/services/history-service/subsquid-multi-chain-history.js +19 -11
- package/cjs/services/keyring-service/index.js +101 -0
- package/cjs/services/migration-service/index.js +13 -10
- package/cjs/{koni/migration/scripts/RemoveWrongCrowdloan.js → services/migration-service/scripts/AutoEnableChainsTokens.js} +11 -6
- package/cjs/services/migration-service/scripts/MigrateNetworkSettings.js +39 -19
- package/cjs/services/migration-service/scripts/MigrateSettings.js +31 -0
- package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +72 -0
- package/cjs/services/migration-service/scripts/index.js +13 -4
- package/cjs/services/price-service/coingecko.js +15 -3
- package/cjs/services/price-service/index.js +15 -18
- package/cjs/services/request-service/constants.js +8 -2
- package/cjs/services/request-service/handler/AuthRequestHandler.js +43 -12
- package/cjs/services/request-service/index.js +3 -0
- package/cjs/services/storage-service/DatabaseService.js +53 -34
- package/cjs/services/storage-service/databases/index.js +1 -1
- package/cjs/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
- package/cjs/services/storage-service/db-stores/Nft.js +8 -18
- package/cjs/services/storage-service/db-stores/Transaction.js +10 -7
- package/cjs/services/subscan-service/index.js +107 -0
- package/cjs/services/subscan-service/subscan-chain-map.js +74 -0
- package/cjs/services/subscan-service/types.js +1 -0
- package/cjs/services/transaction-service/event-parser/index.js +20 -48
- package/cjs/services/transaction-service/index.js +66 -22
- package/cjs/services/transaction-service/utils.js +4 -6
- package/cjs/utils/address.js +9 -1
- package/cjs/utils/index.js +30 -26
- package/constants/index.d.ts +8 -13
- package/constants/index.js +8 -13
- package/koni/api/dotsama/balance.d.ts +0 -1
- package/koni/api/dotsama/balance.js +33 -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 +1 -2
- package/koni/api/staking/bonding/amplitude.js +22 -13
- package/koni/api/staking/bonding/astar.d.ts +2 -11
- package/koni/api/staking/bonding/astar.js +39 -231
- package/koni/api/staking/bonding/index.d.ts +5 -2
- package/koni/api/staking/bonding/index.js +27 -17
- package/koni/api/staking/bonding/paraChain.d.ts +4 -1
- package/koni/api/staking/bonding/paraChain.js +101 -14
- package/koni/api/staking/bonding/relayChain.d.ts +6 -2
- package/koni/api/staking/bonding/relayChain.js +172 -17
- package/koni/api/staking/bonding/utils.d.ts +15 -2
- package/koni/api/staking/bonding/utils.js +53 -11
- 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/index.js +1 -112
- package/koni/api/xcm/polkadotXcm.js +3 -3
- package/koni/api/xcm/utils.d.ts +5 -6
- package/koni/api/xcm/utils.js +15 -10
- package/koni/api/xcm/xTokens.js +5 -7
- package/koni/api/xcm/xcmPallet.js +10 -9
- package/koni/background/cron.d.ts +6 -1
- package/koni/background/cron.js +179 -76
- package/koni/background/handlers/Extension.d.ts +2 -2
- package/koni/background/handlers/Extension.js +161 -125
- package/koni/background/handlers/State.d.ts +21 -20
- package/koni/background/handlers/State.js +144 -111
- package/koni/background/handlers/Tabs.js +30 -20
- package/koni/background/subscription.d.ts +1 -1
- package/koni/background/subscription.js +64 -58
- package/package.json +63 -18
- package/packageInfo.js +1 -1
- package/page/index.d.ts +2 -0
- package/page/index.js +4 -0
- package/services/chain-service/constants.d.ts +0 -1
- package/services/chain-service/constants.js +0 -9
- 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.d.ts +6 -4
- package/services/chain-service/index.js +40 -9
- package/services/chain-service/utils.d.ts +1 -0
- package/services/chain-service/utils.js +3 -0
- package/services/event-service/index.d.ts +22 -0
- package/services/event-service/index.js +63 -0
- package/services/event-service/types.d.ts +28 -0
- package/services/event-service/types.js +4 -0
- package/services/history-service/index.d.ts +5 -3
- package/services/history-service/index.js +46 -21
- package/services/history-service/subsquid-multi-chain-history.js +22 -13
- package/services/keyring-service/index.d.ts +19 -0
- package/services/keyring-service/index.js +93 -0
- package/services/migration-service/index.js +11 -9
- package/services/migration-service/scripts/AutoEnableChainsTokens.d.ts +4 -0
- package/services/migration-service/scripts/AutoEnableChainsTokens.js +13 -0
- package/services/migration-service/scripts/MigrateNetworkSettings.js +37 -18
- package/services/migration-service/scripts/MigrateSettings.d.ts +4 -0
- package/services/migration-service/scripts/MigrateSettings.js +23 -0
- package/services/migration-service/scripts/MigrateTransactionHistory.d.ts +4 -0
- package/services/migration-service/scripts/MigrateTransactionHistory.js +64 -0
- package/services/migration-service/scripts/index.d.ts +1 -0
- package/services/migration-service/scripts/index.js +10 -3
- package/services/price-service/coingecko.js +15 -3
- package/services/price-service/index.d.ts +5 -3
- package/services/price-service/index.js +15 -18
- package/services/request-service/constants.d.ts +1 -0
- package/services/request-service/constants.js +6 -1
- package/services/request-service/handler/AuthRequestHandler.d.ts +8 -1
- package/services/request-service/handler/AuthRequestHandler.js +44 -13
- package/services/request-service/index.d.ts +7 -1
- package/services/request-service/index.js +3 -0
- package/services/storage-service/DatabaseService.d.ts +1 -0
- package/services/storage-service/DatabaseService.js +53 -34
- package/services/storage-service/databases/index.js +1 -1
- package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.d.ts +1 -1
- package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
- package/services/storage-service/db-stores/Nft.d.ts +3 -3
- package/services/storage-service/db-stores/Nft.js +8 -17
- package/services/storage-service/db-stores/Transaction.js +10 -7
- package/services/subscan-service/index.d.ts +20 -0
- package/services/subscan-service/index.js +99 -0
- package/services/subscan-service/subscan-chain-map.d.ts +5 -0
- package/services/subscan-service/subscan-chain-map.js +63 -0
- package/services/subscan-service/types.d.ts +27 -0
- package/services/subscan-service/types.js +1 -0
- package/services/transaction-service/event-parser/index.d.ts +2 -2
- package/services/transaction-service/event-parser/index.js +21 -49
- package/services/transaction-service/index.d.ts +4 -2
- package/services/transaction-service/index.js +66 -22
- package/services/transaction-service/utils.js +5 -6
- package/utils/address.d.ts +1 -0
- package/utils/address.js +9 -2
- package/utils/index.d.ts +2 -1
- package/utils/index.js +26 -23
- package/cjs/background/errors/EvmRpcError.js +0 -21
- package/cjs/background/errors/SubWalletProviderError.js +0 -17
- package/cjs/constants/ethereum.js +0 -19
- package/cjs/errors/SubWalletProviderError.js +0 -17
- package/cjs/koni/api/xcm/astar.js +0 -160
- package/cjs/koni/api/xcm/moonbeamXcm.js +0 -80
- package/cjs/koni/api/xcm/statemintXcm.js +0 -197
- package/cjs/koni/api/xcm/substrateXcm.js +0 -213
- package/cjs/koni/migration/Base.js +0 -20
- package/cjs/koni/migration/index.js +0 -45
- package/cjs/koni/migration/scripts/ChangeRouteToHome.js +0 -22
- package/cjs/koni/migration/scripts/ClearOldStorage.js +0 -24
- package/cjs/koni/migration/scripts/RemoveWrongTransactionHistoriesFromStore.js +0 -36
- package/cjs/koni/migration/scripts/ResetTransactionHistoryEventIdx.js +0 -21
- package/cjs/koni/migration/scripts/index.js +0 -22
- package/cjs/koni/page/index.js +0 -16
- package/cjs/services/asset-service/index.js +0 -91
- package/cjs/services/storage-service/db-stores/ExtraDelegationInfo.js +0 -17
- package/cjs/stores/Balance.js +0 -18
- package/cjs/stores/Crowdloan.js +0 -18
- package/cjs/stores/CustomEvmToken.js +0 -18
- package/cjs/stores/NetworkMap.js +0 -18
- package/cjs/stores/Nft.js +0 -18
- package/cjs/stores/NftCollection.js +0 -18
- package/cjs/stores/Price.js +0 -18
- package/cjs/stores/Staking.js +0 -18
- package/cjs/stores/StakingReward.js +0 -18
- package/cjs/utils/eth/parseTransactionData.js +0 -284
- package/koni/page/index.d.ts +0 -2
- package/koni/page/index.js +0 -9
- /package/cjs/{koni/page → page}/SubWalleEvmProvider.js +0 -0
- /package/{koni/page → page}/SubWalleEvmProvider.d.ts +0 -0
- /package/{koni/page → page}/SubWalleEvmProvider.js +0 -0
|
@@ -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';
|
|
@@ -4,8 +4,7 @@ import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/
|
|
|
4
4
|
export declare function getAmplitudeStakingMetadata(chain: string, substrateApi: _SubstrateApi): Promise<ChainStakingMetadata>;
|
|
5
5
|
export declare function getAmplitudeNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi): Promise<NominatorMetadata | undefined>;
|
|
6
6
|
export declare function getAmplitudeCollatorsInfo(chain: string, substrateApi: _SubstrateApi): Promise<ValidatorInfo[]>;
|
|
7
|
-
export declare function getAmplitudeBondingExtrinsic(
|
|
7
|
+
export declare function getAmplitudeBondingExtrinsic(substrateApi: _SubstrateApi, amount: string, selectedValidatorInfo: ValidatorInfo, nominatorMetadata?: NominatorMetadata): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
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>>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { StakingType, UnstakingStatus } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
|
-
import { getBondedValidators, isUnstakeAll, parseIdentity } from '@subwallet/extension-base/koni/api/staking/bonding/utils';
|
|
4
|
+
import { StakingStatus, StakingType, UnstakingStatus } from '@subwallet/extension-base/background/KoniTypes';
|
|
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
|
-
import { parseRawNumber } from '@subwallet/extension-base/utils';
|
|
8
|
-
import { BN } from '@polkadot/util';
|
|
7
|
+
import { parseRawNumber, reformatAddress } from '@subwallet/extension-base/utils';
|
|
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,23 +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({
|
|
61
|
+
status: delegationStatus,
|
|
54
62
|
chain,
|
|
55
63
|
validatorAddress: delegatorState.owner,
|
|
56
64
|
activeStake: delegatorState.amount.toString(),
|
|
57
65
|
validatorMinStake: '0',
|
|
58
|
-
hasUnstaking: !!unstakingInfo,
|
|
66
|
+
hasUnstaking: !!unstakingInfo && Object.values(unstakingInfo).length > 0,
|
|
59
67
|
validatorIdentity: identity
|
|
60
68
|
});
|
|
61
69
|
}
|
|
@@ -83,9 +91,11 @@ export async function getAmplitudeNominatorMetadata(chainInfo, address, substrat
|
|
|
83
91
|
if (nominationList.length === 0 && unstakingList.length === 0) {
|
|
84
92
|
return;
|
|
85
93
|
}
|
|
94
|
+
const stakingStatus = getStakingStatusByNominations(new BN(activeStake), nominationList);
|
|
86
95
|
return {
|
|
87
96
|
chain,
|
|
88
97
|
type: StakingType.NOMINATED,
|
|
98
|
+
status: stakingStatus,
|
|
89
99
|
address: address,
|
|
90
100
|
activeStake: activeStake,
|
|
91
101
|
nominations: nominationList,
|
|
@@ -121,13 +131,16 @@ export async function getAmplitudeCollatorsInfo(chain, substrateApi) {
|
|
|
121
131
|
}
|
|
122
132
|
return allCollators;
|
|
123
133
|
}
|
|
124
|
-
export async function getAmplitudeBondingExtrinsic(
|
|
134
|
+
export async function getAmplitudeBondingExtrinsic(substrateApi, amount, selectedValidatorInfo, nominatorMetadata) {
|
|
125
135
|
const chainApi = await substrateApi.isReady;
|
|
126
136
|
const binaryAmount = new BN(amount);
|
|
137
|
+
if (!nominatorMetadata) {
|
|
138
|
+
return chainApi.api.tx.parachainStaking.joinDelegators(selectedValidatorInfo.address, binaryAmount);
|
|
139
|
+
}
|
|
127
140
|
const {
|
|
128
141
|
bondedValidators
|
|
129
142
|
} = getBondedValidators(nominatorMetadata.nominations);
|
|
130
|
-
if (!bondedValidators.includes(selectedValidatorInfo.address)) {
|
|
143
|
+
if (!bondedValidators.includes(reformatAddress(selectedValidatorInfo.address, 0))) {
|
|
131
144
|
return chainApi.api.tx.parachainStaking.joinDelegators(selectedValidatorInfo.address, binaryAmount);
|
|
132
145
|
} else {
|
|
133
146
|
const _params = chainApi.api.tx.parachainStaking.delegatorStakeMore.toJSON();
|
|
@@ -163,8 +176,4 @@ export async function getAmplitudeWithdrawalExtrinsic(substrateApi, address) {
|
|
|
163
176
|
export async function getAmplitudeClaimRewardExtrinsic(substrateApi) {
|
|
164
177
|
const chainApi = await substrateApi.isReady;
|
|
165
178
|
return chainApi.api.tx.utility.batch([chainApi.api.tx.parachainStaking.incrementDelegatorRewards(), chainApi.api.tx.parachainStaking.claimRewards()]);
|
|
166
|
-
}
|
|
167
|
-
export async function getAmplitudeCancelWithdrawalExtrinsic(substrateApi) {
|
|
168
|
-
const chainApi = await substrateApi.isReady;
|
|
169
|
-
return chainApi.api.tx.parachainStaking.cancelLeaveCandidates();
|
|
170
179
|
}
|
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { ChainStakingMetadata, NominatorMetadata, ValidatorInfo } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
|
+
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
4
4
|
export declare function getAstarStakingMetadata(chain: string, substrateApi: _SubstrateApi): Promise<ChainStakingMetadata>;
|
|
5
5
|
export declare function getAstarNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi): Promise<NominatorMetadata | undefined>;
|
|
6
6
|
export declare function getAstarDappsInfo(networkKey: string, substrateApi: _SubstrateApi): Promise<ValidatorInfo[]>;
|
|
7
|
-
export declare function getAstarBondingTxInfo(chainInfo: _ChainInfo, substrateApi: _SubstrateApi, stakerAddress: string, amount: number, dappInfo: ValidatorInfo): Promise<import("@polkadot/types/interfaces").RuntimeDispatchInfo>;
|
|
8
|
-
export declare function handleAstarBondingTxInfo(chainInfo: _ChainInfo, amount: number, networkKey: string, stakerAddress: string, dappInfo: ValidatorInfo, substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>): Promise<BasicTxInfo>;
|
|
9
7
|
export declare function getAstarBondingExtrinsic(substrateApi: _SubstrateApi, amount: string, dappInfo: ValidatorInfo): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
10
|
-
export declare function getAstarUnbondingTxInfo(chainInfo: _ChainInfo, substrateApi: _SubstrateApi, stakerAddress: string, amount: number, dappAddress: string): Promise<import("@polkadot/types/interfaces").RuntimeDispatchInfo>;
|
|
11
|
-
export declare function handleAstarUnbondingTxInfo(chainInfo: _ChainInfo, amount: number, networkKey: string, stakerAddress: string, dappAddress: string, substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>): Promise<BasicTxInfo>;
|
|
12
8
|
export declare function getAstarUnbondingExtrinsic(substrateApi: _SubstrateApi, amount: string, dappAddress: string): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
13
|
-
export declare function handleAstarUnlockingInfo(substrateApi: _SubstrateApi, chainInfo: _ChainInfo, networkKey: string, address: string, type: StakingType): Promise<UnlockingStakeInfo>;
|
|
14
|
-
export declare function getAstarWithdrawalTxInfo(substrateApi: _SubstrateApi, address: string): Promise<import("@polkadot/types/interfaces").RuntimeDispatchInfo>;
|
|
15
|
-
export declare function handleAstarWithdrawalTxInfo(networkKey: string, chainInfo: _ChainInfo, substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>, address: string): Promise<BasicTxInfo>;
|
|
16
9
|
export declare function getAstarWithdrawalExtrinsic(substrateApi: _SubstrateApi): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
17
|
-
export declare function getAstarClaimRewardTxInfo(substrateApi: _SubstrateApi, address: string): Promise<import("@polkadot/types/interfaces").RuntimeDispatchInfo>;
|
|
18
|
-
export declare function handleAstarClaimRewardTxInfo(address: string, networkKey: string, chainInfo: _ChainInfo, substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>): Promise<BasicTxInfo>;
|
|
19
10
|
export declare function getAstarClaimRewardExtrinsic(substrateApi: _SubstrateApi, address: string): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|