@subwallet/extension-base 1.1.18-1 → 1.1.20-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 +3 -0
- package/cjs/constants/index.js +3 -6
- package/cjs/koni/api/dotsama/crowdloan.js +2 -4
- package/cjs/koni/api/dotsama/transfer.js +1 -1
- package/cjs/koni/api/xcm/xTokens.js +1 -1
- package/cjs/koni/background/handlers/Extension.js +57 -7
- package/cjs/koni/background/handlers/State.js +7 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/buy-service/constants/index.js +16 -0
- package/cjs/services/buy-service/constants/token.js +31 -0
- package/cjs/services/buy-service/index.js +95 -0
- package/cjs/services/campaign-service/index.js +2 -8
- package/cjs/services/chain-service/handler/EvmChainHandler.js +5 -3
- package/cjs/services/chain-service/index.js +27 -5
- package/cjs/services/event-service/index.js +2 -0
- package/cjs/services/storage-service/db-stores/Crowdloan.js +14 -0
- package/cjs/services/storage-service/db-stores/NftCollection.js +2 -2
- package/cjs/types/buy.js +1 -0
- package/cjs/types/index.js +16 -0
- package/cjs/utils/fetchStaticData.js +18 -0
- package/constants/index.d.ts +0 -1
- package/constants/index.js +0 -1
- package/koni/api/dotsama/crowdloan.js +2 -4
- package/koni/api/dotsama/transfer.js +1 -1
- package/koni/api/xcm/xTokens.js +1 -1
- package/koni/background/handlers/Extension.d.ts +2 -0
- package/koni/background/handlers/Extension.js +57 -7
- package/koni/background/handlers/State.d.ts +2 -0
- package/koni/background/handlers/State.js +7 -1
- package/package.json +39 -9
- package/packageInfo.js +1 -1
- package/services/buy-service/constants/index.d.ts +1 -0
- package/services/buy-service/constants/index.js +4 -0
- package/services/buy-service/constants/token.d.ts +2 -0
- package/services/buy-service/constants/token.js +24 -0
- package/services/buy-service/index.d.ts +14 -0
- package/services/buy-service/index.js +88 -0
- package/services/buy-service/types.d.ts +22 -0
- package/services/campaign-service/index.js +2 -7
- package/services/chain-service/handler/EvmChainHandler.js +5 -3
- package/services/chain-service/index.js +28 -6
- package/services/event-service/index.d.ts +2 -0
- package/services/event-service/index.js +2 -0
- package/services/event-service/types.d.ts +2 -0
- package/services/storage-service/db-stores/Crowdloan.d.ts +1 -0
- package/services/storage-service/db-stores/Crowdloan.js +14 -0
- package/services/storage-service/db-stores/NftCollection.d.ts +1 -1
- package/services/storage-service/db-stores/NftCollection.js +2 -2
- package/types/buy.d.ts +20 -0
- package/types/buy.js +1 -0
- package/{types.d.ts → types/index.d.ts} +1 -0
- package/types/index.js +5 -0
- package/utils/fetchStaticData.d.ts +1 -0
- package/utils/fetchStaticData.js +11 -0
- /package/cjs/{types.js → services/buy-service/types.js} +0 -0
- /package/{types.js → services/buy-service/types.js} +0 -0
|
@@ -1572,7 +1572,7 @@ export default class KoniExtension {
|
|
|
1572
1572
|
if (new BigN(receiverBalance).plus(transferAmount.value).lt(minAmount)) {
|
|
1573
1573
|
const atLeast = new BigN(minAmount).minus(receiverBalance).plus((tokenInfo.decimals || 0) === 0 ? 0 : 1);
|
|
1574
1574
|
const atLeastStr = formatNumber(atLeast, tokenInfo.decimals || 0, balanceFormatter);
|
|
1575
|
-
inputTransaction.errors.push(new TransactionError(TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT, t('You must transfer at least {{amount}}{{symbol}} to keep the destination account alive', {
|
|
1575
|
+
inputTransaction.errors.push(new TransactionError(TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT, t('You must transfer at least {{amount}} {{symbol}} to keep the destination account alive', {
|
|
1576
1576
|
replace: {
|
|
1577
1577
|
amount: atLeastStr,
|
|
1578
1578
|
symbol: tokenInfo.symbol
|
|
@@ -1641,7 +1641,7 @@ export default class KoniExtension {
|
|
|
1641
1641
|
// Check ed for receiver
|
|
1642
1642
|
if (new BigN(value).lt(atLeast)) {
|
|
1643
1643
|
const atLeastStr = formatNumber(atLeast, destinationTokenInfo.decimals || 0, balanceFormatter);
|
|
1644
|
-
inputTransaction.errors.push(new TransactionError(TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT, t('You must transfer at least {{amount}}{{symbol}} to keep the destination account alive', {
|
|
1644
|
+
inputTransaction.errors.push(new TransactionError(TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT, t('You must transfer at least {{amount}} {{symbol}} to keep the destination account alive', {
|
|
1645
1645
|
replace: {
|
|
1646
1646
|
amount: atLeastStr,
|
|
1647
1647
|
symbol: originTokenInfo.symbol
|
|
@@ -1827,7 +1827,6 @@ export default class KoniExtension {
|
|
|
1827
1827
|
if (!destinationTokenInfo) {
|
|
1828
1828
|
estimatedFee = '0';
|
|
1829
1829
|
} else {
|
|
1830
|
-
var _paymentInfo$partialF;
|
|
1831
1830
|
maxTransferable = maxTransferable.sub(new BN(tokenInfo.minAmount || '0'));
|
|
1832
1831
|
const desChainInfo = chainInfoMap[destChain];
|
|
1833
1832
|
const orgChainInfo = chainInfoMap[networkKey];
|
|
@@ -1837,11 +1836,16 @@ export default class KoniExtension {
|
|
|
1837
1836
|
destinationTokenInfo,
|
|
1838
1837
|
originTokenInfo: tokenInfo,
|
|
1839
1838
|
recipient: recipient,
|
|
1840
|
-
sendingValue: '
|
|
1839
|
+
sendingValue: '1000000000000000000',
|
|
1841
1840
|
substrateApi
|
|
1842
1841
|
});
|
|
1843
|
-
|
|
1844
|
-
|
|
1842
|
+
try {
|
|
1843
|
+
var _paymentInfo$partialF;
|
|
1844
|
+
const paymentInfo = await mockTx.paymentInfo(address);
|
|
1845
|
+
estimatedFee = (paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF = paymentInfo.partialFee) === null || _paymentInfo$partialF === void 0 ? void 0 : _paymentInfo$partialF.toString()) || '0';
|
|
1846
|
+
} catch (e) {
|
|
1847
|
+
estimatedFee = tokenInfo.minAmount || '0';
|
|
1848
|
+
}
|
|
1845
1849
|
}
|
|
1846
1850
|
} else {
|
|
1847
1851
|
const chainInfo = this.#koniState.chainService.getChainInfoByKey(networkKey);
|
|
@@ -1865,7 +1869,7 @@ export default class KoniExtension {
|
|
|
1865
1869
|
to: address,
|
|
1866
1870
|
tokenInfo,
|
|
1867
1871
|
transferAll: true,
|
|
1868
|
-
value: '
|
|
1872
|
+
value: '1000000000000000000'
|
|
1869
1873
|
});
|
|
1870
1874
|
const paymentInfo = await (mockTx === null || mockTx === void 0 ? void 0 : mockTx.paymentInfo(address));
|
|
1871
1875
|
estimatedFee = (paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF2 = paymentInfo.partialFee) === null || _paymentInfo$partialF2 === void 0 ? void 0 : _paymentInfo$partialF2.toString()) || '0';
|
|
@@ -3552,6 +3556,45 @@ export default class KoniExtension {
|
|
|
3552
3556
|
|
|
3553
3557
|
/* Campaign */
|
|
3554
3558
|
|
|
3559
|
+
/* Buy service */
|
|
3560
|
+
|
|
3561
|
+
async subscribeBuyTokens(id, port) {
|
|
3562
|
+
const cb = createSubscription(id, port);
|
|
3563
|
+
let ready = false;
|
|
3564
|
+
const callback = rs => {
|
|
3565
|
+
if (ready) {
|
|
3566
|
+
cb(rs);
|
|
3567
|
+
}
|
|
3568
|
+
};
|
|
3569
|
+
const subscription = this.#koniState.buyService.subscribeBuyTokens(callback);
|
|
3570
|
+
this.createUnsubscriptionHandle(id, subscription.unsubscribe);
|
|
3571
|
+
port.onDisconnect.addListener(() => {
|
|
3572
|
+
this.cancelSubscription(id);
|
|
3573
|
+
});
|
|
3574
|
+
await this.#koniState.eventService.waitBuyTokenReady;
|
|
3575
|
+
ready = true;
|
|
3576
|
+
return this.#koniState.buyService.getBuyTokens();
|
|
3577
|
+
}
|
|
3578
|
+
async subscribeBuyServices(id, port) {
|
|
3579
|
+
const cb = createSubscription(id, port);
|
|
3580
|
+
let ready = false;
|
|
3581
|
+
const callback = rs => {
|
|
3582
|
+
if (ready) {
|
|
3583
|
+
cb(rs);
|
|
3584
|
+
}
|
|
3585
|
+
};
|
|
3586
|
+
const subscription = this.#koniState.buyService.subscribeBuyServices(callback);
|
|
3587
|
+
this.createUnsubscriptionHandle(id, subscription.unsubscribe);
|
|
3588
|
+
port.onDisconnect.addListener(() => {
|
|
3589
|
+
this.cancelSubscription(id);
|
|
3590
|
+
});
|
|
3591
|
+
await this.#koniState.eventService.waitBuyServiceReady;
|
|
3592
|
+
ready = true;
|
|
3593
|
+
return this.#koniState.buyService.getBuyServices();
|
|
3594
|
+
}
|
|
3595
|
+
|
|
3596
|
+
/* Buy service */
|
|
3597
|
+
|
|
3555
3598
|
// --------------------------------------------------------------
|
|
3556
3599
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
3557
3600
|
async handle(id, type, request, port) {
|
|
@@ -3995,6 +4038,13 @@ export default class KoniExtension {
|
|
|
3995
4038
|
case 'pri(campaign.banner.complete)':
|
|
3996
4039
|
return this.completeCampaignBanner(request);
|
|
3997
4040
|
/* Campaign */
|
|
4041
|
+
|
|
4042
|
+
/* Buy service */
|
|
4043
|
+
case 'pri(buyService.tokens.subscribe)':
|
|
4044
|
+
return this.subscribeBuyTokens(id, port);
|
|
4045
|
+
case 'pri(buyService.services.subscribe)':
|
|
4046
|
+
return this.subscribeBuyServices(id, port);
|
|
4047
|
+
/* Buy service */
|
|
3998
4048
|
// Default
|
|
3999
4049
|
default:
|
|
4000
4050
|
throw new Error(`Unable to handle message of type ${type}`);
|
|
@@ -3,6 +3,7 @@ import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _MultiChainAsset } from
|
|
|
3
3
|
import { AddTokenRequestExternal, AmountData, ApiMap, AuthRequestV2, BalanceItem, BalanceJson, ChainStakingMetadata, ConfirmationsQueue, CrowdloanItem, CrowdloanJson, CurrentAccountInfo, EvmSendTransactionParams, ExternalRequestPromise, MantaPayConfig, MantaPaySyncState, NftCollection, NftItem, NftJson, NominatorMetadata, RequestAccountExportPrivateKey, RequestCheckPublicAndSecretKey, RequestConfirmationComplete, RequestSettingsType, ResponseAccountExportPrivateKey, ResponseCheckPublicAndSecretKey, ServiceInfo, SingleModeJson, StakingItem, StakingJson, StakingRewardItem, StakingRewardJson, StakingType, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
4
|
import { AccountJson, RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestSign, ResponseRpcListProviders, ResponseSigning } from '@subwallet/extension-base/background/types';
|
|
5
5
|
import { BalanceService } from '@subwallet/extension-base/services/balance-service';
|
|
6
|
+
import BuyService from '@subwallet/extension-base/services/buy-service';
|
|
6
7
|
import CampaignService from '@subwallet/extension-base/services/campaign-service';
|
|
7
8
|
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
8
9
|
import { _ChainState, _NetworkUpsertParams, _ValidateCustomAssetRequest } from '@subwallet/extension-base/services/chain-service/types';
|
|
@@ -64,6 +65,7 @@ export default class KoniState {
|
|
|
64
65
|
readonly subscanService: SubscanService;
|
|
65
66
|
readonly walletConnectService: WalletConnectService;
|
|
66
67
|
readonly campaignService: CampaignService;
|
|
68
|
+
readonly buyService: BuyService;
|
|
67
69
|
private generalStatus;
|
|
68
70
|
private waitSleeping;
|
|
69
71
|
private waitStarting;
|
|
@@ -8,6 +8,7 @@ import { APIItemState, BasicTxErrorType, ChainType, EvmProviderErrorType, Extern
|
|
|
8
8
|
import { ALL_ACCOUNT_KEY, ALL_GENESIS_HASH, MANTA_PAY_BALANCE_INTERVAL } from '@subwallet/extension-base/constants';
|
|
9
9
|
import { BalanceService } from '@subwallet/extension-base/services/balance-service';
|
|
10
10
|
import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
|
|
11
|
+
import BuyService from '@subwallet/extension-base/services/buy-service';
|
|
11
12
|
import CampaignService from '@subwallet/extension-base/services/campaign-service';
|
|
12
13
|
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
13
14
|
import { _DEFAULT_MANTA_ZK_CHAIN, _MANTA_ZK_CHAIN_GROUP, _PREDEFINED_SINGLE_MODES } from '@subwallet/extension-base/services/chain-service/constants';
|
|
@@ -95,6 +96,7 @@ export default class KoniState {
|
|
|
95
96
|
this.walletConnectService = new WalletConnectService(this, this.requestService);
|
|
96
97
|
this.migrationService = new MigrationService(this, this.eventService);
|
|
97
98
|
this.campaignService = new CampaignService(this);
|
|
99
|
+
this.buyService = new BuyService(this);
|
|
98
100
|
this.subscription = new KoniSubscription(this, this.dbService);
|
|
99
101
|
this.cron = new KoniCron(this, this.subscription, this.dbService);
|
|
100
102
|
this.logger = createLogger('State');
|
|
@@ -204,6 +206,9 @@ export default class KoniState {
|
|
|
204
206
|
this.onReady();
|
|
205
207
|
this.onAccountAdd();
|
|
206
208
|
this.onAccountRemove();
|
|
209
|
+
|
|
210
|
+
// TODO: consider moving this to a separate service
|
|
211
|
+
await this.dbService.stores.crowdloan.removeEndedCrowdloans();
|
|
207
212
|
await this.startSubscription();
|
|
208
213
|
}
|
|
209
214
|
async initMantaPay(password) {
|
|
@@ -355,7 +360,8 @@ export default class KoniState {
|
|
|
355
360
|
return this.dbService.getAllNftCollection(this.activeChainSlugs);
|
|
356
361
|
}
|
|
357
362
|
subscribeNftCollection() {
|
|
358
|
-
|
|
363
|
+
const getChains = () => this.activeChainSlugs;
|
|
364
|
+
return this.dbService.stores.nftCollection.subscribeNftCollection(getChains);
|
|
359
365
|
}
|
|
360
366
|
resetNft(newAddress) {
|
|
361
367
|
this.getNft().then(data => this.nftSubject.next(data || {
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.1.
|
|
20
|
+
"version": "1.1.20-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -520,6 +520,26 @@
|
|
|
520
520
|
"require": "./cjs/services/base/types.js",
|
|
521
521
|
"default": "./services/base/types.js"
|
|
522
522
|
},
|
|
523
|
+
"./services/buy-service": {
|
|
524
|
+
"types": "./services/buy-service/index.d.ts",
|
|
525
|
+
"require": "./cjs/services/buy-service/index.js",
|
|
526
|
+
"default": "./services/buy-service/index.js"
|
|
527
|
+
},
|
|
528
|
+
"./services/buy-service/constants": {
|
|
529
|
+
"types": "./services/buy-service/constants/index.d.ts",
|
|
530
|
+
"require": "./cjs/services/buy-service/constants/index.js",
|
|
531
|
+
"default": "./services/buy-service/constants/index.js"
|
|
532
|
+
},
|
|
533
|
+
"./services/buy-service/constants/token": {
|
|
534
|
+
"types": "./services/buy-service/constants/token.d.ts",
|
|
535
|
+
"require": "./cjs/services/buy-service/constants/token.js",
|
|
536
|
+
"default": "./services/buy-service/constants/token.js"
|
|
537
|
+
},
|
|
538
|
+
"./services/buy-service/types": {
|
|
539
|
+
"types": "./services/buy-service/types.d.ts",
|
|
540
|
+
"require": "./cjs/services/buy-service/types.js",
|
|
541
|
+
"default": "./services/buy-service/types.js"
|
|
542
|
+
},
|
|
523
543
|
"./services/campaign-service": {
|
|
524
544
|
"types": "./services/campaign-service/index.d.ts",
|
|
525
545
|
"require": "./cjs/services/campaign-service/index.js",
|
|
@@ -1164,9 +1184,14 @@
|
|
|
1164
1184
|
"default": "./stores/TransactionHistoryV3.js"
|
|
1165
1185
|
},
|
|
1166
1186
|
"./types": {
|
|
1167
|
-
"types": "./types.d.ts",
|
|
1168
|
-
"require": "./cjs/types.js",
|
|
1169
|
-
"default": "./types.js"
|
|
1187
|
+
"types": "./types/index.d.ts",
|
|
1188
|
+
"require": "./cjs/types/index.js",
|
|
1189
|
+
"default": "./types/index.js"
|
|
1190
|
+
},
|
|
1191
|
+
"./types/buy": {
|
|
1192
|
+
"types": "./types/buy.d.ts",
|
|
1193
|
+
"require": "./cjs/types/buy.js",
|
|
1194
|
+
"default": "./types/buy.js"
|
|
1170
1195
|
},
|
|
1171
1196
|
"./utils": {
|
|
1172
1197
|
"types": "./utils/index.d.ts",
|
|
@@ -1213,6 +1238,11 @@
|
|
|
1213
1238
|
"require": "./cjs/utils/eth/parseTransaction/base.js",
|
|
1214
1239
|
"default": "./utils/eth/parseTransaction/base.js"
|
|
1215
1240
|
},
|
|
1241
|
+
"./utils/fetchStaticData": {
|
|
1242
|
+
"types": "./utils/fetchStaticData.d.ts",
|
|
1243
|
+
"require": "./cjs/utils/fetchStaticData.js",
|
|
1244
|
+
"default": "./utils/fetchStaticData.js"
|
|
1245
|
+
},
|
|
1216
1246
|
"./utils/getId": {
|
|
1217
1247
|
"types": "./utils/getId.d.ts",
|
|
1218
1248
|
"require": "./cjs/utils/getId.js",
|
|
@@ -1277,11 +1307,11 @@
|
|
|
1277
1307
|
"@reduxjs/toolkit": "^1.9.1",
|
|
1278
1308
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
1279
1309
|
"@substrate/connect": "^0.7.26",
|
|
1280
|
-
"@subwallet/chain-list": "0.2.
|
|
1281
|
-
"@subwallet/extension-base": "^1.1.
|
|
1282
|
-
"@subwallet/extension-chains": "^1.1.
|
|
1283
|
-
"@subwallet/extension-dapp": "^1.1.
|
|
1284
|
-
"@subwallet/extension-inject": "^1.1.
|
|
1310
|
+
"@subwallet/chain-list": "0.2.20-beta.5",
|
|
1311
|
+
"@subwallet/extension-base": "^1.1.20-0",
|
|
1312
|
+
"@subwallet/extension-chains": "^1.1.20-0",
|
|
1313
|
+
"@subwallet/extension-dapp": "^1.1.20-0",
|
|
1314
|
+
"@subwallet/extension-inject": "^1.1.20-0",
|
|
1285
1315
|
"@subwallet/keyring": "^0.1.1",
|
|
1286
1316
|
"@subwallet/ui-keyring": "^0.1.1",
|
|
1287
1317
|
"@walletconnect/sign-client": "^2.8.4",
|
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.1.
|
|
10
|
+
version: '1.1.20-0'
|
|
11
11
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './token';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
const DEFAULT_BUY_SERVICE = {
|
|
5
|
+
symbol: '',
|
|
6
|
+
network: ''
|
|
7
|
+
};
|
|
8
|
+
export const DEFAULT_SERVICE_INFO = {
|
|
9
|
+
transak: {
|
|
10
|
+
...DEFAULT_BUY_SERVICE
|
|
11
|
+
},
|
|
12
|
+
banxa: {
|
|
13
|
+
...DEFAULT_BUY_SERVICE
|
|
14
|
+
},
|
|
15
|
+
coinbase: {
|
|
16
|
+
...DEFAULT_BUY_SERVICE
|
|
17
|
+
},
|
|
18
|
+
onramper: {
|
|
19
|
+
...DEFAULT_BUY_SERVICE
|
|
20
|
+
},
|
|
21
|
+
moonpay: {
|
|
22
|
+
...DEFAULT_BUY_SERVICE
|
|
23
|
+
}
|
|
24
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
2
|
+
import { BuyServiceInfo, BuyTokenInfo } from '@subwallet/extension-base/types';
|
|
3
|
+
export default class BuyService {
|
|
4
|
+
#private;
|
|
5
|
+
private buyTokensSubject;
|
|
6
|
+
private buyServicesSubject;
|
|
7
|
+
constructor(state: KoniState);
|
|
8
|
+
private fetchTokens;
|
|
9
|
+
private fetchServices;
|
|
10
|
+
subscribeBuyTokens(callback: (data: Record<string, BuyTokenInfo>) => void): import("rxjs").Subscription;
|
|
11
|
+
getBuyTokens(): Record<string, BuyTokenInfo>;
|
|
12
|
+
subscribeBuyServices(callback: (data: Record<string, BuyServiceInfo>) => void): import("rxjs").Subscription;
|
|
13
|
+
getBuyServices(): Record<string, BuyServiceInfo>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { fetchStaticData } from '@subwallet/extension-base/utils/fetchStaticData';
|
|
5
|
+
import { BehaviorSubject } from 'rxjs';
|
|
6
|
+
import { DEFAULT_SERVICE_INFO } from "./constants/index.js";
|
|
7
|
+
export default class BuyService {
|
|
8
|
+
#state;
|
|
9
|
+
buyTokensSubject = new BehaviorSubject({});
|
|
10
|
+
buyServicesSubject = new BehaviorSubject({});
|
|
11
|
+
constructor(state) {
|
|
12
|
+
this.#state = state;
|
|
13
|
+
this.buyTokensSubject.next({});
|
|
14
|
+
this.buyServicesSubject.next({});
|
|
15
|
+
this.fetchTokens().catch(e => {
|
|
16
|
+
console.error('Error on fetch buy tokens', e);
|
|
17
|
+
this.#state.eventService.emit('buy.tokens.ready', true);
|
|
18
|
+
});
|
|
19
|
+
this.fetchServices().catch(e => {
|
|
20
|
+
console.error('Error on fetch buy services', e);
|
|
21
|
+
this.#state.eventService.emit('buy.services.ready', true);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async fetchTokens() {
|
|
25
|
+
const data = await fetchStaticData('buy-token-configs');
|
|
26
|
+
const result = {};
|
|
27
|
+
for (const datum of data) {
|
|
28
|
+
const temp = {
|
|
29
|
+
serviceInfo: {
|
|
30
|
+
...DEFAULT_SERVICE_INFO
|
|
31
|
+
},
|
|
32
|
+
support: datum.support,
|
|
33
|
+
services: [],
|
|
34
|
+
slug: datum.slug,
|
|
35
|
+
symbol: datum.symbol,
|
|
36
|
+
network: datum.network
|
|
37
|
+
};
|
|
38
|
+
for (const [_service, info] of Object.entries(datum.serviceInfo)) {
|
|
39
|
+
const service = _service;
|
|
40
|
+
if (info.isSuspended) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
temp.serviceInfo[service] = {
|
|
44
|
+
network: info.network,
|
|
45
|
+
symbol: info.symbol
|
|
46
|
+
};
|
|
47
|
+
temp.services.push(service);
|
|
48
|
+
}
|
|
49
|
+
if (temp.services.length) {
|
|
50
|
+
result[temp.slug] = temp;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
this.buyTokensSubject.next(result);
|
|
54
|
+
this.#state.eventService.emit('buy.tokens.ready', true);
|
|
55
|
+
}
|
|
56
|
+
async fetchServices() {
|
|
57
|
+
const data = await fetchStaticData('buy-service-infos');
|
|
58
|
+
const result = {};
|
|
59
|
+
for (const datum of data) {
|
|
60
|
+
const {
|
|
61
|
+
id,
|
|
62
|
+
slug,
|
|
63
|
+
...info
|
|
64
|
+
} = datum;
|
|
65
|
+
result[slug] = {
|
|
66
|
+
...info
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
this.buyServicesSubject.next(result);
|
|
70
|
+
this.#state.eventService.emit('buy.services.ready', true);
|
|
71
|
+
}
|
|
72
|
+
subscribeBuyTokens(callback) {
|
|
73
|
+
return this.buyTokensSubject.subscribe({
|
|
74
|
+
next: callback
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
getBuyTokens() {
|
|
78
|
+
return this.buyTokensSubject.getValue();
|
|
79
|
+
}
|
|
80
|
+
subscribeBuyServices(callback) {
|
|
81
|
+
return this.buyServicesSubject.subscribe({
|
|
82
|
+
next: callback
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
getBuyServices() {
|
|
86
|
+
return this.buyServicesSubject.getValue();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BuyService, BuyTokenInfo, SupportService } from '@subwallet/extension-base/types';
|
|
2
|
+
interface _BuyTokenInfo {
|
|
3
|
+
serviceInfo: Record<string, BuyService & {
|
|
4
|
+
isSuspended: boolean;
|
|
5
|
+
}>;
|
|
6
|
+
network: string;
|
|
7
|
+
slug: string;
|
|
8
|
+
symbol: string;
|
|
9
|
+
support: BuyTokenInfo['support'];
|
|
10
|
+
}
|
|
11
|
+
interface _BuyServiceInfo {
|
|
12
|
+
id: number;
|
|
13
|
+
name: string;
|
|
14
|
+
contactUrl: string;
|
|
15
|
+
termUrl: string;
|
|
16
|
+
policyUrl: string;
|
|
17
|
+
url: string;
|
|
18
|
+
slug: SupportService;
|
|
19
|
+
}
|
|
20
|
+
export declare type ListBuyTokenResponse = _BuyTokenInfo[];
|
|
21
|
+
export declare type ListBuyServicesResponse = _BuyServiceInfo[];
|
|
22
|
+
export {};
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { CampaignDataType } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
|
-
import { MARKETING_CAMPAIGN_URL } from '@subwallet/extension-base/constants';
|
|
6
5
|
import { TARGET_ENV } from '@subwallet/extension-base/utils';
|
|
7
|
-
import
|
|
6
|
+
import { fetchStaticData } from '@subwallet/extension-base/utils/fetchStaticData';
|
|
8
7
|
import { runCampaign } from "./helpers.js";
|
|
9
8
|
export default class CampaignService {
|
|
10
9
|
#state;
|
|
@@ -18,11 +17,7 @@ export default class CampaignService {
|
|
|
18
17
|
});
|
|
19
18
|
}
|
|
20
19
|
async fetchCampaign() {
|
|
21
|
-
const
|
|
22
|
-
method: 'GET',
|
|
23
|
-
url: MARKETING_CAMPAIGN_URL
|
|
24
|
-
});
|
|
25
|
-
const respData = response.data;
|
|
20
|
+
const respData = await fetchStaticData('marketing-campaigns');
|
|
26
21
|
const campaigns = [];
|
|
27
22
|
for (const data of respData) {
|
|
28
23
|
// eslint-disable-next-line camelcase
|
|
@@ -122,12 +122,14 @@ export class EvmChainHandler extends AbstractChainHandler {
|
|
|
122
122
|
} else {
|
|
123
123
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
|
|
124
124
|
tokenContract = new evmApi.api.eth.Contract(_ERC20_ABI, contractAddress);
|
|
125
|
-
const [_decimals, _symbol] = await Promise.all([
|
|
125
|
+
const [_decimals, _symbol, _name] = await Promise.all([
|
|
126
126
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
127
127
|
tokenContract.methods.decimals().call(),
|
|
128
128
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
129
|
-
tokenContract.methods.symbol().call()
|
|
130
|
-
|
|
129
|
+
tokenContract.methods.symbol().call(),
|
|
130
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
131
|
+
tokenContract.methods.name().call()]);
|
|
132
|
+
name = _name;
|
|
131
133
|
decimals = new BigN(_decimals).toNumber();
|
|
132
134
|
symbol = _symbol;
|
|
133
135
|
}
|
|
@@ -9,7 +9,7 @@ import { MantaPrivateHandler } from '@subwallet/extension-base/services/chain-se
|
|
|
9
9
|
import { SubstrateChainHandler } from '@subwallet/extension-base/services/chain-service/handler/SubstrateChainHandler';
|
|
10
10
|
import { _CHAIN_VALIDATION_ERROR } from '@subwallet/extension-base/services/chain-service/handler/types';
|
|
11
11
|
import { _ChainConnectionStatus, _CUSTOM_PREFIX, _NFT_CONTRACT_STANDARDS, _SMART_CONTRACT_STANDARDS } from '@subwallet/extension-base/services/chain-service/types';
|
|
12
|
-
import { _isAssetFungibleToken, _isChainEnabled, _isCustomAsset, _isCustomChain, _isEqualContractAddress, _isEqualSmartContractAsset, _isMantaZkAsset, _isPureEvmChain, _isPureSubstrateChain, _parseAssetRefKey } from '@subwallet/extension-base/services/chain-service/utils';
|
|
12
|
+
import { _isAssetFungibleToken, _isChainEnabled, _isCustomAsset, _isCustomChain, _isCustomProvider, _isEqualContractAddress, _isEqualSmartContractAsset, _isMantaZkAsset, _isPureEvmChain, _isPureSubstrateChain, _parseAssetRefKey } from '@subwallet/extension-base/services/chain-service/utils';
|
|
13
13
|
import AssetSettingStore from '@subwallet/extension-base/stores/AssetSetting';
|
|
14
14
|
import { MODULE_SUPPORT } from '@subwallet/extension-base/utils';
|
|
15
15
|
import { BehaviorSubject, Subject } from 'rxjs';
|
|
@@ -631,12 +631,34 @@ export class ChainService {
|
|
|
631
631
|
for (const [storedSlug, storedChainInfo] of Object.entries(storedChainSettingMap)) {
|
|
632
632
|
if (storedSlug in latestChainInfoMap) {
|
|
633
633
|
// check predefined chains first, keep setting for providers and currentProvider
|
|
634
|
-
|
|
635
|
-
|
|
634
|
+
// TODO: review merging providers
|
|
635
|
+
// Keep customer provider only
|
|
636
|
+
const providers = {
|
|
636
637
|
...mergedChainInfoMap[storedSlug].providers
|
|
637
|
-
};
|
|
638
|
+
};
|
|
639
|
+
for (const [key, value] of Object.entries(storedChainInfo.providers)) {
|
|
640
|
+
if (_isCustomProvider(key)) {
|
|
641
|
+
if (!Object.values(providers).includes(value)) {
|
|
642
|
+
providers[key] = value;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
mergedChainInfoMap[storedSlug].providers = providers;
|
|
647
|
+
|
|
648
|
+
// Merge current provider
|
|
649
|
+
let currentProvider = storedChainInfo.currentProvider;
|
|
650
|
+
const providerValue = storedChainInfo.providers[currentProvider] || '';
|
|
651
|
+
if (!providers[currentProvider]) {
|
|
652
|
+
currentProvider = Object.keys(providers)[0];
|
|
653
|
+
for (const [key, value] of Object.entries(providers)) {
|
|
654
|
+
if (providerValue === value) {
|
|
655
|
+
currentProvider = key;
|
|
656
|
+
break;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
638
660
|
this.dataMap.chainStateMap[storedSlug] = {
|
|
639
|
-
currentProvider:
|
|
661
|
+
currentProvider: currentProvider,
|
|
640
662
|
slug: storedSlug,
|
|
641
663
|
connectionStatus: _ChainConnectionStatus.DISCONNECTED,
|
|
642
664
|
active: storedChainInfo.active
|
|
@@ -644,7 +666,7 @@ export class ChainService {
|
|
|
644
666
|
newStorageData.push({
|
|
645
667
|
...mergedChainInfoMap[storedSlug],
|
|
646
668
|
active: storedChainInfo.active,
|
|
647
|
-
currentProvider:
|
|
669
|
+
currentProvider: currentProvider
|
|
648
670
|
});
|
|
649
671
|
} else {
|
|
650
672
|
var _storedChainInfo$subs, _storedChainInfo$evmI;
|
|
@@ -13,6 +13,8 @@ export declare class EventService extends EventEmitter<EventRegistry> {
|
|
|
13
13
|
readonly waitAssetReady: Promise<boolean>;
|
|
14
14
|
readonly waitMigrateReady: Promise<boolean>;
|
|
15
15
|
readonly waitCampaignReady: Promise<boolean>;
|
|
16
|
+
readonly waitBuyTokenReady: Promise<boolean>;
|
|
17
|
+
readonly waitBuyServiceReady: Promise<boolean>;
|
|
16
18
|
constructor(options?: {
|
|
17
19
|
lazyTime: number;
|
|
18
20
|
});
|
|
@@ -21,6 +21,8 @@ export class EventService extends EventEmitter {
|
|
|
21
21
|
this.waitAssetReady = this.generateWaitPromise('asset.ready');
|
|
22
22
|
this.waitMigrateReady = this.generateWaitPromise('migration.done');
|
|
23
23
|
this.waitCampaignReady = this.generateWaitPromise('campaign.ready');
|
|
24
|
+
this.waitBuyTokenReady = this.generateWaitPromise('buy.tokens.ready');
|
|
25
|
+
this.waitBuyServiceReady = this.generateWaitPromise('buy.services.ready');
|
|
24
26
|
}
|
|
25
27
|
generateWaitPromise(eventType) {
|
|
26
28
|
return new Promise(resolve => {
|
|
@@ -25,6 +25,8 @@ export interface EventRegistry {
|
|
|
25
25
|
'mantaPay.enable': [string];
|
|
26
26
|
'migration.done': [boolean];
|
|
27
27
|
'campaign.ready': [boolean];
|
|
28
|
+
'buy.tokens.ready': [boolean];
|
|
29
|
+
'buy.services.ready': [boolean];
|
|
28
30
|
}
|
|
29
31
|
export declare type EventType = keyof EventRegistry;
|
|
30
32
|
export declare const COMMON_RELOAD_EVENTS: EventType[];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import BaseStoreWithAddressAndChain from '@subwallet/extension-base/services/storage-service/db-stores/BaseStoreWithAddressAndChain';
|
|
2
2
|
import { ICrowdloanItem } from '../databases';
|
|
3
3
|
export default class CrowdloanStore extends BaseStoreWithAddressAndChain<ICrowdloanItem> {
|
|
4
|
+
removeEndedCrowdloans(): Promise<void>;
|
|
4
5
|
getCrowdloan(address: string): import("dexie").PromiseExtended<ICrowdloanItem[]>;
|
|
5
6
|
deleteByChainAndAddress(chain: string, address: string): import("dexie").PromiseExtended<number>;
|
|
6
7
|
}
|
|
@@ -3,6 +3,20 @@
|
|
|
3
3
|
|
|
4
4
|
import BaseStoreWithAddressAndChain from '@subwallet/extension-base/services/storage-service/db-stores/BaseStoreWithAddressAndChain';
|
|
5
5
|
export default class CrowdloanStore extends BaseStoreWithAddressAndChain {
|
|
6
|
+
async removeEndedCrowdloans() {
|
|
7
|
+
const now = new Date();
|
|
8
|
+
const removeList = [];
|
|
9
|
+
await this.table.each((obj, cursor) => {
|
|
10
|
+
try {
|
|
11
|
+
if (!obj.endTime || new Date(obj.endTime) < now) {
|
|
12
|
+
removeList.push(cursor.primaryKey);
|
|
13
|
+
}
|
|
14
|
+
} catch (e) {
|
|
15
|
+
console.error(e);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
await this.table.bulkDelete(removeList);
|
|
19
|
+
}
|
|
6
20
|
getCrowdloan(address) {
|
|
7
21
|
return this.table.where('address').equals(address).toArray();
|
|
8
22
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NftCollection } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
2
|
import BaseStoreWithChain from './BaseStoreWithChain';
|
|
3
3
|
export default class NftCollectionStore extends BaseStoreWithChain<NftCollection> {
|
|
4
|
-
subscribeNftCollection(
|
|
4
|
+
subscribeNftCollection(getChains: () => string[] | undefined): import("dexie").Observable<NftCollection[]>;
|
|
5
5
|
getNftCollection(chainList?: string[]): import("dexie").PromiseExtended<NftCollection[]>;
|
|
6
6
|
removeCollection(chain: string, collectionId: string): import("dexie").PromiseExtended<number>;
|
|
7
7
|
}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
import { liveQuery } from 'dexie';
|
|
5
5
|
import BaseStoreWithChain from "./BaseStoreWithChain.js";
|
|
6
6
|
export default class NftCollectionStore extends BaseStoreWithChain {
|
|
7
|
-
subscribeNftCollection(
|
|
8
|
-
return liveQuery(() => this.getNftCollection(
|
|
7
|
+
subscribeNftCollection(getChains) {
|
|
8
|
+
return liveQuery(() => this.getNftCollection(getChains()));
|
|
9
9
|
}
|
|
10
10
|
getNftCollection(chainList) {
|
|
11
11
|
if (chainList && chainList.length > 0) {
|
package/types/buy.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface BuyService {
|
|
2
|
+
network: string;
|
|
3
|
+
symbol: string;
|
|
4
|
+
}
|
|
5
|
+
export declare type SupportService = 'transak' | 'banxa' | 'coinbase' | 'moonpay' | 'onramper';
|
|
6
|
+
export interface BuyTokenInfo {
|
|
7
|
+
network: string;
|
|
8
|
+
symbol: string;
|
|
9
|
+
slug: string;
|
|
10
|
+
support: 'ETHEREUM' | 'SUBSTRATE';
|
|
11
|
+
services: Array<SupportService>;
|
|
12
|
+
serviceInfo: Record<SupportService, BuyService>;
|
|
13
|
+
}
|
|
14
|
+
export interface BuyServiceInfo {
|
|
15
|
+
name: string;
|
|
16
|
+
contactUrl: string;
|
|
17
|
+
termUrl: string;
|
|
18
|
+
policyUrl: string;
|
|
19
|
+
url: string;
|
|
20
|
+
}
|
package/types/buy.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/types/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function fetchStaticData<T>(slug: string, targetFile?: string): Promise<T>;
|