@subwallet/extension-base 1.1.19-0 → 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/xcm/xTokens.js +1 -1
- package/cjs/koni/background/handlers/Extension.js +46 -0
- package/cjs/koni/background/handlers/State.js +4 -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/event-service/index.js +2 -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/xcm/xTokens.js +1 -1
- package/koni/background/handlers/Extension.d.ts +2 -0
- package/koni/background/handlers/Extension.js +46 -0
- package/koni/background/handlers/State.d.ts +2 -0
- package/koni/background/handlers/State.js +4 -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/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/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
|
@@ -7,6 +7,7 @@ import { _CHAIN_VALIDATION_ERROR } from '@subwallet/extension-base/services/chai
|
|
|
7
7
|
import { _ChainState, _EvmApi, _NetworkUpsertParams, _SubstrateApi, _ValidateCustomAssetRequest, _ValidateCustomAssetResponse, EnableChainParams, EnableMultiChainParams } from '@subwallet/extension-base/services/chain-service/types';
|
|
8
8
|
import { SWTransactionResponse, SWTransactionResult } from '@subwallet/extension-base/services/transaction-service/types';
|
|
9
9
|
import { WalletConnectNotSupportRequest, WalletConnectSessionRequest } from '@subwallet/extension-base/services/wallet-connect-service/types';
|
|
10
|
+
import { BuyServiceInfo, BuyTokenInfo } from '@subwallet/extension-base/types';
|
|
10
11
|
import { InjectedAccount, InjectedAccountWithMeta, MetadataDefBase } from '@subwallet/extension-inject/types';
|
|
11
12
|
import { KeyringPair$Json, KeyringPair$Meta } from '@subwallet/keyring/types';
|
|
12
13
|
import { KeyringOptions } from '@subwallet/ui-keyring/options/types';
|
|
@@ -1786,6 +1787,8 @@ export interface KoniRequestSignatures {
|
|
|
1786
1787
|
'pri(metadata.find)': [RequestFindRawMetadata, ResponseFindRawMetadata];
|
|
1787
1788
|
'pri(campaign.banner.subscribe)': [null, CampaignBanner[], CampaignBanner[]];
|
|
1788
1789
|
'pri(campaign.banner.complete)': [RequestCampaignBannerComplete, boolean];
|
|
1790
|
+
'pri(buyService.tokens.subscribe)': [null, Record<string, BuyTokenInfo>, Record<string, BuyTokenInfo>];
|
|
1791
|
+
'pri(buyService.services.subscribe)': [null, Record<string, BuyServiceInfo>, Record<string, BuyServiceInfo>];
|
|
1789
1792
|
}
|
|
1790
1793
|
export interface ApplicationMetadataType {
|
|
1791
1794
|
version: string;
|
package/cjs/constants/index.js
CHANGED
|
@@ -25,10 +25,9 @@ var _exportNames = {
|
|
|
25
25
|
ALL_GENESIS_HASH: true,
|
|
26
26
|
IGNORE_GET_SUBSTRATE_FEATURES_LIST: true,
|
|
27
27
|
IGNORE_QR_SIGNER: true,
|
|
28
|
-
XCM_MIN_AMOUNT_RATIO: true
|
|
29
|
-
MARKETING_CAMPAIGN_URL: true
|
|
28
|
+
XCM_MIN_AMOUNT_RATIO: true
|
|
30
29
|
};
|
|
31
|
-
exports.XCM_MIN_AMOUNT_RATIO = exports.SUB_TOKEN_REFRESH_BALANCE_INTERVAL = exports.
|
|
30
|
+
exports.XCM_MIN_AMOUNT_RATIO = exports.SUB_TOKEN_REFRESH_BALANCE_INTERVAL = exports.MANTA_PAY_BALANCE_INTERVAL = exports.IGNORE_QR_SIGNER = exports.IGNORE_GET_SUBSTRATE_FEATURES_LIST = exports.CRON_SYNC_MANTA_PAY = exports.CRON_REFRESH_STAKING_REWARD_INTERVAL = exports.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = exports.CRON_REFRESH_PRICE_INTERVAL = exports.CRON_REFRESH_NFT_INTERVAL = exports.CRON_REFRESH_HISTORY_INTERVAL = exports.CRON_REFRESH_CHAIN_STAKING_METADATA = exports.CRON_REFRESH_CHAIN_NOMINATOR_METADATA = exports.CRON_RECOVER_HISTORY_INTERVAL = exports.CRON_GET_API_MAP_STATUS = exports.CRON_AUTO_RECOVER_WEB3_INTERVAL = exports.CRON_AUTO_RECOVER_DOTSAMA_INTERVAL = exports.ASTAR_REFRESH_BALANCE_INTERVAL = exports.ALL_NETWORK_KEY = exports.ALL_GENESIS_HASH = exports.ALL_ACCOUNT_KEY = exports.ACALA_REFRESH_CROWDLOAN_INTERVAL = void 0;
|
|
32
31
|
var _staking = require("./staking");
|
|
33
32
|
Object.keys(_staking).forEach(function (key) {
|
|
34
33
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -99,6 +98,4 @@ exports.IGNORE_GET_SUBSTRATE_FEATURES_LIST = IGNORE_GET_SUBSTRATE_FEATURES_LIST;
|
|
|
99
98
|
const IGNORE_QR_SIGNER = [];
|
|
100
99
|
exports.IGNORE_QR_SIGNER = IGNORE_QR_SIGNER;
|
|
101
100
|
const XCM_MIN_AMOUNT_RATIO = 1.2;
|
|
102
|
-
exports.XCM_MIN_AMOUNT_RATIO = XCM_MIN_AMOUNT_RATIO;
|
|
103
|
-
const MARKETING_CAMPAIGN_URL = process.env.MARKETING_CAMPAIGN_URL || '';
|
|
104
|
-
exports.MARKETING_CAMPAIGN_URL = MARKETING_CAMPAIGN_URL;
|
|
101
|
+
exports.XCM_MIN_AMOUNT_RATIO = XCM_MIN_AMOUNT_RATIO;
|
|
@@ -12,6 +12,7 @@ var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
|
12
12
|
var _constants = require("@subwallet/extension-base/constants");
|
|
13
13
|
var _typeRegistry = _interopRequireDefault(require("@subwallet/extension-base/koni/api/dotsama/typeRegistry"));
|
|
14
14
|
var _utils = require("@subwallet/extension-base/utils");
|
|
15
|
+
var _fetchStaticData = require("@subwallet/extension-base/utils/fetchStaticData");
|
|
15
16
|
var _axios = _interopRequireDefault(require("axios"));
|
|
16
17
|
var _util = require("@polkadot/util");
|
|
17
18
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
@@ -23,10 +24,7 @@ const STATUS_MAP = {
|
|
|
23
24
|
[_types._FundStatus.FAILED]: _KoniTypes.CrowdloanParaState.FAILED,
|
|
24
25
|
[_types._FundStatus.WON]: _KoniTypes.CrowdloanParaState.COMPLETED
|
|
25
26
|
};
|
|
26
|
-
const getOnlineFundList = (
|
|
27
|
-
const request = await _axios.default.get('https://static-data.subwallet.app/crowdloan-funds/list.json');
|
|
28
|
-
return request.data;
|
|
29
|
-
})();
|
|
27
|
+
const getOnlineFundList = (0, _fetchStaticData.fetchStaticData)('crowdloan-funds');
|
|
30
28
|
function getRPCCrowdloan(parentAPI, fundInfo, hexAddresses, callback) {
|
|
31
29
|
const {
|
|
32
30
|
auctionIndex,
|
|
@@ -25,6 +25,6 @@ function getCurrencyId(tokenInfo) {
|
|
|
25
25
|
}
|
|
26
26
|
function getExtrinsicByXtokensPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
27
27
|
const weightParam = ['pioneer'].includes(originChainInfo.slug) ? _utils.FOUR_INSTRUCTIONS_WEIGHT : (0, _utils.getDestWeight)();
|
|
28
|
-
const destVersion = ['moonbeam', 'moonriver', 'bifrost_dot', 'interlay', 'hydradx_main', 'acala'].includes(originChainInfo.slug) ? 'V3' : undefined;
|
|
28
|
+
const destVersion = ['moonbeam', 'moonriver', 'bifrost_dot', 'interlay', 'hydradx_main', 'acala', 'parallel'].includes(originChainInfo.slug) ? 'V3' : undefined;
|
|
29
29
|
return api.tx.xTokens.transfer(getCurrencyId(tokenInfo), value, (0, _utils.getDestMultilocation)(destinationChainInfo, recipientAddress, destVersion), weightParam);
|
|
30
30
|
}
|
|
@@ -3657,6 +3657,45 @@ class KoniExtension {
|
|
|
3657
3657
|
|
|
3658
3658
|
/* Campaign */
|
|
3659
3659
|
|
|
3660
|
+
/* Buy service */
|
|
3661
|
+
|
|
3662
|
+
async subscribeBuyTokens(id, port) {
|
|
3663
|
+
const cb = (0, _subscriptions.createSubscription)(id, port);
|
|
3664
|
+
let ready = false;
|
|
3665
|
+
const callback = rs => {
|
|
3666
|
+
if (ready) {
|
|
3667
|
+
cb(rs);
|
|
3668
|
+
}
|
|
3669
|
+
};
|
|
3670
|
+
const subscription = this.#koniState.buyService.subscribeBuyTokens(callback);
|
|
3671
|
+
this.createUnsubscriptionHandle(id, subscription.unsubscribe);
|
|
3672
|
+
port.onDisconnect.addListener(() => {
|
|
3673
|
+
this.cancelSubscription(id);
|
|
3674
|
+
});
|
|
3675
|
+
await this.#koniState.eventService.waitBuyTokenReady;
|
|
3676
|
+
ready = true;
|
|
3677
|
+
return this.#koniState.buyService.getBuyTokens();
|
|
3678
|
+
}
|
|
3679
|
+
async subscribeBuyServices(id, port) {
|
|
3680
|
+
const cb = (0, _subscriptions.createSubscription)(id, port);
|
|
3681
|
+
let ready = false;
|
|
3682
|
+
const callback = rs => {
|
|
3683
|
+
if (ready) {
|
|
3684
|
+
cb(rs);
|
|
3685
|
+
}
|
|
3686
|
+
};
|
|
3687
|
+
const subscription = this.#koniState.buyService.subscribeBuyServices(callback);
|
|
3688
|
+
this.createUnsubscriptionHandle(id, subscription.unsubscribe);
|
|
3689
|
+
port.onDisconnect.addListener(() => {
|
|
3690
|
+
this.cancelSubscription(id);
|
|
3691
|
+
});
|
|
3692
|
+
await this.#koniState.eventService.waitBuyServiceReady;
|
|
3693
|
+
ready = true;
|
|
3694
|
+
return this.#koniState.buyService.getBuyServices();
|
|
3695
|
+
}
|
|
3696
|
+
|
|
3697
|
+
/* Buy service */
|
|
3698
|
+
|
|
3660
3699
|
// --------------------------------------------------------------
|
|
3661
3700
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
3662
3701
|
async handle(id, type, request, port) {
|
|
@@ -4100,6 +4139,13 @@ class KoniExtension {
|
|
|
4100
4139
|
case 'pri(campaign.banner.complete)':
|
|
4101
4140
|
return this.completeCampaignBanner(request);
|
|
4102
4141
|
/* Campaign */
|
|
4142
|
+
|
|
4143
|
+
/* Buy service */
|
|
4144
|
+
case 'pri(buyService.tokens.subscribe)':
|
|
4145
|
+
return this.subscribeBuyTokens(id, port);
|
|
4146
|
+
case 'pri(buyService.services.subscribe)':
|
|
4147
|
+
return this.subscribeBuyServices(id, port);
|
|
4148
|
+
/* Buy service */
|
|
4103
4149
|
// Default
|
|
4104
4150
|
default:
|
|
4105
4151
|
throw new Error(`Unable to handle message of type ${type}`);
|
|
@@ -12,6 +12,7 @@ var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
|
12
12
|
var _constants = require("@subwallet/extension-base/constants");
|
|
13
13
|
var _balanceService = require("@subwallet/extension-base/services/balance-service");
|
|
14
14
|
var _types = require("@subwallet/extension-base/services/base/types");
|
|
15
|
+
var _buyService = _interopRequireDefault(require("@subwallet/extension-base/services/buy-service"));
|
|
15
16
|
var _campaignService = _interopRequireDefault(require("@subwallet/extension-base/services/campaign-service"));
|
|
16
17
|
var _chainService = require("@subwallet/extension-base/services/chain-service");
|
|
17
18
|
var _constants2 = require("@subwallet/extension-base/services/chain-service/constants");
|
|
@@ -102,6 +103,7 @@ class KoniState {
|
|
|
102
103
|
this.walletConnectService = new _walletConnectService.default(this, this.requestService);
|
|
103
104
|
this.migrationService = new _migrationService.default(this, this.eventService);
|
|
104
105
|
this.campaignService = new _campaignService.default(this);
|
|
106
|
+
this.buyService = new _buyService.default(this);
|
|
105
107
|
this.subscription = new _subscription.KoniSubscription(this, this.dbService);
|
|
106
108
|
this.cron = new _cron.KoniCron(this, this.subscription, this.dbService);
|
|
107
109
|
this.logger = (0, _util.logger)('State');
|
|
@@ -369,7 +371,8 @@ class KoniState {
|
|
|
369
371
|
return this.dbService.getAllNftCollection(this.activeChainSlugs);
|
|
370
372
|
}
|
|
371
373
|
subscribeNftCollection() {
|
|
372
|
-
|
|
374
|
+
const getChains = () => this.activeChainSlugs;
|
|
375
|
+
return this.dbService.stores.nftCollection.subscribeNftCollection(getChains);
|
|
373
376
|
}
|
|
374
377
|
resetNft(newAddress) {
|
|
375
378
|
this.getNft().then(data => this.nftSubject.next(data || {
|
package/cjs/packageInfo.js
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _token = require("./token");
|
|
7
|
+
Object.keys(_token).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _token[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _token[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DEFAULT_SERVICE_INFO = void 0;
|
|
7
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
8
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
|
|
10
|
+
const DEFAULT_BUY_SERVICE = {
|
|
11
|
+
symbol: '',
|
|
12
|
+
network: ''
|
|
13
|
+
};
|
|
14
|
+
const DEFAULT_SERVICE_INFO = {
|
|
15
|
+
transak: {
|
|
16
|
+
...DEFAULT_BUY_SERVICE
|
|
17
|
+
},
|
|
18
|
+
banxa: {
|
|
19
|
+
...DEFAULT_BUY_SERVICE
|
|
20
|
+
},
|
|
21
|
+
coinbase: {
|
|
22
|
+
...DEFAULT_BUY_SERVICE
|
|
23
|
+
},
|
|
24
|
+
onramper: {
|
|
25
|
+
...DEFAULT_BUY_SERVICE
|
|
26
|
+
},
|
|
27
|
+
moonpay: {
|
|
28
|
+
...DEFAULT_BUY_SERVICE
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
exports.DEFAULT_SERVICE_INFO = DEFAULT_SERVICE_INFO;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _fetchStaticData = require("@subwallet/extension-base/utils/fetchStaticData");
|
|
8
|
+
var _rxjs = require("rxjs");
|
|
9
|
+
var _constants = require("./constants");
|
|
10
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
11
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
+
|
|
13
|
+
class BuyService {
|
|
14
|
+
#state;
|
|
15
|
+
buyTokensSubject = new _rxjs.BehaviorSubject({});
|
|
16
|
+
buyServicesSubject = new _rxjs.BehaviorSubject({});
|
|
17
|
+
constructor(state) {
|
|
18
|
+
this.#state = state;
|
|
19
|
+
this.buyTokensSubject.next({});
|
|
20
|
+
this.buyServicesSubject.next({});
|
|
21
|
+
this.fetchTokens().catch(e => {
|
|
22
|
+
console.error('Error on fetch buy tokens', e);
|
|
23
|
+
this.#state.eventService.emit('buy.tokens.ready', true);
|
|
24
|
+
});
|
|
25
|
+
this.fetchServices().catch(e => {
|
|
26
|
+
console.error('Error on fetch buy services', e);
|
|
27
|
+
this.#state.eventService.emit('buy.services.ready', true);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async fetchTokens() {
|
|
31
|
+
const data = await (0, _fetchStaticData.fetchStaticData)('buy-token-configs');
|
|
32
|
+
const result = {};
|
|
33
|
+
for (const datum of data) {
|
|
34
|
+
const temp = {
|
|
35
|
+
serviceInfo: {
|
|
36
|
+
..._constants.DEFAULT_SERVICE_INFO
|
|
37
|
+
},
|
|
38
|
+
support: datum.support,
|
|
39
|
+
services: [],
|
|
40
|
+
slug: datum.slug,
|
|
41
|
+
symbol: datum.symbol,
|
|
42
|
+
network: datum.network
|
|
43
|
+
};
|
|
44
|
+
for (const [_service, info] of Object.entries(datum.serviceInfo)) {
|
|
45
|
+
const service = _service;
|
|
46
|
+
if (info.isSuspended) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
temp.serviceInfo[service] = {
|
|
50
|
+
network: info.network,
|
|
51
|
+
symbol: info.symbol
|
|
52
|
+
};
|
|
53
|
+
temp.services.push(service);
|
|
54
|
+
}
|
|
55
|
+
if (temp.services.length) {
|
|
56
|
+
result[temp.slug] = temp;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
this.buyTokensSubject.next(result);
|
|
60
|
+
this.#state.eventService.emit('buy.tokens.ready', true);
|
|
61
|
+
}
|
|
62
|
+
async fetchServices() {
|
|
63
|
+
const data = await (0, _fetchStaticData.fetchStaticData)('buy-service-infos');
|
|
64
|
+
const result = {};
|
|
65
|
+
for (const datum of data) {
|
|
66
|
+
const {
|
|
67
|
+
id,
|
|
68
|
+
slug,
|
|
69
|
+
...info
|
|
70
|
+
} = datum;
|
|
71
|
+
result[slug] = {
|
|
72
|
+
...info
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
this.buyServicesSubject.next(result);
|
|
76
|
+
this.#state.eventService.emit('buy.services.ready', true);
|
|
77
|
+
}
|
|
78
|
+
subscribeBuyTokens(callback) {
|
|
79
|
+
return this.buyTokensSubject.subscribe({
|
|
80
|
+
next: callback
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
getBuyTokens() {
|
|
84
|
+
return this.buyTokensSubject.getValue();
|
|
85
|
+
}
|
|
86
|
+
subscribeBuyServices(callback) {
|
|
87
|
+
return this.buyServicesSubject.subscribe({
|
|
88
|
+
next: callback
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
getBuyServices() {
|
|
92
|
+
return this.buyServicesSubject.getValue();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.default = BuyService;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.default = void 0;
|
|
8
7
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
9
|
-
var _constants = require("@subwallet/extension-base/constants");
|
|
10
8
|
var _utils = require("@subwallet/extension-base/utils");
|
|
11
|
-
var
|
|
9
|
+
var _fetchStaticData = require("@subwallet/extension-base/utils/fetchStaticData");
|
|
12
10
|
var _helpers = require("./helpers");
|
|
13
11
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
14
12
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -25,11 +23,7 @@ class CampaignService {
|
|
|
25
23
|
});
|
|
26
24
|
}
|
|
27
25
|
async fetchCampaign() {
|
|
28
|
-
const
|
|
29
|
-
method: 'GET',
|
|
30
|
-
url: _constants.MARKETING_CAMPAIGN_URL
|
|
31
|
-
});
|
|
32
|
-
const respData = response.data;
|
|
26
|
+
const respData = await (0, _fetchStaticData.fetchStaticData)('marketing-campaigns');
|
|
33
27
|
const campaigns = [];
|
|
34
28
|
for (const data of respData) {
|
|
35
29
|
// eslint-disable-next-line camelcase
|
|
@@ -130,12 +130,14 @@ class EvmChainHandler extends _AbstractChainHandler.AbstractChainHandler {
|
|
|
130
130
|
} else {
|
|
131
131
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
|
|
132
132
|
tokenContract = new evmApi.api.eth.Contract(_helper._ERC20_ABI, contractAddress);
|
|
133
|
-
const [_decimals, _symbol] = await Promise.all([
|
|
133
|
+
const [_decimals, _symbol, _name] = await Promise.all([
|
|
134
134
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
135
135
|
tokenContract.methods.decimals().call(),
|
|
136
136
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
137
|
-
tokenContract.methods.symbol().call()
|
|
138
|
-
|
|
137
|
+
tokenContract.methods.symbol().call(),
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
139
|
+
tokenContract.methods.name().call()]);
|
|
140
|
+
name = _name;
|
|
139
141
|
decimals = new _bignumber.default(_decimals).toNumber();
|
|
140
142
|
symbol = _symbol;
|
|
141
143
|
}
|
|
@@ -29,6 +29,8 @@ class EventService extends _eventemitter.default {
|
|
|
29
29
|
this.waitAssetReady = this.generateWaitPromise('asset.ready');
|
|
30
30
|
this.waitMigrateReady = this.generateWaitPromise('migration.done');
|
|
31
31
|
this.waitCampaignReady = this.generateWaitPromise('campaign.ready');
|
|
32
|
+
this.waitBuyTokenReady = this.generateWaitPromise('buy.tokens.ready');
|
|
33
|
+
this.waitBuyServiceReady = this.generateWaitPromise('buy.services.ready');
|
|
32
34
|
}
|
|
33
35
|
generateWaitPromise(eventType) {
|
|
34
36
|
return new Promise(resolve => {
|
|
@@ -11,8 +11,8 @@ var _BaseStoreWithChain = _interopRequireDefault(require("./BaseStoreWithChain")
|
|
|
11
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
12
12
|
|
|
13
13
|
class NftCollectionStore extends _BaseStoreWithChain.default {
|
|
14
|
-
subscribeNftCollection(
|
|
15
|
-
return (0, _dexie.liveQuery)(() => this.getNftCollection(
|
|
14
|
+
subscribeNftCollection(getChains) {
|
|
15
|
+
return (0, _dexie.liveQuery)(() => this.getNftCollection(getChains()));
|
|
16
16
|
}
|
|
17
17
|
getNftCollection(chainList) {
|
|
18
18
|
if (chainList && chainList.length > 0) {
|
package/cjs/types/buy.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _buy = require("./buy");
|
|
7
|
+
Object.keys(_buy).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _buy[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _buy[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.fetchStaticData = fetchStaticData;
|
|
8
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
9
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
10
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
11
|
+
|
|
12
|
+
const branchName = process.env.BRANCH_NAME || 'koni-dev';
|
|
13
|
+
const fetchTarget = branchName === 'master' || branchName === 'webapp' ? 'list.json' : 'preview.json';
|
|
14
|
+
async function fetchStaticData(slug, targetFile) {
|
|
15
|
+
const fetchFile = targetFile || fetchTarget;
|
|
16
|
+
const rs = await _axios.default.get(`https://static-data.subwallet.app/${slug}/${fetchFile}`);
|
|
17
|
+
return rs.data;
|
|
18
|
+
}
|
package/constants/index.d.ts
CHANGED
|
@@ -20,6 +20,5 @@ export declare const ALL_GENESIS_HASH: null;
|
|
|
20
20
|
export declare const IGNORE_GET_SUBSTRATE_FEATURES_LIST: string[];
|
|
21
21
|
export declare const IGNORE_QR_SIGNER: string[];
|
|
22
22
|
export declare const XCM_MIN_AMOUNT_RATIO = 1.2;
|
|
23
|
-
export declare const MARKETING_CAMPAIGN_URL: string;
|
|
24
23
|
export * from './staking';
|
|
25
24
|
export * from './storage';
|
package/constants/index.js
CHANGED
|
@@ -23,6 +23,5 @@ export const ALL_GENESIS_HASH = null;
|
|
|
23
23
|
export const IGNORE_GET_SUBSTRATE_FEATURES_LIST = ['astarEvm', 'ethereum', 'ethereum_goerli', 'binance', 'binance_test', 'boba_rinkeby', 'boba', 'bobabase', 'bobabeam'];
|
|
24
24
|
export const IGNORE_QR_SIGNER = [];
|
|
25
25
|
export const XCM_MIN_AMOUNT_RATIO = 1.2;
|
|
26
|
-
export const MARKETING_CAMPAIGN_URL = process.env.MARKETING_CAMPAIGN_URL || '';
|
|
27
26
|
export * from "./staking.js";
|
|
28
27
|
export * from "./storage.js";
|
|
@@ -7,6 +7,7 @@ import { APIItemState, CrowdloanParaState } from '@subwallet/extension-base/back
|
|
|
7
7
|
import { ACALA_REFRESH_CROWDLOAN_INTERVAL } from '@subwallet/extension-base/constants';
|
|
8
8
|
import registry from '@subwallet/extension-base/koni/api/dotsama/typeRegistry';
|
|
9
9
|
import { categoryAddresses, reformatAddress } from '@subwallet/extension-base/utils';
|
|
10
|
+
import { fetchStaticData } from '@subwallet/extension-base/utils/fetchStaticData';
|
|
10
11
|
import axios from 'axios';
|
|
11
12
|
import { BN } from '@polkadot/util';
|
|
12
13
|
const STATUS_MAP = {
|
|
@@ -15,10 +16,7 @@ const STATUS_MAP = {
|
|
|
15
16
|
[_FundStatus.FAILED]: CrowdloanParaState.FAILED,
|
|
16
17
|
[_FundStatus.WON]: CrowdloanParaState.COMPLETED
|
|
17
18
|
};
|
|
18
|
-
const getOnlineFundList = (
|
|
19
|
-
const request = await axios.get('https://static-data.subwallet.app/crowdloan-funds/list.json');
|
|
20
|
-
return request.data;
|
|
21
|
-
})();
|
|
19
|
+
const getOnlineFundList = fetchStaticData('crowdloan-funds');
|
|
22
20
|
function getRPCCrowdloan(parentAPI, fundInfo, hexAddresses, callback) {
|
|
23
21
|
const {
|
|
24
22
|
auctionIndex,
|
package/koni/api/xcm/xTokens.js
CHANGED
|
@@ -19,6 +19,6 @@ function getCurrencyId(tokenInfo) {
|
|
|
19
19
|
}
|
|
20
20
|
export function getExtrinsicByXtokensPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
21
21
|
const weightParam = ['pioneer'].includes(originChainInfo.slug) ? FOUR_INSTRUCTIONS_WEIGHT : getDestWeight();
|
|
22
|
-
const destVersion = ['moonbeam', 'moonriver', 'bifrost_dot', 'interlay', 'hydradx_main', 'acala'].includes(originChainInfo.slug) ? 'V3' : undefined;
|
|
22
|
+
const destVersion = ['moonbeam', 'moonriver', 'bifrost_dot', 'interlay', 'hydradx_main', 'acala', 'parallel'].includes(originChainInfo.slug) ? 'V3' : undefined;
|
|
23
23
|
return api.tx.xTokens.transfer(getCurrencyId(tokenInfo), value, getDestMultilocation(destinationChainInfo, recipientAddress, destVersion), weightParam);
|
|
24
24
|
}
|
|
@@ -215,5 +215,7 @@ export default class KoniExtension {
|
|
|
215
215
|
private removeInjects;
|
|
216
216
|
private subscribeProcessingBanner;
|
|
217
217
|
private completeCampaignBanner;
|
|
218
|
+
private subscribeBuyTokens;
|
|
219
|
+
private subscribeBuyServices;
|
|
218
220
|
handle<TMessageType extends MessageTypes>(id: string, type: TMessageType, request: RequestTypes[TMessageType], port: chrome.runtime.Port): Promise<ResponseType<TMessageType>>;
|
|
219
221
|
}
|
|
@@ -3556,6 +3556,45 @@ export default class KoniExtension {
|
|
|
3556
3556
|
|
|
3557
3557
|
/* Campaign */
|
|
3558
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
|
+
|
|
3559
3598
|
// --------------------------------------------------------------
|
|
3560
3599
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
3561
3600
|
async handle(id, type, request, port) {
|
|
@@ -3999,6 +4038,13 @@ export default class KoniExtension {
|
|
|
3999
4038
|
case 'pri(campaign.banner.complete)':
|
|
4000
4039
|
return this.completeCampaignBanner(request);
|
|
4001
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 */
|
|
4002
4048
|
// Default
|
|
4003
4049
|
default:
|
|
4004
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');
|
|
@@ -358,7 +360,8 @@ export default class KoniState {
|
|
|
358
360
|
return this.dbService.getAllNftCollection(this.activeChainSlugs);
|
|
359
361
|
}
|
|
360
362
|
subscribeNftCollection() {
|
|
361
|
-
|
|
363
|
+
const getChains = () => this.activeChainSlugs;
|
|
364
|
+
return this.dbService.stores.nftCollection.subscribeNftCollection(getChains);
|
|
362
365
|
}
|
|
363
366
|
resetNft(newAddress) {
|
|
364
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
|
}
|
|
@@ -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,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>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import axios from 'axios';
|
|
5
|
+
const branchName = process.env.BRANCH_NAME || 'koni-dev';
|
|
6
|
+
const fetchTarget = branchName === 'master' || branchName === 'webapp' ? 'list.json' : 'preview.json';
|
|
7
|
+
export async function fetchStaticData(slug, targetFile) {
|
|
8
|
+
const fetchFile = targetFile || fetchTarget;
|
|
9
|
+
const rs = await axios.get(`https://static-data.subwallet.app/${slug}/${fetchFile}`);
|
|
10
|
+
return rs.data;
|
|
11
|
+
}
|
|
File without changes
|
|
File without changes
|