Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

Commit

Permalink
Performance improvement. (Temporary) issue #22
Browse files Browse the repository at this point in the history
  • Loading branch information
CieloChiara committed May 17, 2022
1 parent 84b9378 commit dbd0cca
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 80 deletions.
1 change: 1 addition & 0 deletions packages/extension-base/src/background/KoniTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export interface NetWorkInfo {
nativeToken?: string;
crowdloanUrl?: string;
decimals?: number;
isSubscribe?: boolean;
}

export interface DonateInfo {
Expand Down
13 changes: 4 additions & 9 deletions packages/extension-koni-base/build-cjs/api/dotsama/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,28 +180,23 @@ function initApi(networkKey, apiUrl) {

};
api.on('connected', () => {
console.log('DotSamaAPI connected to', apiUrl);
console.log('Arth DotSamaAPI connected to', apiUrl);
result.apiRetry = 0;

if (result.isApiReadyOnce) {
result.isApiReady = true;
}

result.isApiConnected = true;
});
api.on('disconnected', () => {
result.isApiConnected = false;
result.isApiReady = false;
result.apiRetry = (result.apiRetry || 0) + 1;
console.log(`DotSamaAPI disconnected from ${JSON.stringify(apiUrl)} ${JSON.stringify(result.apiRetry)} times`);
console.log(`Arth DotSamaAPI disconnected from ${JSON.stringify(apiUrl)} ${JSON.stringify(result.apiRetry)} times`);

if (result.apiRetry > _constants.DOTSAMA_MAX_CONTINUE_RETRY) {
console.log(`Discontinue to use ${JSON.stringify(apiUrl)} because max retry`);
console.log(`Arth Discontinue to use ${JSON.stringify(apiUrl)} because max retry`);
provider.disconnect().then(console.log).catch(console.error);
}
});
api.on('ready', () => {
console.log('DotSamaAPI ready with', apiUrl);
console.log('Arth DotSamaAPI ready with', apiUrl);
loadOnReady(registry, api).then(rs => {
(0, _util.objectSpread)(result, rs);
}).catch(error => {
Expand Down
15 changes: 10 additions & 5 deletions packages/extension-koni-base/build-cjs/api/dotsama/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,19 @@ function connectDotSamaApis() {
let networks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _endpoints.default;
const apisMap = {};
Object.keys(networks).forEach(networkKey => {
const network = networks[networkKey];
//console.log('Arth networkKey: ', networkKey);
//console.log('Arth networks[networkKey].isSubscribe: ', networks[networkKey].isSubscribe);
if (networks[networkKey].isSubscribe) {
const network = networks[networkKey]; //console.log('Arth networks: ', networks);

if (!network.genesisHash || network.genesisHash.toLowerCase() === 'unknown' || !network.provider) {
return;
}
if (!network.genesisHash || network.genesisHash.toLowerCase() === 'unknown' || !network.provider) {
return;
}

apisMap[networkKey] = (0, _api.initApi)(networkKey, network.provider);
apisMap[networkKey] = (0, _api.initApi)(networkKey, network.provider);
}
});
console.log('Arth apisMap: ', apisMap);
return apisMap;
}

Expand Down
18 changes: 12 additions & 6 deletions packages/extension-koni-base/build-cjs/api/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const NETWORKS = {
provider: 'wss://polkadot.api.onfinality.io/public-ws',
groups: ['RELAY_CHAIN'],
nativeToken: 'DOT',
decimals: 10
decimals: 10,
isSubscribe: true
},
kusama: {
chain: 'Kusama Relay Chain',
Expand All @@ -28,7 +29,8 @@ const NETWORKS = {
provider: 'wss://kusama.api.onfinality.io/public-ws',
groups: ['RELAY_CHAIN'],
nativeToken: 'KSM',
decimals: 12
decimals: 12,
isSubscribe: true
},
westend: {
chain: 'Westend Relay Chain',
Expand Down Expand Up @@ -99,7 +101,8 @@ const NETWORKS = {
paraId: 2006,
nativeToken: 'ASTR',
crowdloanUrl: 'https://crowdloan.astar.network/#/',
decimals: 18
decimals: 18,
isSubscribe: true
},
astarEvm: {
chain: 'Astar - EVM',
Expand All @@ -111,7 +114,8 @@ const NETWORKS = {
groups: ['POLKADOT_PARACHAIN', 'ASTAR_MAINNET'],
isEthereum: true,
nativeToken: 'ASTR',
decimals: 18
decimals: 18,
isSubscribe: true
},
parallel: {
chain: 'Parallel',
Expand Down Expand Up @@ -392,7 +396,8 @@ const NETWORKS = {
groups: ['KUSAMA_PARACHAIN'],
paraId: 2007,
nativeToken: 'SDN',
crowdloanUrl: 'https://polkadot.js.org/apps/#/parachains/crowdloan'
crowdloanUrl: 'https://polkadot.js.org/apps/#/parachains/crowdloan',
isSubscribe: true
},
shidenEvm: {
chain: 'Shiden - EVM',
Expand All @@ -401,7 +406,8 @@ const NETWORKS = {
provider: 'wss://rpc.shiden.astar.network',
groups: ['KUSAMA_PARACHAIN'],
nativeToken: 'SDN',
isEthereum: true
isEthereum: true,
isSubscribe: true
},
khala: {
chain: 'Khala',
Expand Down
10 changes: 10 additions & 0 deletions packages/extension-koni-base/build-cjs/api/subquery/crowdloan.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ const fetchDotSamaCrowdloan = async () => {
const paraList = [];
polkadotCrowdloan === null || polkadotCrowdloan === void 0 ? void 0 : (_polkadotCrowdloan$da = polkadotCrowdloan.data) === null || _polkadotCrowdloan$da === void 0 ? void 0 : (_polkadotCrowdloan$da2 = _polkadotCrowdloan$da.crowdloans) === null || _polkadotCrowdloan$da2 === void 0 ? void 0 : _polkadotCrowdloan$da2.nodes.forEach(node => {
let parachainId = node === null || node === void 0 ? void 0 : node.parachainId.substring(0, 4);

if (parachainId !== '2006') {
return;
}

parachainId = parachainId ? `polkadot-${parachainId}` : '';
paraList.push(parachainId);

Expand All @@ -89,6 +94,11 @@ const fetchDotSamaCrowdloan = async () => {
});
kusamaCrowdloan === null || kusamaCrowdloan === void 0 ? void 0 : (_kusamaCrowdloan$data = kusamaCrowdloan.data) === null || _kusamaCrowdloan$data === void 0 ? void 0 : (_kusamaCrowdloan$data2 = _kusamaCrowdloan$data.crowdloans) === null || _kusamaCrowdloan$data2 === void 0 ? void 0 : _kusamaCrowdloan$data2.nodes.forEach(node => {
let parachainId = node === null || node === void 0 ? void 0 : node.parachainId.substring(0, 4);

if (parachainId !== '2007') {
return;
}

parachainId = parachainId ? `kusama-${parachainId}` : '';
paraList.push(parachainId);

Expand Down
42 changes: 21 additions & 21 deletions packages/extension-koni-base/build-cjs/api/subquery/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@ var _utils = require("@polkadot/extension-koni-base/utils/utils");
const HistoryApiMap = {
polkadot: 'https://api.subquery.network/sq/nova-wallet/nova-westend',
kusama: 'https://api.subquery.network/sq/nova-wallet/nova-kusama',
westend: 'https://api.subquery.network/sq/nova-wallet/nova-westend',
picasso: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-picasso',
calamari: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-calamari',
khala: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-khala',
parallel: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-parallel',
bifrost: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-bifrost',
clover: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-clover',
basilisk: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-basilisk',
acala: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-acala',
// westend: 'https://api.subquery.network/sq/nova-wallet/nova-westend',
// picasso: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-picasso',
// calamari: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-calamari',
// khala: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-khala',
// parallel: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-parallel',
// bifrost: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-bifrost',
// clover: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-clover',
// basilisk: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-basilisk',
// acala: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-acala',
astar: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-astar',
karura: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-karura',
altair: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-altair',
kilt: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-kilt',
robonomics: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-robonomics',
statemint: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-statemint',
quartz: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-quartz',
zeigeist: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-zeitgeist',
shiden: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-shiden',
statemine: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-statemine',
moonbeam: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-moonbeam',
moonriver: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-moonriver',
pioneer: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-bit-country'
// karura: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-karura',
// altair: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-altair',
// kilt: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-kilt',
// robonomics: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-robonomics',
// statemint: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-statemint',
// quartz: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-quartz',
// zeigeist: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-zeitgeist',
shiden: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-shiden' // statemine: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-statemine',
// moonbeam: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-moonbeam',
// moonriver: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-moonriver',
// pioneer: 'https://api.subquery.network/sq/nova-wallet/nova-wallet-bit-country'

};
exports.HistoryApiMap = HistoryApiMap;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ function getRpcsMap() {
Object.keys(_endpoints.default).forEach(networkKey => {
const networkInfo = _endpoints.default[networkKey];

if (!networkInfo.isSubscribe) {
return;
}

if (!networkInfo.genesisHash || networkInfo.genesisHash.toLowerCase() === 'unknown') {
return;
}
Expand Down
15 changes: 6 additions & 9 deletions packages/extension-koni-base/src/api/dotsama/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ async function loadOnReady (registry: Registry, api: ApiPromise): Promise<ApiSta
}

export function initApi (networkKey: string, apiUrl: string): ApiProps {

const registry = new TypeRegistry();

const provider = apiUrl.startsWith('http') ? new HttpProvider(apiUrl) : new WsProvider(apiUrl, DOTSAMA_AUTO_CONNECT_MS);
Expand Down Expand Up @@ -169,13 +170,8 @@ export function initApi (networkKey: string, apiUrl: string): ApiProps {
}) as unknown as ApiProps;

api.on('connected', () => {
console.log('DotSamaAPI connected to', apiUrl);
console.log('Arth DotSamaAPI connected to', apiUrl);
result.apiRetry = 0;

if (result.isApiReadyOnce) {
result.isApiReady = true;
}

result.isApiConnected = true;
});

Expand All @@ -184,18 +180,18 @@ export function initApi (networkKey: string, apiUrl: string): ApiProps {
result.isApiReady = false;
result.apiRetry = (result.apiRetry || 0) + 1;

console.log(`DotSamaAPI disconnected from ${JSON.stringify(apiUrl)} ${JSON.stringify(result.apiRetry)} times`);
console.log(`Arth DotSamaAPI disconnected from ${JSON.stringify(apiUrl)} ${JSON.stringify(result.apiRetry)} times`);

if (result.apiRetry > DOTSAMA_MAX_CONTINUE_RETRY) {
console.log(`Discontinue to use ${JSON.stringify(apiUrl)} because max retry`);
console.log(`Arth Discontinue to use ${JSON.stringify(apiUrl)} because max retry`);
provider.disconnect()
.then(console.log)
.catch(console.error);
}
});

api.on('ready', () => {
console.log('DotSamaAPI ready with', apiUrl);
console.log('Arth DotSamaAPI ready with', apiUrl);
loadOnReady(registry, api)
.then((rs) => {
objectSpread(result, rs);
Expand All @@ -206,4 +202,5 @@ export function initApi (networkKey: string, apiUrl: string): ApiProps {
});

return result;

}
19 changes: 15 additions & 4 deletions packages/extension-koni-base/src/api/dotsama/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,26 @@ export function connectDotSamaApis (networks = NETWORKS): Record<string, ApiProp
const apisMap: Record<string, ApiProps> = {};

Object.keys(networks).forEach((networkKey) => {
const network = networks[networkKey];

if (!network.genesisHash || network.genesisHash.toLowerCase() === 'unknown' || !network.provider) {
return;
//console.log('Arth networkKey: ', networkKey);
//console.log('Arth networks[networkKey].isSubscribe: ', networks[networkKey].isSubscribe);

if (networks[networkKey].isSubscribe) {

const network = networks[networkKey];
//console.log('Arth networks: ', networks);

if (!network.genesisHash || network.genesisHash.toLowerCase() === 'unknown' || !network.provider) {
return;
}

apisMap[networkKey] = initApi(networkKey, network.provider);
}

apisMap[networkKey] = initApi(networkKey, network.provider);
});

console.log('Arth apisMap: ', apisMap);

return apisMap;
}

Expand Down
18 changes: 12 additions & 6 deletions packages/extension-koni-base/src/api/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const NETWORKS: Record<string, NetWorkInfo> = {
provider: 'wss://polkadot.api.onfinality.io/public-ws',
groups: ['RELAY_CHAIN'],
nativeToken: 'DOT',
decimals: 10
decimals: 10,
isSubscribe: true
},
kusama: {
chain: 'Kusama Relay Chain',
Expand All @@ -23,7 +24,8 @@ const NETWORKS: Record<string, NetWorkInfo> = {
provider: 'wss://kusama.api.onfinality.io/public-ws',
groups: ['RELAY_CHAIN'],
nativeToken: 'KSM',
decimals: 12
decimals: 12,
isSubscribe: true
},
westend: {
chain: 'Westend Relay Chain',
Expand Down Expand Up @@ -94,7 +96,8 @@ const NETWORKS: Record<string, NetWorkInfo> = {
paraId: 2006,
nativeToken: 'ASTR',
crowdloanUrl: 'https://crowdloan.astar.network/#/',
decimals: 18
decimals: 18,
isSubscribe: true
},
astarEvm: {
chain: 'Astar - EVM',
Expand All @@ -106,7 +109,8 @@ const NETWORKS: Record<string, NetWorkInfo> = {
groups: ['POLKADOT_PARACHAIN', 'ASTAR_MAINNET'],
isEthereum: true,
nativeToken: 'ASTR',
decimals: 18
decimals: 18,
isSubscribe: true
},
parallel: {
chain: 'Parallel',
Expand Down Expand Up @@ -387,7 +391,8 @@ const NETWORKS: Record<string, NetWorkInfo> = {
groups: ['KUSAMA_PARACHAIN'],
paraId: 2007,
nativeToken: 'SDN',
crowdloanUrl: 'https://polkadot.js.org/apps/#/parachains/crowdloan'
crowdloanUrl: 'https://polkadot.js.org/apps/#/parachains/crowdloan',
isSubscribe: true
},
shidenEvm: {
chain: 'Shiden - EVM',
Expand All @@ -396,7 +401,8 @@ const NETWORKS: Record<string, NetWorkInfo> = {
provider: 'wss://rpc.shiden.astar.network',
groups: ['KUSAMA_PARACHAIN'],
nativeToken: 'SDN',
isEthereum: true
isEthereum: true,
isSubscribe: true
},
khala: {
chain: 'Khala',
Expand Down
8 changes: 8 additions & 0 deletions packages/extension-koni-base/src/api/subquery/crowdloan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ export const fetchDotSamaCrowdloan = async () => {
polkadotCrowdloan?.data?.crowdloans?.nodes.forEach((node) => {
let parachainId = node?.parachainId.substring(0, 4);

if (parachainId !== '2006') {
return;
}

parachainId = parachainId ? `polkadot-${parachainId}` : '';
paraList.push(parachainId);

Expand All @@ -88,6 +92,10 @@ export const fetchDotSamaCrowdloan = async () => {
kusamaCrowdloan?.data?.crowdloans?.nodes.forEach((node) => {
let parachainId = node?.parachainId.substring(0, 4);

if (parachainId !== '2007') {
return;
}

parachainId = parachainId ? `kusama-${parachainId}` : '';
paraList.push(parachainId);

Expand Down
Loading

0 comments on commit dbd0cca

Please sign in to comment.