@subwallet/extension-base 1.2.14-0 → 1.2.16-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +6 -1
- package/cjs/core/substrate/nominationpools-pallet.js +2 -1
- package/cjs/koni/api/nft/config.js +9 -5
- package/cjs/koni/api/nft/index.js +9 -1
- package/cjs/koni/api/nft/unique_network_nft/index.js +12 -20
- package/cjs/koni/background/handlers/Extension.js +45 -7
- package/cjs/koni/background/handlers/State.js +11 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/index.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/substrate/gear.js +135 -0
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +9 -62
- package/cjs/services/balance-service/transfer/token.js +4 -3
- package/cjs/services/chain-service/constants.js +1 -0
- package/cjs/services/chain-service/handler/SubstrateApi.js +3 -1
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +21 -26
- package/cjs/services/chain-service/health-check/constants/index.js +4 -4
- package/cjs/services/chain-service/health-check/utils/asset-info.js +23 -6
- package/cjs/services/chain-service/health-check/utils/chain-info.js +25 -2
- package/cjs/services/chain-service/health-check/utils/new-utils/asset-asset-validate.js +160 -0
- package/cjs/services/chain-service/health-check/utils/new-utils/asset-validate.js +45 -0
- package/cjs/services/chain-service/health-check/utils/new-utils/chain-asset-validate.js +73 -0
- package/cjs/services/chain-service/health-check/utils/new-utils/chain-validate.js +34 -0
- package/cjs/services/chain-service/index.js +77 -3
- package/cjs/services/chain-service/types.js +1 -1
- package/cjs/services/chain-service/utils/index.js +18 -12
- package/cjs/services/earning-service/handlers/liquid-staking/acala.js +49 -19
- package/cjs/services/earning-service/service.js +3 -0
- package/cjs/services/migration-service/scripts/databases/ClearMetadataDatabase.js +16 -0
- package/cjs/services/migration-service/scripts/index.js +7 -7
- package/cjs/services/price-service/coingecko.js +57 -32
- package/cjs/services/price-service/index.js +30 -11
- package/cjs/services/transaction-service/index.js +12 -7
- package/cjs/utils/gear/combine.js +28 -0
- package/cjs/utils/gear/grc20.js +56 -49
- package/cjs/utils/gear/index.js +22 -0
- package/cjs/utils/gear/vft.js +173 -0
- package/cjs/utils/metadata.js +45 -34
- package/core/substrate/nominationpools-pallet.js +2 -1
- package/koni/api/nft/config.d.ts +1 -0
- package/koni/api/nft/config.js +3 -1
- package/koni/api/nft/index.js +9 -1
- package/koni/api/nft/unique_network_nft/index.js +12 -20
- package/koni/background/handlers/Extension.d.ts +2 -0
- package/koni/background/handlers/Extension.js +37 -1
- package/koni/background/handlers/State.d.ts +2 -0
- package/koni/background/handlers/State.js +11 -1
- package/package.json +44 -8
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/index.js +1 -1
- package/services/balance-service/helpers/subscribe/substrate/gear.d.ts +4 -0
- package/services/balance-service/helpers/subscribe/substrate/gear.js +123 -0
- package/services/balance-service/helpers/subscribe/substrate/index.js +10 -61
- package/services/balance-service/transfer/token.js +5 -4
- package/services/chain-service/constants.d.ts +1 -0
- package/services/chain-service/constants.js +1 -0
- package/services/chain-service/handler/SubstrateApi.d.ts +1 -1
- package/services/chain-service/handler/SubstrateApi.js +3 -1
- package/services/chain-service/handler/SubstrateChainHandler.d.ts +1 -0
- package/services/chain-service/handler/SubstrateChainHandler.js +22 -27
- package/services/chain-service/health-check/constants/index.js +4 -4
- package/services/chain-service/health-check/utils/asset-info.d.ts +1 -0
- package/services/chain-service/health-check/utils/asset-info.js +20 -4
- package/services/chain-service/health-check/utils/chain-info.d.ts +4 -2
- package/services/chain-service/health-check/utils/chain-info.js +20 -0
- package/services/chain-service/health-check/utils/new-utils/asset-asset-validate.d.ts +10 -0
- package/services/chain-service/health-check/utils/new-utils/asset-asset-validate.js +146 -0
- package/services/chain-service/health-check/utils/new-utils/asset-validate.d.ts +3 -0
- package/services/chain-service/health-check/utils/new-utils/asset-validate.js +38 -0
- package/services/chain-service/health-check/utils/new-utils/chain-asset-validate.d.ts +5 -0
- package/services/chain-service/health-check/utils/new-utils/chain-asset-validate.js +64 -0
- package/services/chain-service/health-check/utils/new-utils/chain-validate.d.ts +4 -0
- package/services/chain-service/health-check/utils/new-utils/chain-validate.js +26 -0
- package/services/chain-service/index.d.ts +4 -0
- package/services/chain-service/index.js +78 -4
- package/services/chain-service/types.d.ts +6 -0
- package/services/chain-service/types.js +1 -1
- package/services/chain-service/utils/index.d.ts +1 -0
- package/services/chain-service/utils/index.js +16 -12
- package/services/earning-service/handlers/liquid-staking/acala.js +46 -17
- package/services/earning-service/service.js +3 -0
- package/services/migration-service/scripts/databases/ClearMetadataDatabase.js +16 -0
- package/services/migration-service/scripts/index.js +7 -7
- package/services/price-service/coingecko.js +54 -32
- package/services/price-service/index.js +29 -11
- package/services/transaction-service/index.js +13 -8
- package/types/metadata.d.ts +9 -2
- package/utils/gear/combine.d.ts +10 -0
- package/utils/gear/combine.js +18 -0
- package/utils/gear/grc20.d.ts +18 -20
- package/utils/gear/grc20.js +53 -45
- package/utils/gear/index.d.ts +2 -0
- package/utils/gear/index.js +3 -1
- package/utils/gear/vft.d.ts +36 -0
- package/utils/gear/vft.js +162 -0
- package/utils/metadata.d.ts +7 -2
- package/utils/metadata.js +41 -31
|
@@ -15,6 +15,7 @@ import { getERC20SpendingApprovalTx } from '@subwallet/extension-base/koni/api/c
|
|
|
15
15
|
import { isSnowBridgeGatewayContract } from '@subwallet/extension-base/koni/api/contract-handler/utils';
|
|
16
16
|
import { resolveAzeroAddressToDomain, resolveAzeroDomainToAddress } from '@subwallet/extension-base/koni/api/dotsama/domain';
|
|
17
17
|
import { parseSubstrateTransaction } from '@subwallet/extension-base/koni/api/dotsama/parseTransaction';
|
|
18
|
+
import { UNSUPPORTED_TRANSFER_EVM_CHAIN_NAME } from '@subwallet/extension-base/koni/api/nft/config';
|
|
18
19
|
import { getNftTransferExtrinsic, isRecipientSelf } from '@subwallet/extension-base/koni/api/nft/transfer';
|
|
19
20
|
import { getBondingExtrinsic, getCancelWithdrawalExtrinsic, getClaimRewardExtrinsic, getNominationPoolsInfo, getUnbondingExtrinsic, getValidatorsInfo, validateBondingCondition, validateUnbondingCondition } from '@subwallet/extension-base/koni/api/staking/bonding';
|
|
20
21
|
import { getTuringCancelCompoundingExtrinsic, getTuringCompoundExtrinsic } from '@subwallet/extension-base/koni/api/staking/bonding/paraChain';
|
|
@@ -1797,6 +1798,17 @@ export default class KoniExtension {
|
|
|
1797
1798
|
} = inputData;
|
|
1798
1799
|
const contractAddress = params.contractAddress;
|
|
1799
1800
|
const tokenId = params.tokenId;
|
|
1801
|
+
if (UNSUPPORTED_TRANSFER_EVM_CHAIN_NAME.includes(networkKey)) {
|
|
1802
|
+
return await this.#koniState.transactionService.handleTransaction({
|
|
1803
|
+
address: senderAddress,
|
|
1804
|
+
chain: networkKey,
|
|
1805
|
+
chainType: ChainType.EVM,
|
|
1806
|
+
data: inputData,
|
|
1807
|
+
extrinsicType: ExtrinsicType.SEND_NFT,
|
|
1808
|
+
transaction: null,
|
|
1809
|
+
url: EXTENSION_REQUEST_URL
|
|
1810
|
+
});
|
|
1811
|
+
}
|
|
1800
1812
|
const transaction = await getERC721Transaction(this.#koniState.getEvmApi(networkKey), networkKey, contractAddress, senderAddress, recipientAddress, tokenId);
|
|
1801
1813
|
|
|
1802
1814
|
// this.addContact(recipientAddress);
|
|
@@ -3620,7 +3632,7 @@ export default class KoniExtension {
|
|
|
3620
3632
|
};
|
|
3621
3633
|
}
|
|
3622
3634
|
|
|
3623
|
-
|
|
3635
|
+
/* Metadata */
|
|
3624
3636
|
|
|
3625
3637
|
async findRawMetadata({
|
|
3626
3638
|
genesisHash
|
|
@@ -3638,6 +3650,26 @@ export default class KoniExtension {
|
|
|
3638
3650
|
userExtensions
|
|
3639
3651
|
};
|
|
3640
3652
|
}
|
|
3653
|
+
async calculateMetadataHash({
|
|
3654
|
+
chain
|
|
3655
|
+
}) {
|
|
3656
|
+
const hash = await this.#koniState.calculateMetadataHash(chain);
|
|
3657
|
+
return {
|
|
3658
|
+
metadataHash: hash || ''
|
|
3659
|
+
};
|
|
3660
|
+
}
|
|
3661
|
+
async shortenMetadata({
|
|
3662
|
+
chain,
|
|
3663
|
+
txBlob
|
|
3664
|
+
}) {
|
|
3665
|
+
const shorten = await this.#koniState.shortenMetadata(chain, txBlob);
|
|
3666
|
+
return {
|
|
3667
|
+
txMetadata: shorten || ''
|
|
3668
|
+
};
|
|
3669
|
+
}
|
|
3670
|
+
|
|
3671
|
+
/* Metadata */
|
|
3672
|
+
|
|
3641
3673
|
async resolveDomainByAddress(request) {
|
|
3642
3674
|
const chainApi = this.#koniState.getSubstrateApi(request.chain);
|
|
3643
3675
|
return await resolveAzeroDomainToAddress(request.domain, request.chain, chainApi.api);
|
|
@@ -4575,6 +4607,10 @@ export default class KoniExtension {
|
|
|
4575
4607
|
// Metadata
|
|
4576
4608
|
case 'pri(metadata.find)':
|
|
4577
4609
|
return this.findRawMetadata(request);
|
|
4610
|
+
case 'pri(metadata.hash)':
|
|
4611
|
+
return this.calculateMetadataHash(request);
|
|
4612
|
+
case 'pri(metadata.transaction.shorten)':
|
|
4613
|
+
return this.shortenMetadata(request);
|
|
4578
4614
|
|
|
4579
4615
|
/* Campaign */
|
|
4580
4616
|
case 'pri(campaign.banner.subscribe)':
|
|
@@ -258,6 +258,8 @@ export default class KoniState {
|
|
|
258
258
|
types: Record<string, string | Record<string, string>>;
|
|
259
259
|
userExtensions: import("@polkadot/types/extrinsic/signedExtensions/types").ExtDef | undefined;
|
|
260
260
|
}>;
|
|
261
|
+
calculateMetadataHash(chain: string): Promise<string | undefined>;
|
|
262
|
+
shortenMetadata(chain: string, txBlob: string): Promise<string | undefined>;
|
|
261
263
|
getCrowdloanContributions({ address, page, relayChain }: RequestCrowdloanContributions): Promise<import("../../../services/subscan-service/types").CrowdloanContributionsResponse>;
|
|
262
264
|
}
|
|
263
265
|
export {};
|
|
@@ -1789,7 +1789,8 @@ export default class KoniState {
|
|
|
1789
1789
|
return (_this$chainService34 = this.chainService) === null || _this$chainService34 === void 0 ? void 0 : (_this$chainService34$ = _this$chainService34.mantaPay) === null || _this$chainService34$ === void 0 ? void 0 : _this$chainService34$.subscribeSyncState();
|
|
1790
1790
|
}
|
|
1791
1791
|
|
|
1792
|
-
|
|
1792
|
+
/* Metadata */
|
|
1793
|
+
|
|
1793
1794
|
async findMetadata(hash) {
|
|
1794
1795
|
const metadata = await this.chainService.getMetadataByHash(hash);
|
|
1795
1796
|
return {
|
|
@@ -1799,6 +1800,15 @@ export default class KoniState {
|
|
|
1799
1800
|
userExtensions: metadata === null || metadata === void 0 ? void 0 : metadata.userExtensions
|
|
1800
1801
|
};
|
|
1801
1802
|
}
|
|
1803
|
+
async calculateMetadataHash(chain) {
|
|
1804
|
+
return this.chainService.calculateMetadataHash(chain);
|
|
1805
|
+
}
|
|
1806
|
+
async shortenMetadata(chain, txBlob) {
|
|
1807
|
+
return this.chainService.shortenMetadata(chain, txBlob);
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
/* Metadata */
|
|
1811
|
+
|
|
1802
1812
|
getCrowdloanContributions({
|
|
1803
1813
|
address,
|
|
1804
1814
|
page,
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.2.
|
|
20
|
+
"version": "1.2.16-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -559,6 +559,11 @@
|
|
|
559
559
|
"require": "./cjs/services/balance-service/helpers/subscribe/substrate/equilibrium.js",
|
|
560
560
|
"default": "./services/balance-service/helpers/subscribe/substrate/equilibrium.js"
|
|
561
561
|
},
|
|
562
|
+
"./services/balance-service/helpers/subscribe/substrate/gear": {
|
|
563
|
+
"types": "./services/balance-service/helpers/subscribe/substrate/gear.d.ts",
|
|
564
|
+
"require": "./cjs/services/balance-service/helpers/subscribe/substrate/gear.js",
|
|
565
|
+
"default": "./services/balance-service/helpers/subscribe/substrate/gear.js"
|
|
566
|
+
},
|
|
562
567
|
"./services/balance-service/transfer/smart-contract": {
|
|
563
568
|
"types": "./services/balance-service/transfer/smart-contract.d.ts",
|
|
564
569
|
"require": "./cjs/services/balance-service/transfer/smart-contract.js",
|
|
@@ -719,6 +724,26 @@
|
|
|
719
724
|
"require": "./cjs/services/chain-service/health-check/utils/chain-info.js",
|
|
720
725
|
"default": "./services/chain-service/health-check/utils/chain-info.js"
|
|
721
726
|
},
|
|
727
|
+
"./services/chain-service/health-check/utils/new-utils/asset-asset-validate": {
|
|
728
|
+
"types": "./services/chain-service/health-check/utils/new-utils/asset-asset-validate.d.ts",
|
|
729
|
+
"require": "./cjs/services/chain-service/health-check/utils/new-utils/asset-asset-validate.js",
|
|
730
|
+
"default": "./services/chain-service/health-check/utils/new-utils/asset-asset-validate.js"
|
|
731
|
+
},
|
|
732
|
+
"./services/chain-service/health-check/utils/new-utils/asset-validate": {
|
|
733
|
+
"types": "./services/chain-service/health-check/utils/new-utils/asset-validate.d.ts",
|
|
734
|
+
"require": "./cjs/services/chain-service/health-check/utils/new-utils/asset-validate.js",
|
|
735
|
+
"default": "./services/chain-service/health-check/utils/new-utils/asset-validate.js"
|
|
736
|
+
},
|
|
737
|
+
"./services/chain-service/health-check/utils/new-utils/chain-asset-validate": {
|
|
738
|
+
"types": "./services/chain-service/health-check/utils/new-utils/chain-asset-validate.d.ts",
|
|
739
|
+
"require": "./cjs/services/chain-service/health-check/utils/new-utils/chain-asset-validate.js",
|
|
740
|
+
"default": "./services/chain-service/health-check/utils/new-utils/chain-asset-validate.js"
|
|
741
|
+
},
|
|
742
|
+
"./services/chain-service/health-check/utils/new-utils/chain-validate": {
|
|
743
|
+
"types": "./services/chain-service/health-check/utils/new-utils/chain-validate.d.ts",
|
|
744
|
+
"require": "./cjs/services/chain-service/health-check/utils/new-utils/chain-validate.js",
|
|
745
|
+
"default": "./services/chain-service/health-check/utils/new-utils/chain-validate.js"
|
|
746
|
+
},
|
|
722
747
|
"./services/chain-service/health-check/utils/provider": {
|
|
723
748
|
"types": "./services/chain-service/health-check/utils/provider.d.ts",
|
|
724
749
|
"require": "./cjs/services/chain-service/health-check/utils/provider.js",
|
|
@@ -1861,11 +1886,21 @@
|
|
|
1861
1886
|
"require": "./cjs/utils/gear/index.js",
|
|
1862
1887
|
"default": "./utils/gear/index.js"
|
|
1863
1888
|
},
|
|
1889
|
+
"./utils/gear/combine": {
|
|
1890
|
+
"types": "./utils/gear/combine.d.ts",
|
|
1891
|
+
"require": "./cjs/utils/gear/combine.js",
|
|
1892
|
+
"default": "./utils/gear/combine.js"
|
|
1893
|
+
},
|
|
1864
1894
|
"./utils/gear/grc20": {
|
|
1865
1895
|
"types": "./utils/gear/grc20.d.ts",
|
|
1866
1896
|
"require": "./cjs/utils/gear/grc20.js",
|
|
1867
1897
|
"default": "./utils/gear/grc20.js"
|
|
1868
1898
|
},
|
|
1899
|
+
"./utils/gear/vft": {
|
|
1900
|
+
"types": "./utils/gear/vft.d.ts",
|
|
1901
|
+
"require": "./cjs/utils/gear/vft.js",
|
|
1902
|
+
"default": "./utils/gear/vft.js"
|
|
1903
|
+
},
|
|
1869
1904
|
"./utils/getId": {
|
|
1870
1905
|
"types": "./utils/getId.d.ts",
|
|
1871
1906
|
"require": "./cjs/utils/getId.js",
|
|
@@ -1949,11 +1984,12 @@
|
|
|
1949
1984
|
"@ethereumjs/tx": "^5.1.0",
|
|
1950
1985
|
"@ethersproject/abi": "^5.7.0",
|
|
1951
1986
|
"@galacticcouncil/sdk": "^2.1.0",
|
|
1952
|
-
"@gear-js/api": "^0.
|
|
1987
|
+
"@gear-js/api": "^0.38.1",
|
|
1953
1988
|
"@json-rpc-tools/utils": "^1.7.6",
|
|
1954
1989
|
"@metamask/safe-event-emitter": "^2.0.0",
|
|
1955
1990
|
"@metaverse-network-sdk/type-definitions": "^0.0.1-13",
|
|
1956
1991
|
"@oak-foundation/types": "^0.0.23",
|
|
1992
|
+
"@polkadot-api/merkleize-metadata": "^1.1.0",
|
|
1957
1993
|
"@polkadot/api": "^11.0.3",
|
|
1958
1994
|
"@polkadot/api-base": "^10.11.2",
|
|
1959
1995
|
"@polkadot/api-contract": "^11.0.3",
|
|
@@ -1973,11 +2009,11 @@
|
|
|
1973
2009
|
"@reduxjs/toolkit": "^1.9.1",
|
|
1974
2010
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
1975
2011
|
"@substrate/connect": "^0.8.9",
|
|
1976
|
-
"@subwallet/chain-list": "0.2.
|
|
1977
|
-
"@subwallet/extension-base": "^1.2.
|
|
1978
|
-
"@subwallet/extension-chains": "^1.2.
|
|
1979
|
-
"@subwallet/extension-dapp": "^1.2.
|
|
1980
|
-
"@subwallet/extension-inject": "^1.2.
|
|
2012
|
+
"@subwallet/chain-list": "0.2.75",
|
|
2013
|
+
"@subwallet/extension-base": "^1.2.16-0",
|
|
2014
|
+
"@subwallet/extension-chains": "^1.2.16-0",
|
|
2015
|
+
"@subwallet/extension-dapp": "^1.2.16-0",
|
|
2016
|
+
"@subwallet/extension-inject": "^1.2.16-0",
|
|
1981
2017
|
"@subwallet/keyring": "^0.1.5",
|
|
1982
2018
|
"@subwallet/ui-keyring": "^0.1.5",
|
|
1983
2019
|
"@walletconnect/keyvaluestorage": "^1.1.1",
|
|
@@ -2006,7 +2042,7 @@
|
|
|
2006
2042
|
"moment": "^2.29.4",
|
|
2007
2043
|
"protobufjs": "^7.2.4",
|
|
2008
2044
|
"rxjs": "^7.8.1",
|
|
2009
|
-
"sails-js": "^0.1.
|
|
2045
|
+
"sails-js": "^0.1.6",
|
|
2010
2046
|
"uuid": "^9.0.0",
|
|
2011
2047
|
"web3": "^1.10.0",
|
|
2012
2048
|
"web3-core": "^1.10.0",
|
package/packageInfo.js
CHANGED
|
@@ -7,5 +7,5 @@ export const packageInfo = {
|
|
|
7
7
|
name: '@subwallet/extension-base',
|
|
8
8
|
path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
|
|
9
9
|
type: 'esm',
|
|
10
|
-
version: '1.2.
|
|
10
|
+
version: '1.2.16-0'
|
|
11
11
|
};
|
|
@@ -82,7 +82,7 @@ export function subscribeBalance(addresses, chains, tokens, _chainAssetMap, _cha
|
|
|
82
82
|
const chainSlug = chainInfo.slug;
|
|
83
83
|
const [useAddresses, notSupportAddresses] = filterAddress(addresses, chainInfo);
|
|
84
84
|
if (notSupportAddresses.length) {
|
|
85
|
-
const tokens = filterAssetsByChainAndType(chainAssetMap, chainSlug, [_AssetType.NATIVE, _AssetType.ERC20, _AssetType.PSP22, _AssetType.LOCAL, _AssetType.GRC20]);
|
|
85
|
+
const tokens = filterAssetsByChainAndType(chainAssetMap, chainSlug, [_AssetType.NATIVE, _AssetType.ERC20, _AssetType.PSP22, _AssetType.LOCAL, _AssetType.GRC20, _AssetType.VFT]);
|
|
86
86
|
const now = new Date().getTime();
|
|
87
87
|
Object.values(tokens).forEach(token => {
|
|
88
88
|
const items = notSupportAddresses.map(address => ({
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="filesystem" />
|
|
2
|
+
import { SubscribeSubstratePalletBalance } from '@subwallet/extension-base/types';
|
|
3
|
+
export declare const subscribeGRC20Balance: ({ addresses, assetMap, callback, chainInfo, substrateApi }: SubscribeSubstratePalletBalance) => VoidCallback;
|
|
4
|
+
export declare const subscribeVftBalance: ({ addresses, assetMap, callback, chainInfo, substrateApi }: SubscribeSubstratePalletBalance) => VoidCallback;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { GearApi } from '@gear-js/api';
|
|
5
|
+
import { _AssetType } from '@subwallet/chain-list/types';
|
|
6
|
+
import { APIItemState } from '@subwallet/extension-base/background/KoniTypes';
|
|
7
|
+
import { SUB_TOKEN_REFRESH_BALANCE_INTERVAL } from '@subwallet/extension-base/constants';
|
|
8
|
+
import { _getContractAddressOfToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
|
+
import { filterAssetsByChainAndType, getGRC20ContractPromise, getVFTContractPromise } from '@subwallet/extension-base/utils';
|
|
10
|
+
import { noop, u8aToHex } from '@polkadot/util';
|
|
11
|
+
import { decodeAddress } from '@polkadot/util-crypto';
|
|
12
|
+
export const subscribeGRC20Balance = ({
|
|
13
|
+
addresses,
|
|
14
|
+
assetMap,
|
|
15
|
+
callback,
|
|
16
|
+
chainInfo,
|
|
17
|
+
substrateApi
|
|
18
|
+
}) => {
|
|
19
|
+
if (!(substrateApi instanceof GearApi)) {
|
|
20
|
+
console.warn('Cannot subscribe GRC20 balance without GearApi instance');
|
|
21
|
+
return noop;
|
|
22
|
+
}
|
|
23
|
+
const chain = chainInfo.slug;
|
|
24
|
+
const grc20ContractMap = {};
|
|
25
|
+
const tokenList = filterAssetsByChainAndType(assetMap, chain, [_AssetType.GRC20]);
|
|
26
|
+
Object.entries(tokenList).forEach(([slug, tokenInfo]) => {
|
|
27
|
+
grc20ContractMap[slug] = getGRC20ContractPromise(substrateApi, _getContractAddressOfToken(tokenInfo));
|
|
28
|
+
});
|
|
29
|
+
const getTokenBalances = () => {
|
|
30
|
+
Object.values(tokenList).map(async tokenInfo => {
|
|
31
|
+
try {
|
|
32
|
+
const contract = grc20ContractMap[tokenInfo.slug];
|
|
33
|
+
const balances = await Promise.all(addresses.map(async address => {
|
|
34
|
+
try {
|
|
35
|
+
const actor = u8aToHex(decodeAddress(address));
|
|
36
|
+
const _balanceOf = await contract.service.balanceOf(actor, address);
|
|
37
|
+
return {
|
|
38
|
+
address: address,
|
|
39
|
+
tokenSlug: tokenInfo.slug,
|
|
40
|
+
free: _balanceOf.toString(10),
|
|
41
|
+
locked: '0',
|
|
42
|
+
state: APIItemState.READY
|
|
43
|
+
};
|
|
44
|
+
} catch (err) {
|
|
45
|
+
console.error(`Error on get balance of account ${address} for token ${tokenInfo.slug}`, err);
|
|
46
|
+
return {
|
|
47
|
+
address: address,
|
|
48
|
+
tokenSlug: tokenInfo.slug,
|
|
49
|
+
free: '0',
|
|
50
|
+
locked: '0',
|
|
51
|
+
state: APIItemState.READY
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}));
|
|
55
|
+
callback(balances);
|
|
56
|
+
} catch (err) {
|
|
57
|
+
console.warn(tokenInfo.slug, err); // TODO: error createType
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
getTokenBalances();
|
|
63
|
+
const interval = setInterval(getTokenBalances, SUB_TOKEN_REFRESH_BALANCE_INTERVAL);
|
|
64
|
+
return () => {
|
|
65
|
+
clearInterval(interval);
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
export const subscribeVftBalance = ({
|
|
69
|
+
addresses,
|
|
70
|
+
assetMap,
|
|
71
|
+
callback,
|
|
72
|
+
chainInfo,
|
|
73
|
+
substrateApi
|
|
74
|
+
}) => {
|
|
75
|
+
if (!(substrateApi instanceof GearApi)) {
|
|
76
|
+
console.warn('Cannot subscribe VFT balance without GearApi instance');
|
|
77
|
+
return noop;
|
|
78
|
+
}
|
|
79
|
+
const chain = chainInfo.slug;
|
|
80
|
+
const vftContractMap = {};
|
|
81
|
+
const tokenList = filterAssetsByChainAndType(assetMap, chain, [_AssetType.VFT]);
|
|
82
|
+
Object.entries(tokenList).forEach(([slug, tokenInfo]) => {
|
|
83
|
+
vftContractMap[slug] = getVFTContractPromise(substrateApi, _getContractAddressOfToken(tokenInfo));
|
|
84
|
+
});
|
|
85
|
+
const getTokenBalances = () => {
|
|
86
|
+
Object.values(tokenList).map(async tokenInfo => {
|
|
87
|
+
try {
|
|
88
|
+
const contract = vftContractMap[tokenInfo.slug];
|
|
89
|
+
const balances = await Promise.all(addresses.map(async address => {
|
|
90
|
+
try {
|
|
91
|
+
const actor = u8aToHex(decodeAddress(address));
|
|
92
|
+
const _balanceOf = await contract.service.balanceOf(actor, address);
|
|
93
|
+
return {
|
|
94
|
+
address: address,
|
|
95
|
+
tokenSlug: tokenInfo.slug,
|
|
96
|
+
free: _balanceOf.toString(10),
|
|
97
|
+
locked: '0',
|
|
98
|
+
state: APIItemState.READY
|
|
99
|
+
};
|
|
100
|
+
} catch (err) {
|
|
101
|
+
console.error(`Error on get balance of account ${address} for token ${tokenInfo.slug}`, err);
|
|
102
|
+
return {
|
|
103
|
+
address: address,
|
|
104
|
+
tokenSlug: tokenInfo.slug,
|
|
105
|
+
free: '0',
|
|
106
|
+
locked: '0',
|
|
107
|
+
state: APIItemState.READY
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}));
|
|
111
|
+
callback(balances);
|
|
112
|
+
} catch (err) {
|
|
113
|
+
console.warn(tokenInfo.slug, err); // TODO: error createType
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
getTokenBalances();
|
|
119
|
+
const interval = setInterval(getTokenBalances, SUB_TOKEN_REFRESH_BALANCE_INTERVAL);
|
|
120
|
+
return () => {
|
|
121
|
+
clearInterval(interval);
|
|
122
|
+
};
|
|
123
|
+
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { GearApi } from '@gear-js/api';
|
|
5
4
|
import { _AssetType } from '@subwallet/chain-list/types';
|
|
6
5
|
import { APIItemState } from '@subwallet/extension-base/background/KoniTypes';
|
|
7
6
|
import { SUB_TOKEN_REFRESH_BALANCE_INTERVAL } from '@subwallet/extension-base/constants';
|
|
@@ -12,13 +11,13 @@ import { getPSP22ContractPromise } from '@subwallet/extension-base/koni/api/cont
|
|
|
12
11
|
import { getDefaultWeightV2 } from '@subwallet/extension-base/koni/api/contract-handler/wasm/utils';
|
|
13
12
|
import { _BALANCE_CHAIN_GROUP, _MANTA_ZK_CHAIN_GROUP, _ZK_ASSET_PREFIX } from '@subwallet/extension-base/services/chain-service/constants';
|
|
14
13
|
import { _checkSmartContractSupportByChain, _getChainExistentialDeposit, _getChainNativeTokenSlug, _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _getTokenTypesSupportedByChain, _getXcmAssetMultilocation, _isBridgedToken, _isChainEvmCompatible, _isSubstrateRelayChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
15
|
-
import { filterAssetsByChainAndType
|
|
14
|
+
import { filterAssetsByChainAndType } from '@subwallet/extension-base/utils';
|
|
16
15
|
import BigN from 'bignumber.js';
|
|
17
16
|
import { combineLatest, Observable } from 'rxjs';
|
|
18
|
-
import { BN, BN_ZERO
|
|
19
|
-
import { decodeAddress } from '@polkadot/util-crypto';
|
|
17
|
+
import { BN, BN_ZERO } from '@polkadot/util';
|
|
20
18
|
import { subscribeERC20Interval } from "../evm.js";
|
|
21
19
|
import { subscribeEquilibriumTokenBalance } from "./equilibrium.js";
|
|
20
|
+
import { subscribeGRC20Balance, subscribeVftBalance } from "./gear.js";
|
|
22
21
|
export const subscribeSubstrateBalance = async (addresses, chainInfo, assetMap, substrateApi, evmApi, callback, extrinsicType) => {
|
|
23
22
|
let unsubNativeToken;
|
|
24
23
|
let unsubLocalToken;
|
|
@@ -26,6 +25,7 @@ export const subscribeSubstrateBalance = async (addresses, chainInfo, assetMap,
|
|
|
26
25
|
let unsubWasmContractToken;
|
|
27
26
|
let unsubBridgedToken;
|
|
28
27
|
let unsubGrcToken;
|
|
28
|
+
let unsubVftToken;
|
|
29
29
|
const chain = chainInfo.slug;
|
|
30
30
|
const baseParams = {
|
|
31
31
|
addresses,
|
|
@@ -82,17 +82,22 @@ export const subscribeSubstrateBalance = async (addresses, chainInfo, assetMap,
|
|
|
82
82
|
// Get sub-token for substrate-based chains
|
|
83
83
|
unsubGrcToken = subscribeGRC20Balance(substrateParams);
|
|
84
84
|
}
|
|
85
|
+
if (_checkSmartContractSupportByChain(chainInfo, _AssetType.VFT)) {
|
|
86
|
+
// Get sub-token for substrate-based chains
|
|
87
|
+
unsubVftToken = subscribeVftBalance(substrateParams);
|
|
88
|
+
}
|
|
85
89
|
} catch (err) {
|
|
86
90
|
console.warn(err);
|
|
87
91
|
}
|
|
88
92
|
return () => {
|
|
89
|
-
var _unsubGrcToken;
|
|
93
|
+
var _unsubGrcToken, _unsubVftToken;
|
|
90
94
|
unsubNativeToken && unsubNativeToken();
|
|
91
95
|
unsubLocalToken && unsubLocalToken();
|
|
92
96
|
unsubEvmContractToken && unsubEvmContractToken();
|
|
93
97
|
unsubWasmContractToken && unsubWasmContractToken();
|
|
94
98
|
unsubBridgedToken && unsubBridgedToken();
|
|
95
99
|
(_unsubGrcToken = unsubGrcToken) === null || _unsubGrcToken === void 0 ? void 0 : _unsubGrcToken();
|
|
100
|
+
(_unsubVftToken = unsubVftToken) === null || _unsubVftToken === void 0 ? void 0 : _unsubVftToken();
|
|
96
101
|
};
|
|
97
102
|
};
|
|
98
103
|
|
|
@@ -421,60 +426,4 @@ const subscribeOrmlTokensPallet = async ({
|
|
|
421
426
|
}).catch(console.error);
|
|
422
427
|
});
|
|
423
428
|
};
|
|
424
|
-
};
|
|
425
|
-
const subscribeGRC20Balance = ({
|
|
426
|
-
addresses,
|
|
427
|
-
assetMap,
|
|
428
|
-
callback,
|
|
429
|
-
chainInfo,
|
|
430
|
-
substrateApi
|
|
431
|
-
}) => {
|
|
432
|
-
if (!(substrateApi instanceof GearApi)) {
|
|
433
|
-
console.warn('Cannot subscribe VFT balance without GearApi instance');
|
|
434
|
-
return noop;
|
|
435
|
-
}
|
|
436
|
-
const chain = chainInfo.slug;
|
|
437
|
-
const psp22ContractMap = {};
|
|
438
|
-
const tokenList = filterAssetsByChainAndType(assetMap, chain, [_AssetType.GRC20]);
|
|
439
|
-
Object.entries(tokenList).forEach(([slug, tokenInfo]) => {
|
|
440
|
-
psp22ContractMap[slug] = getGRC20ContractPromise(substrateApi, _getContractAddressOfToken(tokenInfo));
|
|
441
|
-
});
|
|
442
|
-
const getTokenBalances = () => {
|
|
443
|
-
Object.values(tokenList).map(async tokenInfo => {
|
|
444
|
-
try {
|
|
445
|
-
const contract = psp22ContractMap[tokenInfo.slug];
|
|
446
|
-
const balances = await Promise.all(addresses.map(async address => {
|
|
447
|
-
try {
|
|
448
|
-
const actor = u8aToHex(decodeAddress(address));
|
|
449
|
-
const _balanceOf = await contract.balanceOf(actor, address);
|
|
450
|
-
return {
|
|
451
|
-
address: address,
|
|
452
|
-
tokenSlug: tokenInfo.slug,
|
|
453
|
-
free: _balanceOf.toString(10),
|
|
454
|
-
locked: '0',
|
|
455
|
-
state: APIItemState.READY
|
|
456
|
-
};
|
|
457
|
-
} catch (err) {
|
|
458
|
-
console.error(`Error on get balance of account ${address} for token ${tokenInfo.slug}`, err);
|
|
459
|
-
return {
|
|
460
|
-
address: address,
|
|
461
|
-
tokenSlug: tokenInfo.slug,
|
|
462
|
-
free: '0',
|
|
463
|
-
locked: '0',
|
|
464
|
-
state: APIItemState.READY
|
|
465
|
-
};
|
|
466
|
-
}
|
|
467
|
-
}));
|
|
468
|
-
callback(balances);
|
|
469
|
-
} catch (err) {
|
|
470
|
-
console.warn(tokenInfo.slug, err); // TODO: error createType
|
|
471
|
-
}
|
|
472
|
-
});
|
|
473
|
-
};
|
|
474
|
-
|
|
475
|
-
getTokenBalances();
|
|
476
|
-
const interval = setInterval(getTokenBalances, SUB_TOKEN_REFRESH_BALANCE_INTERVAL);
|
|
477
|
-
return () => {
|
|
478
|
-
clearInterval(interval);
|
|
479
|
-
};
|
|
480
429
|
};
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { GearApi } from '@gear-js/api';
|
|
5
|
+
import { _AssetType } from '@subwallet/chain-list/types';
|
|
5
6
|
import { getPSP22ContractPromise } from '@subwallet/extension-base/koni/api/contract-handler/wasm';
|
|
6
7
|
import { getWasmContractGasLimit } from '@subwallet/extension-base/koni/api/contract-handler/wasm/utils';
|
|
7
8
|
import { _TRANSFER_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
8
9
|
import { _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _getXcmAssetMultilocation, _isBridgedToken, _isChainEvmCompatible, _isNativeToken, _isTokenGearSmartContract, _isTokenTransferredByEvm, _isTokenWasmSmartContract } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
10
|
import { calculateGasFeeParams } from '@subwallet/extension-base/services/fee-service/utils';
|
|
10
|
-
import { getGRC20ContractPromise } from '@subwallet/extension-base/utils';
|
|
11
|
+
import { getGRC20ContractPromise, getVFTContractPromise } from '@subwallet/extension-base/utils';
|
|
11
12
|
import BigN from 'bignumber.js';
|
|
12
13
|
import { BN, u8aToHex } from '@polkadot/util';
|
|
13
14
|
import { decodeAddress } from '@polkadot/util-crypto';
|
|
@@ -53,12 +54,12 @@ export const createTransferExtrinsic = async ({
|
|
|
53
54
|
}, to, value, {});
|
|
54
55
|
transferAmount = value;
|
|
55
56
|
} else if (_isTokenGearSmartContract(tokenInfo) && api instanceof GearApi) {
|
|
56
|
-
const contractPromise = getGRC20ContractPromise(api, _getContractAddressOfToken(tokenInfo));
|
|
57
|
-
const transaction = await contractPromise.transfer(u8aToHex(decodeAddress(to)),
|
|
57
|
+
const contractPromise = tokenInfo.assetType === _AssetType.GRC20 ? getGRC20ContractPromise(api, _getContractAddressOfToken(tokenInfo)) : getVFTContractPromise(api, _getContractAddressOfToken(tokenInfo));
|
|
58
|
+
const transaction = await contractPromise.service.transfer(u8aToHex(decodeAddress(to)), value) // Create transfer transaction
|
|
58
59
|
.withAccount(from) // Set sender account
|
|
59
60
|
.calculateGas(); // Add account arg to extrinsic
|
|
60
61
|
|
|
61
|
-
transfer = transaction.
|
|
62
|
+
transfer = transaction.extrinsic;
|
|
62
63
|
transferAmount = value;
|
|
63
64
|
} else if (_TRANSFER_CHAIN_GROUP.acala.includes(networkKey)) {
|
|
64
65
|
if (!_isNativeToken(tokenInfo)) {
|
|
@@ -48,6 +48,7 @@ export const _NFT_CHAIN_GROUP = {
|
|
|
48
48
|
statemine: ['statemine'],
|
|
49
49
|
statemint: ['statemint'],
|
|
50
50
|
unique_network: ['unique_network', 'quartz', 'opal'],
|
|
51
|
+
unique_evm: ['unique_evm'],
|
|
51
52
|
bitcountry: ['bitcountry', 'pioneer', 'continuum_network'],
|
|
52
53
|
vara: ['vara_network']
|
|
53
54
|
};
|
|
@@ -39,7 +39,7 @@ export declare class SubstrateApi implements _SubstrateApi {
|
|
|
39
39
|
constructor(chainSlug: string, apiUrl: string, { externalApiPromise, metadata, providerName }?: _ApiOptions);
|
|
40
40
|
get isReady(): Promise<_SubstrateApi>;
|
|
41
41
|
updateApiUrl(apiUrl: string): Promise<void>;
|
|
42
|
-
connect(): void;
|
|
42
|
+
connect(_callbackUpdateMetadata?: (substrateApi: _SubstrateApi) => void): void;
|
|
43
43
|
disconnect(): Promise<void>;
|
|
44
44
|
recoverConnect(): Promise<void>;
|
|
45
45
|
destroy(): Promise<void>;
|
|
@@ -159,14 +159,16 @@ export class SubstrateApi {
|
|
|
159
159
|
this.provider = this.createProvider(apiUrl);
|
|
160
160
|
this.api = this.createApi(this.provider);
|
|
161
161
|
}
|
|
162
|
-
connect() {
|
|
162
|
+
connect(_callbackUpdateMetadata) {
|
|
163
163
|
if (this.api.isConnected) {
|
|
164
164
|
this.updateConnectionStatus(_ChainConnectionStatus.CONNECTED);
|
|
165
|
+
_callbackUpdateMetadata === null || _callbackUpdateMetadata === void 0 ? void 0 : _callbackUpdateMetadata(this);
|
|
165
166
|
} else {
|
|
166
167
|
this.updateConnectionStatus(_ChainConnectionStatus.CONNECTING);
|
|
167
168
|
this.api.connect().then(() => {
|
|
168
169
|
this.api.isReady.then(() => {
|
|
169
170
|
this.updateConnectionStatus(_ChainConnectionStatus.CONNECTED);
|
|
171
|
+
_callbackUpdateMetadata === null || _callbackUpdateMetadata === void 0 ? void 0 : _callbackUpdateMetadata(this);
|
|
170
172
|
}).catch(console.error);
|
|
171
173
|
}).catch(console.error);
|
|
172
174
|
}
|
|
@@ -19,6 +19,7 @@ export declare class SubstrateChainHandler extends AbstractChainHandler {
|
|
|
19
19
|
private getPsp22TokenInfo;
|
|
20
20
|
private getPsp34TokenInfo;
|
|
21
21
|
private getGrc20TokenInfo;
|
|
22
|
+
private getVftTokenInfo;
|
|
22
23
|
getSubstrateContractTokenInfo(contractAddress: string, tokenType: _AssetType, originChain: string, contractCaller?: string): Promise<_SmartContractTokenInfo>;
|
|
23
24
|
setSubstrateApi(chainSlug: string, substrateApi: SubstrateApi): void;
|
|
24
25
|
destroySubstrateApi(chainSlug: string): void;
|