@subwallet/extension-base 1.1.2-0 → 1.1.2-1

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.
Files changed (77) hide show
  1. package/background/KoniTypes.d.ts +14 -4
  2. package/cjs/constants/i18n.js +10 -2
  3. package/cjs/koni/api/dotsama/transfer.js +6 -0
  4. package/cjs/koni/api/nft/acala_nft/index.js +0 -2
  5. package/cjs/koni/api/nft/bit.country/index.js +49 -18
  6. package/cjs/koni/api/nft/config.js +5 -3
  7. package/cjs/koni/api/nft/evm_nft/index.js +0 -5
  8. package/cjs/koni/api/nft/index.js +2 -3
  9. package/cjs/koni/api/nft/karura_nft/index.js +0 -2
  10. package/cjs/koni/api/nft/rmrk_nft/index.js +0 -4
  11. package/cjs/koni/api/nft/statemine_nft/index.js +0 -2
  12. package/cjs/koni/api/nft/unique_nft/index.js +0 -5
  13. package/cjs/koni/api/nft/wasm_nft/index.js +0 -5
  14. package/cjs/koni/api/staking/bonding/amplitude.js +6 -6
  15. package/cjs/koni/api/staking/bonding/astar.js +6 -6
  16. package/cjs/koni/api/staking/bonding/paraChain.js +5 -5
  17. package/cjs/koni/api/staking/bonding/relayChain.js +24 -14
  18. package/cjs/koni/api/staking/bonding/utils.js +1 -7
  19. package/cjs/koni/api/xcm/xTokens.js +1 -1
  20. package/cjs/koni/background/cron.js +2 -37
  21. package/cjs/koni/background/handlers/Extension.js +133 -123
  22. package/cjs/koni/background/handlers/State.js +6 -43
  23. package/cjs/koni/background/subscription.js +6 -88
  24. package/cjs/packageInfo.js +1 -1
  25. package/cjs/services/chain-service/constants.js +6 -4
  26. package/cjs/services/setting-service/constants.js +16 -6
  27. package/cjs/services/storage-service/DatabaseService.js +3 -0
  28. package/cjs/services/storage-service/db-stores/Nft.js +3 -0
  29. package/cjs/services/storage-service/db-stores/NominatorMetadata.js +3 -2
  30. package/cjs/utils/index.js +12 -0
  31. package/cjs/utils/translate.js +11 -0
  32. package/constants/i18n.d.ts +2 -1
  33. package/constants/i18n.js +8 -1
  34. package/koni/api/dotsama/transfer.js +6 -0
  35. package/koni/api/nft/acala_nft/index.js +0 -2
  36. package/koni/api/nft/bit.country/index.d.ts +1 -0
  37. package/koni/api/nft/bit.country/index.js +50 -19
  38. package/koni/api/nft/config.d.ts +2 -1
  39. package/koni/api/nft/config.js +2 -1
  40. package/koni/api/nft/evm_nft/index.js +0 -4
  41. package/koni/api/nft/index.d.ts +1 -1
  42. package/koni/api/nft/index.js +2 -3
  43. package/koni/api/nft/karura_nft/index.js +0 -2
  44. package/koni/api/nft/nft.d.ts +0 -1
  45. package/koni/api/nft/rmrk_nft/index.js +0 -4
  46. package/koni/api/nft/statemine_nft/index.js +0 -2
  47. package/koni/api/nft/unique_nft/index.js +0 -5
  48. package/koni/api/nft/wasm_nft/index.js +0 -4
  49. package/koni/api/staking/bonding/amplitude.js +6 -6
  50. package/koni/api/staking/bonding/astar.js +6 -6
  51. package/koni/api/staking/bonding/paraChain.js +5 -5
  52. package/koni/api/staking/bonding/relayChain.js +24 -14
  53. package/koni/api/staking/bonding/utils.js +1 -7
  54. package/koni/api/xcm/xTokens.js +1 -1
  55. package/koni/background/cron.d.ts +0 -5
  56. package/koni/background/cron.js +4 -39
  57. package/koni/background/handlers/Extension.d.ts +2 -0
  58. package/koni/background/handlers/Extension.js +25 -17
  59. package/koni/background/handlers/State.d.ts +2 -6
  60. package/koni/background/handlers/State.js +6 -43
  61. package/koni/background/subscription.d.ts +1 -4
  62. package/koni/background/subscription.js +9 -88
  63. package/package.json +11 -6
  64. package/packageInfo.js +1 -1
  65. package/services/chain-service/constants.d.ts +1 -0
  66. package/services/chain-service/constants.js +6 -4
  67. package/services/setting-service/constants.d.ts +6 -1
  68. package/services/setting-service/constants.js +10 -5
  69. package/services/storage-service/DatabaseService.d.ts +1 -0
  70. package/services/storage-service/DatabaseService.js +3 -0
  71. package/services/storage-service/db-stores/Nft.d.ts +1 -0
  72. package/services/storage-service/db-stores/Nft.js +3 -0
  73. package/services/storage-service/db-stores/NominatorMetadata.js +3 -2
  74. package/utils/index.d.ts +1 -0
  75. package/utils/index.js +2 -1
  76. package/utils/translate.d.ts +1 -0
  77. package/utils/translate.js +4 -0
@@ -129,7 +129,6 @@ export class RmrkNftApi extends BaseNftApi {
129
129
  const kusamaAddress = reformatAddress(address, 2);
130
130
  allNfts = await this.getAllByAccount(kusamaAddress);
131
131
  if (allNfts.length <= 0) {
132
- params.cleanUpNfts(this.chain, address, [], [], true);
133
132
  return;
134
133
  }
135
134
  const collectionInfoUrl = [];
@@ -237,9 +236,6 @@ export class RmrkNftApi extends BaseNftApi {
237
236
  });
238
237
  params.updateCollection(this.chain, parsedCollection);
239
238
  });
240
- const allCollectionIds = allCollections.map(item => item.collectionId);
241
- const allNftIds = allNfts.map(nft => nft === null || nft === void 0 ? void 0 : nft.id);
242
- params.cleanUpNfts(this.chain, address, allCollectionIds, allNftIds);
243
239
  } catch (e) {
244
240
  console.error(`${this.chain}`, e);
245
241
  }
@@ -86,7 +86,6 @@ export default class StatemineNftApi extends BaseNftApi {
86
86
  const assetIds = await this.getNfts([address]);
87
87
  try {
88
88
  if (!assetIds || assetIds.length === 0) {
89
- params.cleanUpNfts(this.chain, address, [], [], true);
90
89
  return;
91
90
  }
92
91
  const collectionIds = [];
@@ -117,7 +116,6 @@ export default class StatemineNftApi extends BaseNftApi {
117
116
  };
118
117
  params.updateCollection(this.chain, parsedCollection);
119
118
  }));
120
- params.cleanUpNfts(this.chain, address, collectionIds, nftIds);
121
119
  } catch (e) {
122
120
  console.error(`${this.chain}`, e);
123
121
  }
@@ -133,8 +133,6 @@ export default class UniqueNftApi extends BaseNftApi {
133
133
  }
134
134
  }
135
135
  }));
136
- const collectionIds = [];
137
- let allNftIds = [];
138
136
  await Promise.all(allCollectionId.map(async collectionId => {
139
137
  const collectionIdStr = collectionId.toString();
140
138
 
@@ -142,8 +140,6 @@ export default class UniqueNftApi extends BaseNftApi {
142
140
  const collection = (await this.substrateApi.api.query.nft.collectionById(collectionId)).toJSON();
143
141
  collectionMap[collectionIdStr] = collection;
144
142
  const nftIds = Object.entries(nftMap).filter(item => item[1] === collectionId).map(item => item[0]);
145
- collectionIds.push(collectionIdStr);
146
- allNftIds = allNftIds.concat(nftIds);
147
143
  const parsedCollection = {
148
144
  collectionId: collectionIdStr,
149
145
  chain: this.chain
@@ -173,7 +169,6 @@ export default class UniqueNftApi extends BaseNftApi {
173
169
  }
174
170
  }));
175
171
  }));
176
- params.cleanUpNfts(this.chain, address, collectionIds, allNftIds);
177
172
  } catch (e) {
178
173
  console.error(`${this.chain}`, e);
179
174
  }
@@ -324,7 +324,6 @@ export class WasmNftApi extends BaseNftApi {
324
324
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
325
325
  const balance = _balance.output ? balanceJson.ok || balanceJson.Ok : '0';
326
326
  if (parseInt(balance) === 0) {
327
- nftParams.cleanUpNfts(this.chain, address, [smartContract], []);
328
327
  return;
329
328
  }
330
329
  const itemIndexes = [];
@@ -408,9 +407,6 @@ export class WasmNftApi extends BaseNftApi {
408
407
  originAsset: tokenInfo.slug
409
408
  };
410
409
  nftParams.updateCollection(this.chain, nftCollection);
411
- Object.entries(nftOwnerMap).forEach(([owner, nftIds]) => {
412
- nftParams.cleanUpNfts(this.chain, owner, [smartContract], nftIds);
413
- });
414
410
  }
415
411
  }
416
412
  async fetchNfts(params) {
@@ -89,14 +89,14 @@ export async function subscribeAmplitudeNominatorMetadata(chainInfo, address, su
89
89
  const nearestUnstakingAmount = Object.values(unstakingInfo)[0];
90
90
  const blockDuration = (_STAKING_ERA_LENGTH_MAP[chainInfo.slug] || _STAKING_ERA_LENGTH_MAP.default) / blockPerRound; // in hours
91
91
 
92
- const isClaimable = parseInt(nearestUnstakingBlock) - currentBlockNumber <= 0;
93
- const remainingBlock = parseInt(nearestUnstakingBlock) - (currentBlockNumber + 1);
92
+ const isClaimable = parseInt(nearestUnstakingBlock) - currentBlockNumber < 0;
93
+ const remainingBlock = parseInt(nearestUnstakingBlock) - currentBlockNumber;
94
94
  const waitingTime = remainingBlock * blockDuration;
95
95
  unstakingList.push({
96
96
  chain: chainInfo.slug,
97
97
  status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
98
98
  claimable: nearestUnstakingAmount.toString(),
99
- waitingTime: waitingTime > 0 ? waitingTime : 0,
99
+ waitingTime,
100
100
  validatorAddress: (delegatorState === null || delegatorState === void 0 ? void 0 : delegatorState.owner) || undefined
101
101
  });
102
102
  }
@@ -165,14 +165,14 @@ export async function getAmplitudeNominatorMetadata(chainInfo, address, substrat
165
165
  const nearestUnstakingAmount = Object.values(unstakingInfo)[0];
166
166
  const blockDuration = (_STAKING_ERA_LENGTH_MAP[chain] || _STAKING_ERA_LENGTH_MAP.default) / blockPerRound; // in hours
167
167
 
168
- const isClaimable = parseInt(nearestUnstakingBlock) - currentBlockNumber <= 0;
169
- const remainingBlock = parseInt(nearestUnstakingBlock) - (currentBlockNumber + 1);
168
+ const isClaimable = parseInt(nearestUnstakingBlock) - currentBlockNumber < 0;
169
+ const remainingBlock = parseInt(nearestUnstakingBlock) - currentBlockNumber;
170
170
  const waitingTime = remainingBlock * blockDuration;
171
171
  unstakingList.push({
172
172
  chain,
173
173
  status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
174
174
  claimable: nearestUnstakingAmount.toString(),
175
- waitingTime: waitingTime > 0 ? waitingTime : 0,
175
+ waitingTime,
176
176
  validatorAddress: (delegatorState === null || delegatorState === void 0 ? void 0 : delegatorState.owner) || undefined
177
177
  });
178
178
  }
@@ -111,14 +111,14 @@ export async function subscribeAstarNominatorMetadata(chainInfo, address, substr
111
111
  const unlockingChunks = ledger.unbondingInfo.unlockingChunks;
112
112
  if (unlockingChunks.length > 0) {
113
113
  for (const unlockingChunk of unlockingChunks) {
114
- const isClaimable = unlockingChunk.unlockEra - parseInt(currentEra) <= 0;
115
- const remainingEra = unlockingChunk.unlockEra - (parseInt(currentEra) + 1);
114
+ const isClaimable = unlockingChunk.unlockEra - parseInt(currentEra) < 0;
115
+ const remainingEra = unlockingChunk.unlockEra - parseInt(currentEra);
116
116
  const waitingTime = remainingEra * _STAKING_ERA_LENGTH_MAP[chainInfo.slug];
117
117
  unstakingList.push({
118
118
  chain: chainInfo.slug,
119
119
  status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
120
120
  claimable: unlockingChunk.amount.toString(),
121
- waitingTime: waitingTime > 0 ? waitingTime : 0
121
+ waitingTime
122
122
  });
123
123
  }
124
124
  }
@@ -199,14 +199,14 @@ export async function getAstarNominatorMetadata(chainInfo, address, substrateApi
199
199
  const unlockingChunks = ledger.unbondingInfo.unlockingChunks;
200
200
  if (unlockingChunks.length > 0) {
201
201
  for (const unlockingChunk of unlockingChunks) {
202
- const isClaimable = unlockingChunk.unlockEra - parseInt(currentEra) <= 0;
203
- const remainingEra = unlockingChunk.unlockEra - (parseInt(currentEra) + 1);
202
+ const isClaimable = unlockingChunk.unlockEra - parseInt(currentEra) < 0;
203
+ const remainingEra = unlockingChunk.unlockEra - parseInt(currentEra);
204
204
  const waitingTime = remainingEra * _STAKING_ERA_LENGTH_MAP[chain];
205
205
  unstakingList.push({
206
206
  chain,
207
207
  status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
208
208
  claimable: unlockingChunk.amount.toString(),
209
- waitingTime: waitingTime > 0 ? waitingTime : 0
209
+ waitingTime
210
210
  });
211
211
  }
212
212
  }
@@ -162,8 +162,8 @@ export async function subscribeParaChainNominatorMetadata(chainInfo, address, su
162
162
  for (const scheduledRequest of delegationScheduledRequests) {
163
163
  if (reformatAddress(scheduledRequest.delegator, 0) === reformatAddress(address, 0)) {
164
164
  // add network prefix
165
- const isClaimable = scheduledRequest.whenExecutable - currentRound <= 0;
166
- const remainingEra = scheduledRequest.whenExecutable - (currentRound + 1);
165
+ const isClaimable = scheduledRequest.whenExecutable - currentRound < 0;
166
+ const remainingEra = scheduledRequest.whenExecutable - currentRound;
167
167
  const waitingTime = remainingEra * _STAKING_ERA_LENGTH_MAP[chainInfo.slug];
168
168
  const claimable = Object.values(scheduledRequest.action)[0];
169
169
  unstakingMap[delegation.owner] = {
@@ -171,7 +171,7 @@ export async function subscribeParaChainNominatorMetadata(chainInfo, address, su
171
171
  status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
172
172
  validatorAddress: delegation.owner,
173
173
  claimable: claimable.toString(),
174
- waitingTime: waitingTime > 0 ? waitingTime : 0
174
+ waitingTime
175
175
  };
176
176
  hasUnstaking = true;
177
177
  break; // only handle 1 scheduledRequest per collator
@@ -254,7 +254,7 @@ export async function getParaChainNominatorMetadata(chainInfo, address, substrat
254
254
  for (const scheduledRequest of delegationScheduledRequests) {
255
255
  if (reformatAddress(scheduledRequest.delegator, 0) === reformatAddress(address, 0)) {
256
256
  // add network prefix
257
- const isClaimable = scheduledRequest.whenExecutable - currentRound <= 0;
257
+ const isClaimable = scheduledRequest.whenExecutable - currentRound < 0;
258
258
  const remainingEra = scheduledRequest.whenExecutable - (currentRound + 1);
259
259
  const waitingTime = remainingEra * _STAKING_ERA_LENGTH_MAP[chain];
260
260
  const claimable = Object.values(scheduledRequest.action)[0];
@@ -263,7 +263,7 @@ export async function getParaChainNominatorMetadata(chainInfo, address, substrat
263
263
  status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
264
264
  validatorAddress: delegation.owner,
265
265
  claimable: claimable.toString(),
266
- waitingTime: waitingTime > 0 ? waitingTime : 0
266
+ waitingTime: waitingTime
267
267
  };
268
268
  hasUnstaking = true;
269
269
  break; // only handle 1 scheduledRequest per collator
@@ -214,14 +214,14 @@ export async function subscribeRelayChainNominatorMetadata(chainInfo, address, s
214
214
  }
215
215
  }
216
216
  ledger.unlocking.forEach(unlockingChunk => {
217
- const isClaimable = unlockingChunk.era - parseInt(currentEra) <= 0;
218
- const remainingEra = unlockingChunk.era - (parseInt(currentEra) + 1);
217
+ const isClaimable = unlockingChunk.era - parseInt(currentEra) < 0;
218
+ const remainingEra = unlockingChunk.era - parseInt(currentEra);
219
219
  const waitingTime = remainingEra * _STAKING_ERA_LENGTH_MAP[chain];
220
220
  unstakingList.push({
221
221
  chain,
222
222
  status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
223
223
  claimable: unlockingChunk.value.toString(),
224
- waitingTime: waitingTime > 0 ? waitingTime : 0
224
+ waitingTime: waitingTime
225
225
  });
226
226
  });
227
227
  return {
@@ -313,14 +313,14 @@ export async function getRelayChainNominatorMetadata(chainInfo, address, substra
313
313
  }
314
314
  }
315
315
  ledger.unlocking.forEach(unlockingChunk => {
316
- const isClaimable = unlockingChunk.era - parseInt(currentEra) <= 0;
317
- const remainingEra = unlockingChunk.era - (parseInt(currentEra) + 1);
316
+ const isClaimable = unlockingChunk.era - parseInt(currentEra) < 0;
317
+ const remainingEra = unlockingChunk.era - parseInt(currentEra);
318
318
  const waitingTime = remainingEra * _STAKING_ERA_LENGTH_MAP[chain];
319
319
  unstakingList.push({
320
320
  chain,
321
321
  status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
322
322
  claimable: unlockingChunk.value.toString(),
323
- waitingTime: waitingTime > 0 ? waitingTime : 0
323
+ waitingTime: waitingTime
324
324
  });
325
325
  });
326
326
  return {
@@ -370,14 +370,14 @@ export async function subscribeRelayChainPoolMemberMetadata(chainInfo, address,
370
370
  };
371
371
  const unstakings = [];
372
372
  Object.entries(poolMemberInfo.unbondingEras).forEach(([unlockingEra, amount]) => {
373
- const isClaimable = parseInt(unlockingEra) - parseInt(currentEra) <= 0;
374
- const remainingEra = parseInt(unlockingEra) - (parseInt(currentEra) + 1);
373
+ const isClaimable = parseInt(unlockingEra) - parseInt(currentEra) < 0;
374
+ const remainingEra = parseInt(unlockingEra) - parseInt(currentEra);
375
375
  const waitingTime = remainingEra * _STAKING_ERA_LENGTH_MAP[chainInfo.slug];
376
376
  unstakings.push({
377
377
  chain: chainInfo.slug,
378
378
  status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
379
379
  claimable: amount.toString(),
380
- waitingTime: waitingTime > 0 ? waitingTime : 0
380
+ waitingTime: waitingTime
381
381
  });
382
382
  });
383
383
  const bnActiveStake = new BN(poolMemberInfo.points.toString());
@@ -447,14 +447,14 @@ export async function getRelayChainPoolMemberMetadata(chainInfo, address, substr
447
447
  };
448
448
  const unstakings = [];
449
449
  Object.entries(poolMemberInfo.unbondingEras).forEach(([unlockingEra, amount]) => {
450
- const isClaimable = parseInt(unlockingEra) - parseInt(currentEra) <= 0;
451
- const remainingEra = parseInt(unlockingEra) - (parseInt(currentEra) + 1);
450
+ const isClaimable = parseInt(unlockingEra) - parseInt(currentEra) < 0;
451
+ const remainingEra = parseInt(unlockingEra) - parseInt(currentEra);
452
452
  const waitingTime = remainingEra * _STAKING_ERA_LENGTH_MAP[chainInfo.slug];
453
453
  unstakings.push({
454
454
  chain: chainInfo.slug,
455
455
  status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
456
456
  claimable: amount.toString(),
457
- waitingTime: waitingTime > 0 ? waitingTime : 0
457
+ waitingTime: waitingTime
458
458
  });
459
459
  });
460
460
  const bnActiveStake = new BN(poolMemberInfo.points.toString());
@@ -588,17 +588,27 @@ export async function getRelayBondingExtrinsic(substrateApi, amount, targetValid
588
588
  const binaryAmount = new BN(amount);
589
589
  let bondTx;
590
590
  let nominateTx;
591
+ const _params = chainApi.api.tx.staking.bond.toJSON();
592
+ const paramsCount = _params.args.length;
591
593
  const validatorParamList = targetValidators.map(validator => {
592
594
  return validator.address;
593
595
  });
594
596
  if (!nominatorMetadata) {
595
- bondTx = chainApi.api.tx.staking.bond(address, binaryAmount, bondDest);
597
+ if (paramsCount === 2) {
598
+ bondTx = chainApi.api.tx.staking.bond(binaryAmount, bondDest);
599
+ } else {
600
+ bondTx = chainApi.api.tx.staking.bond(address, binaryAmount, bondDest);
601
+ }
596
602
  nominateTx = chainApi.api.tx.staking.nominate(validatorParamList);
597
603
  return chainApi.api.tx.utility.batchAll([bondTx, nominateTx]);
598
604
  }
599
605
  if (!nominatorMetadata.isBondedBefore) {
600
606
  // first time
601
- bondTx = chainApi.api.tx.staking.bond(nominatorMetadata.address, binaryAmount, bondDest);
607
+ if (paramsCount === 2) {
608
+ bondTx = chainApi.api.tx.staking.bond(binaryAmount, bondDest);
609
+ } else {
610
+ bondTx = chainApi.api.tx.staking.bond(nominatorMetadata.address, binaryAmount, bondDest);
611
+ }
602
612
  nominateTx = chainApi.api.tx.staking.nominate(validatorParamList);
603
613
  return chainApi.api.tx.utility.batchAll([bondTx, nominateTx]);
604
614
  } else {
@@ -189,13 +189,7 @@ export function getStakingAvailableActionsByNominator(nominatorMetadata, unclaim
189
189
  }
190
190
  if (nominatorMetadata.unstakings.length > 0) {
191
191
  result.push(StakingAction.CANCEL_UNSTAKE);
192
- let hasClaimable = false;
193
- for (const unstaking of nominatorMetadata.unstakings) {
194
- if (unstaking.status === UnstakingStatus.CLAIMABLE) {
195
- hasClaimable = true;
196
- break;
197
- }
198
- }
192
+ const hasClaimable = nominatorMetadata.unstakings.some(unstaking => unstaking.status === UnstakingStatus.CLAIMABLE);
199
193
  if (hasClaimable) {
200
194
  result.push(StakingAction.WITHDRAW);
201
195
  }
@@ -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'].includes(originChainInfo.slug) ? 'V3' : undefined;
22
+ const destVersion = ['moonbeam', 'moonriver', 'bifrost_dot', 'interlay', 'hydradx_main', 'acala'].includes(originChainInfo.slug) ? 'V3' : undefined;
23
23
  return api.tx.xTokens.transfer(getCurrencyId(tokenInfo), value, getDestMultilocation(destinationChainInfo, recipientAddress, destVersion), weightParam);
24
24
  }
@@ -1,7 +1,6 @@
1
1
  import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
2
2
  import { ApiMap, ServiceInfo } from '@subwallet/extension-base/background/KoniTypes';
3
3
  import { KoniSubscription } from '@subwallet/extension-base/koni/background/subscription';
4
- import { _ChainState, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
5
4
  import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
6
5
  import { Subject } from 'rxjs';
7
6
  import KoniState from './handlers/State';
@@ -27,15 +26,11 @@ export declare class KoniCron {
27
26
  syncMantaPay: () => void;
28
27
  refreshNft: (address: string, apiMap: ApiMap, smartContractNfts: _ChainAsset[], chainInfoMap: Record<string, _ChainInfo>) => () => void;
29
28
  resetNft: (newAddress: string) => void;
30
- resetStakingReward: () => void;
31
29
  refreshStakingReward: (address: string) => () => void;
32
30
  refreshStakingRewardFastInterval: (address: string) => () => void;
33
31
  setStakingRewardReady: () => void;
34
32
  checkNetworkAvailable: (serviceInfo: ServiceInfo) => boolean;
35
- updateChainStakingMetadata: (chainInfoMap: Record<string, _ChainInfo>, chainStateMap: Record<string, _ChainState>, substrateApiMap: Record<string, _SubstrateApi>) => () => void;
36
- updateNominatorMetadata: (address: string, chainInfoMap: Record<string, _ChainInfo>, chainStateMap: Record<string, _ChainState>, substrateApiMap: Record<string, _SubstrateApi>) => () => void;
37
33
  reloadNft(): Promise<boolean>;
38
34
  reloadStaking(): Promise<boolean>;
39
35
  private needUpdateNft;
40
- private needUpdateStaking;
41
36
  }
@@ -1,8 +1,8 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { CRON_REFRESH_CHAIN_STAKING_METADATA, CRON_REFRESH_NFT_INTERVAL, CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL, CRON_REFRESH_STAKING_REWARD_INTERVAL, CRON_SYNC_MANTA_PAY } from '@subwallet/extension-base/constants';
5
- import { _isChainSupportEvmNft, _isChainSupportNativeNft, _isChainSupportSubstrateStaking, _isChainSupportWasmNft } from '@subwallet/extension-base/services/chain-service/utils';
4
+ import { CRON_REFRESH_NFT_INTERVAL, CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL, CRON_REFRESH_STAKING_REWARD_INTERVAL, CRON_SYNC_MANTA_PAY } from '@subwallet/extension-base/constants';
5
+ import { _isChainSupportEvmNft, _isChainSupportNativeNft, _isChainSupportWasmNft } from '@subwallet/extension-base/services/chain-service/utils';
6
6
  import { waitTimeout } from '@subwallet/extension-base/utils';
7
7
  import { Subject } from 'rxjs';
8
8
  import { logger as createLogger } from '@polkadot/util';
@@ -61,7 +61,6 @@ export class KoniCron {
61
61
  const serviceInfo = this.state.getServiceInfo();
62
62
  const commonReload = eventTypes.some(eventType => commonReloadEvents.includes(eventType));
63
63
  const chainUpdated = eventTypes.includes('chain.updateState');
64
- const stakingSubmitted = eventTypes.includes('transaction.submitStaking');
65
64
  const reloadMantaPay = eventTypes.includes('mantaPay.submitTransaction') || eventTypes.includes('mantaPay.enable');
66
65
  const updatedChains = [];
67
66
  if (chainUpdated) {
@@ -72,7 +71,7 @@ export class KoniCron {
72
71
  }
73
72
  });
74
73
  }
75
- if (!commonReload && !chainUpdated && !stakingSubmitted && !reloadMantaPay) {
74
+ if (!commonReload && !chainUpdated && !reloadMantaPay) {
76
75
  return;
77
76
  }
78
77
  const address = (_serviceInfo$currentA = serviceInfo.currentAccountInfo) === null || _serviceInfo$currentA === void 0 ? void 0 : _serviceInfo$currentA.address;
@@ -81,7 +80,6 @@ export class KoniCron {
81
80
  }
82
81
  const chainInfoMap = serviceInfo.chainInfoMap;
83
82
  const needUpdateNft = this.needUpdateNft(chainInfoMap, updatedChains);
84
- const needUpdateStaking = this.needUpdateStaking(chainInfoMap, updatedChains);
85
83
 
86
84
  // MantaPay
87
85
  reloadMantaPay && this.removeCron('syncMantaPay');
@@ -90,19 +88,10 @@ export class KoniCron {
90
88
  (commonReload || needUpdateNft) && this.resetNft(address);
91
89
  (commonReload || needUpdateNft) && this.removeCron('refreshNft');
92
90
 
93
- // Staking
94
- (commonReload || needUpdateStaking || stakingSubmitted) && this.resetStakingReward();
95
- (commonReload || needUpdateStaking || stakingSubmitted) && this.removeCron('refreshStakingReward');
96
- (commonReload || needUpdateStaking || stakingSubmitted) && this.removeCron('refreshPoolingStakingReward');
97
- needUpdateStaking && this.removeCron('updateChainStakingMetadata');
98
-
99
91
  // Chains
100
92
  if (this.checkNetworkAvailable(serviceInfo)) {
101
93
  // only add cron job if there's at least 1 active network
102
94
  (commonReload || needUpdateNft) && this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
103
- (commonReload || needUpdateStaking || stakingSubmitted) && this.addCron('refreshStakingReward', this.refreshStakingReward(address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
104
- (commonReload || needUpdateStaking || stakingSubmitted) && this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
105
- needUpdateStaking && this.addCron('updateChainStakingMetadata', this.updateChainStakingMetadata(serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), CRON_REFRESH_CHAIN_STAKING_METADATA);
106
95
  reloadMantaPay && this.addCron('syncMantaPay', this.syncMantaPay, CRON_SYNC_MANTA_PAY);
107
96
  } else {
108
97
  this.setStakingRewardReady();
@@ -117,7 +106,6 @@ export class KoniCron {
117
106
  this.addCron('refreshNft', this.refreshNft(currentAccountInfo.address, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
118
107
  this.addCron('refreshStakingReward', this.refreshStakingReward(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
119
108
  this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
120
- this.addCron('updateChainStakingMetadata', this.updateChainStakingMetadata(this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap()), CRON_REFRESH_CHAIN_STAKING_METADATA);
121
109
  this.addCron('syncMantaPay', this.syncMantaPay, CRON_SYNC_MANTA_PAY);
122
110
  } else {
123
111
  this.setStakingRewardReady();
@@ -155,9 +143,6 @@ export class KoniCron {
155
143
  resetNft = newAddress => {
156
144
  this.state.resetNft(newAddress);
157
145
  };
158
- resetStakingReward = () => {
159
- this.state.resetStakingReward();
160
- };
161
146
  refreshStakingReward = address => {
162
147
  return () => {
163
148
  this.subscriptions.subscribeStakingReward(address).catch(this.logger.error);
@@ -174,16 +159,6 @@ export class KoniCron {
174
159
  checkNetworkAvailable = serviceInfo => {
175
160
  return Object.keys(serviceInfo.chainApiMap.substrate).length > 0 || Object.keys(serviceInfo.chainApiMap.evm).length > 0;
176
161
  };
177
- updateChainStakingMetadata = (chainInfoMap, chainStateMap, substrateApiMap) => {
178
- return () => {
179
- this.subscriptions.fetchChainStakingMetadata(chainInfoMap, chainStateMap, substrateApiMap).catch(this.logger.error);
180
- };
181
- };
182
- updateNominatorMetadata = (address, chainInfoMap, chainStateMap, substrateApiMap) => {
183
- return () => {
184
- this.subscriptions.fetchNominatorMetadata(address, chainInfoMap, chainStateMap, substrateApiMap).catch(this.logger.error);
185
- };
186
- };
187
162
  async reloadNft() {
188
163
  const address = this.state.keyringService.currentAccount.address;
189
164
  const serviceInfo = this.state.getServiceInfo();
@@ -195,11 +170,7 @@ export class KoniCron {
195
170
  }
196
171
  async reloadStaking() {
197
172
  const address = this.state.keyringService.currentAccount.address;
198
- this.resetStakingReward();
199
- this.removeCron('refreshStakingReward');
200
- this.removeCron('refreshPoolingStakingReward');
201
- this.addCron('refreshStakingReward', this.refreshStakingReward(address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
202
- this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
173
+ console.log('reload staking', address);
203
174
  await waitTimeout(1800);
204
175
  return true;
205
176
  }
@@ -212,10 +183,4 @@ export class KoniCron {
212
183
  }
213
184
  return false;
214
185
  }
215
- needUpdateStaking(chainInfoMap, updatedChains) {
216
- if (updatedChains && updatedChains.length > 0) {
217
- return updatedChains.some(updatedChain => _isChainSupportSubstrateStaking(chainInfoMap[updatedChain]));
218
- }
219
- return false;
220
- }
221
186
  }
@@ -76,6 +76,8 @@ export default class KoniExtension {
76
76
  private setAutoLockTime;
77
77
  private subscribeSettings;
78
78
  private setEnableChainPatrol;
79
+ private setShowZeroBalance;
80
+ private setLanguage;
79
81
  private subscribeAuthUrls;
80
82
  private _saveCurrentAccountAddress;
81
83
  private updateCurrentAccountAddress;
@@ -828,32 +828,24 @@ export default class KoniExtension {
828
828
  });
829
829
  return true;
830
830
  }
831
- saveTheme(data, id, port) {
832
- const cb = createSubscription(id, port);
833
- this.#koniState.setTheme(data, cb);
834
- port.onDisconnect.addListener(() => {
835
- this.cancelSubscription(id);
836
- });
831
+ saveTheme(data) {
832
+ this.#koniState.updateSetting('theme', data);
837
833
  return true;
838
834
  }
839
835
  setCamera({
840
836
  camera
841
837
  }) {
842
- this.#koniState.setCamera(camera);
838
+ this.#koniState.updateSetting('camera', camera);
843
839
  return true;
844
840
  }
845
- saveBrowserConfirmationType(data, id, port) {
846
- const cb = createSubscription(id, port);
847
- this.#koniState.setBrowserConfirmationType(data, cb);
848
- port.onDisconnect.addListener(() => {
849
- this.cancelSubscription(id);
850
- });
841
+ saveBrowserConfirmationType(data) {
842
+ this.#koniState.updateSetting('browserConfirmationType', data);
851
843
  return true;
852
844
  }
853
845
  setAutoLockTime({
854
846
  autoLockTime
855
847
  }) {
856
- this.#koniState.setAutoLockTime(autoLockTime);
848
+ this.#koniState.updateSetting('timeAutoLock', autoLockTime);
857
849
  return true;
858
850
  }
859
851
  async subscribeSettings(id, port) {
@@ -872,7 +864,19 @@ export default class KoniExtension {
872
864
  setEnableChainPatrol({
873
865
  enable
874
866
  }) {
875
- this.#koniState.setEnableChainPatrol(enable);
867
+ this.#koniState.updateSetting('enableChainPatrol', enable);
868
+ return true;
869
+ }
870
+ setShowZeroBalance({
871
+ show
872
+ }) {
873
+ this.#koniState.updateSetting('isShowZeroBalance', show);
874
+ return true;
875
+ }
876
+ setLanguage({
877
+ language
878
+ }) {
879
+ this.#koniState.updateSetting('language', language);
876
880
  return true;
877
881
  }
878
882
  async subscribeAuthUrls(id, port) {
@@ -3402,13 +3406,17 @@ export default class KoniExtension {
3402
3406
  case 'pri(settings.saveCamera)':
3403
3407
  return this.setCamera(request);
3404
3408
  case 'pri(settings.saveTheme)':
3405
- return this.saveTheme(request, id, port);
3409
+ return this.saveTheme(request);
3406
3410
  case 'pri(settings.saveBrowserConfirmationType)':
3407
- return this.saveBrowserConfirmationType(request, id, port);
3411
+ return this.saveBrowserConfirmationType(request);
3408
3412
  case 'pri(settings.saveAutoLockTime)':
3409
3413
  return this.setAutoLockTime(request);
3410
3414
  case 'pri(settings.saveEnableChainPatrol)':
3411
3415
  return this.setEnableChainPatrol(request);
3416
+ case 'pri(settings.saveShowZeroBalance)':
3417
+ return this.setShowZeroBalance(request);
3418
+ case 'pri(settings.saveLanguage)':
3419
+ return this.setLanguage(request);
3412
3420
  case 'pri(price.getPrice)':
3413
3421
  return await this.getPrice();
3414
3422
  case 'pri(price.getSubscription)':
@@ -1,6 +1,6 @@
1
1
  /// <reference types="chrome" />
2
2
  import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _MultiChainAsset } from '@subwallet/chain-list/types';
3
- import { AddTokenRequestExternal, AmountData, ApiMap, AuthRequestV2, BalanceItem, BalanceJson, BrowserConfirmationType, ChainStakingMetadata, ConfirmationsQueue, CrowdloanItem, CrowdloanJson, CurrentAccountInfo, EvmSendTransactionParams, ExternalRequestPromise, MantaPayConfig, NftCollection, NftItem, NftJson, NominatorMetadata, RequestAccountExportPrivateKey, RequestCheckPublicAndSecretKey, RequestConfirmationComplete, RequestSettingsType, ResponseAccountExportPrivateKey, ResponseCheckPublicAndSecretKey, ServiceInfo, SingleModeJson, StakingItem, StakingJson, StakingRewardItem, StakingRewardJson, StakingType, ThemeNames, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
3
+ import { AddTokenRequestExternal, AmountData, ApiMap, AuthRequestV2, BalanceItem, BalanceJson, ChainStakingMetadata, ConfirmationsQueue, CrowdloanItem, CrowdloanJson, CurrentAccountInfo, EvmSendTransactionParams, ExternalRequestPromise, MantaPayConfig, 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
6
  import { ChainService } from '@subwallet/extension-base/services/chain-service';
@@ -138,11 +138,7 @@ export default class KoniState {
138
138
  get signSubject(): BehaviorSubject<import("@subwallet/extension-base/background/types").SigningRequest[]>;
139
139
  getSettings(callback: (settings: UiSettings) => void): void;
140
140
  setSettings(settings: UiSettings, callback?: () => void): void;
141
- setTheme(theme: ThemeNames, callback?: (settingData: UiSettings) => void): void;
142
- setBrowserConfirmationType(browserConfirmationType: BrowserConfirmationType, callback?: (settingData: UiSettings) => void): void;
143
- setCamera(value: boolean): void;
144
- setAutoLockTime(value: number): void;
145
- setEnableChainPatrol(value: boolean): void;
141
+ updateSetting<T extends keyof UiSettings>(key: T, value: UiSettings[T]): void;
146
142
  subscribeSettingsSubject(): Subject<RequestSettingsType>;
147
143
  getAccountAddress(): string | null;
148
144
  getDecodedAddresses(address?: string): string[];
@@ -605,51 +605,11 @@ export default class KoniState {
605
605
  setSettings(settings, callback) {
606
606
  this.settingService.setSettings(settings, callback);
607
607
  }
608
- setTheme(theme, callback) {
608
+ updateSetting(key, value) {
609
609
  this.settingService.getSettings(settings => {
610
610
  const newSettings = {
611
611
  ...settings,
612
- theme
613
- };
614
- this.settingService.setSettings(newSettings, () => {
615
- callback && callback(newSettings);
616
- });
617
- });
618
- }
619
- setBrowserConfirmationType(browserConfirmationType, callback) {
620
- this.settingService.getSettings(settings => {
621
- const newSettings = {
622
- ...settings,
623
- browserConfirmationType
624
- };
625
- this.settingService.setSettings(newSettings, () => {
626
- callback && callback(newSettings);
627
- });
628
- });
629
- }
630
- setCamera(value) {
631
- this.settingService.getSettings(settings => {
632
- const newSettings = {
633
- ...settings,
634
- camera: value
635
- };
636
- this.settingService.setSettings(newSettings);
637
- });
638
- }
639
- setAutoLockTime(value) {
640
- this.settingService.getSettings(settings => {
641
- const newSettings = {
642
- ...settings,
643
- timeAutoLock: value
644
- };
645
- this.settingService.setSettings(newSettings);
646
- });
647
- }
648
- setEnableChainPatrol(value) {
649
- this.settingService.getSettings(settings => {
650
- const newSettings = {
651
- ...settings,
652
- enableChainPatrol: value
612
+ [key]: value
653
613
  };
654
614
  this.settingService.setSettings(newSettings);
655
615
  });
@@ -1535,10 +1495,13 @@ export default class KoniState {
1535
1495
  });
1536
1496
  }
1537
1497
  async reloadNft() {
1498
+ const currentAddress = this.keyringService.currentAccount.address;
1499
+ await this.dbService.removeNftsByAddress(currentAddress);
1538
1500
  return await this.cron.reloadNft();
1539
1501
  }
1540
1502
  async reloadStaking() {
1541
- return await this.cron.reloadStaking();
1503
+ await this.subscription.reloadStaking();
1504
+ return true;
1542
1505
  }
1543
1506
  async approvePassPhishingPage(_url) {
1544
1507
  return new Promise(resolve => {