@keplr-wallet/stores 0.12.299 → 0.12.300-rc.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/build/account/babylon.js +19 -7
- package/build/account/babylon.js.map +1 -1
- package/build/account/base.js +7 -5
- package/build/account/base.js.map +1 -1
- package/build/account/cosmos.js +94 -54
- package/build/account/cosmos.js.map +1 -1
- package/build/account/cosmwasm.js +10 -2
- package/build/account/cosmwasm.js.map +1 -1
- package/build/account/secret.js +10 -2
- package/build/account/secret.js.map +1 -1
- package/build/account/store.js +4 -4
- package/build/account/store.js.map +1 -1
- package/build/chain/base.d.ts +122 -1
- package/build/chain/base.js +601 -40
- package/build/chain/base.js.map +1 -1
- package/build/chain/types.d.ts +27 -1
- package/build/common/utils/index.d.ts +2 -2
- package/build/common/utils/index.js.map +1 -1
- package/build/lsm/currency-registrar.js +7 -7
- package/build/lsm/currency-registrar.js.map +1 -1
- package/build/query/balances.js +24 -11
- package/build/query/balances.js.map +1 -1
- package/build/query/chain-query.js +2 -2
- package/build/query/chain-query.js.map +1 -1
- package/build/query/chain-rpc-query.js +2 -2
- package/build/query/chain-rpc-query.js.map +1 -1
- package/build/query/cosmos/balance/balances.js +8 -4
- package/build/query/cosmos/balance/balances.js.map +1 -1
- package/build/query/cosmos/balance/spendable.js +3 -2
- package/build/query/cosmos/balance/spendable.js.map +1 -1
- package/build/query/cosmos/ibc/channel.js +3 -2
- package/build/query/cosmos/ibc/channel.js.map +1 -1
- package/build/query/cosmos/ibc/client-state.js +2 -2
- package/build/query/cosmos/ibc/client-state.js.map +1 -1
- package/build/query/cosmos/ibc/denom-trace.js +6 -8
- package/build/query/cosmos/ibc/denom-trace.js.map +1 -1
- package/build/query/cosmos/staking/babylon-btc-delegation-reward.js +3 -2
- package/build/query/cosmos/staking/babylon-btc-delegation-reward.js.map +1 -1
- package/build/query/cosmos/staking/delegations.js +5 -4
- package/build/query/cosmos/staking/delegations.js.map +1 -1
- package/build/query/cosmos/staking/initia-delegations.js +8 -6
- package/build/query/cosmos/staking/initia-delegations.js.map +1 -1
- package/build/query/cosmos/staking/initia-unbonding-delegations.js +6 -5
- package/build/query/cosmos/staking/initia-unbonding-delegations.js.map +1 -1
- package/build/query/cosmos/staking/initia-validators.js +3 -3
- package/build/query/cosmos/staking/initia-validators.js.map +1 -1
- package/build/query/cosmos/staking/pool.js +3 -3
- package/build/query/cosmos/staking/pool.js.map +1 -1
- package/build/query/cosmos/staking/rewards.js +13 -10
- package/build/query/cosmos/staking/rewards.js.map +1 -1
- package/build/query/cosmos/staking/unbonding-delegations.js +3 -3
- package/build/query/cosmos/staking/unbonding-delegations.js.map +1 -1
- package/build/query/cosmos/staking/validators.js +2 -3
- package/build/query/cosmos/staking/validators.js.map +1 -1
- package/build/query/cosmwasm/contract-query.js +2 -2
- package/build/query/cosmwasm/contract-query.js.map +1 -1
- package/build/query/cosmwasm/cw20-balance.js +7 -4
- package/build/query/cosmwasm/cw20-balance.js.map +1 -1
- package/build/query/cosmwasm/neutron/staking-rewards.js +10 -8
- package/build/query/cosmwasm/neutron/staking-rewards.js.map +1 -1
- package/build/query/noble/swap/simulate-swap.js +1 -1
- package/build/query/noble/swap/simulate-swap.js.map +1 -1
- package/build/query/osmosis/txfees/fee-tokens/index.js +8 -4
- package/build/query/osmosis/txfees/fee-tokens/index.js.map +1 -1
- package/build/query/secret-wasm/secret20-balance.js +7 -5
- package/build/query/secret-wasm/secret20-balance.js.map +1 -1
- package/build/token-factory/currency-registrar.js +1 -1
- package/build/token-factory/currency-registrar.js.map +1 -1
- package/package.json +11 -11
- package/src/account/babylon.ts +21 -7
- package/src/account/base.ts +7 -5
- package/src/account/cosmos.ts +121 -66
- package/src/account/cosmwasm.ts +12 -3
- package/src/account/secret.ts +12 -3
- package/src/account/store.ts +4 -4
- package/src/chain/base.ts +816 -34
- package/src/chain/types.ts +27 -1
- package/src/common/utils/index.ts +2 -2
- package/src/lsm/currency-registrar.ts +9 -7
- package/src/query/balances.ts +30 -13
- package/src/query/chain-query.ts +6 -2
- package/src/query/chain-rpc-query.ts +6 -2
- package/src/query/cosmos/balance/balances.ts +8 -4
- package/src/query/cosmos/balance/spendable.ts +3 -3
- package/src/query/cosmos/ibc/channel.ts +5 -2
- package/src/query/cosmos/ibc/client-state.ts +2 -2
- package/src/query/cosmos/ibc/denom-trace.ts +7 -7
- package/src/query/cosmos/staking/babylon-btc-delegation-reward.ts +5 -2
- package/src/query/cosmos/staking/delegations.ts +9 -4
- package/src/query/cosmos/staking/initia-delegations.ts +14 -7
- package/src/query/cosmos/staking/initia-unbonding-delegations.ts +12 -6
- package/src/query/cosmos/staking/initia-validators.ts +5 -3
- package/src/query/cosmos/staking/pool.ts +3 -3
- package/src/query/cosmos/staking/rewards.ts +13 -10
- package/src/query/cosmos/staking/unbonding-delegations.ts +7 -3
- package/src/query/cosmos/staking/validators.ts +4 -3
- package/src/query/cosmwasm/contract-query.ts +4 -2
- package/src/query/cosmwasm/cw20-balance.ts +8 -5
- package/src/query/cosmwasm/neutron/staking-rewards.ts +10 -8
- package/src/query/noble/swap/simulate-swap.ts +1 -1
- package/src/query/osmosis/txfees/fee-tokens/index.ts +8 -4
- package/src/query/secret-wasm/secret20-balance.ts +7 -5
- package/src/token-factory/currency-registrar.ts +1 -1
package/build/chain/base.js
CHANGED
|
@@ -455,27 +455,76 @@ __decorate([
|
|
|
455
455
|
], ChainInfoImpl.prototype, "setEmbeddedChainInfo", null);
|
|
456
456
|
exports.ChainInfoImpl = ChainInfoImpl;
|
|
457
457
|
class ModularChainInfoImpl {
|
|
458
|
+
get unknownDenomMap() {
|
|
459
|
+
return new Map();
|
|
460
|
+
}
|
|
458
461
|
constructor(embedded, currencyRegistry) {
|
|
459
462
|
this.currencyRegistry = currencyRegistry;
|
|
460
463
|
this.registeredCosmosCurrencies = [];
|
|
461
464
|
this.registeredStarkentCurrencies = [];
|
|
462
465
|
this.registeredBitcoinCurrencies = [];
|
|
466
|
+
this.registeredEvmCurrencies = [];
|
|
467
|
+
this.registeredCurrenciesNoReaction = [];
|
|
468
|
+
this.registrationInProgressCurrencyMap = new Map();
|
|
463
469
|
this._embedded = embedded;
|
|
470
|
+
this.availableModules = this.detectAvailableModules();
|
|
464
471
|
(0, mobx_1.makeObservable)(this);
|
|
465
472
|
(0, mobx_utils_1.keepAlive)(this, "cosmosCurrencyMap");
|
|
466
473
|
(0, mobx_utils_1.keepAlive)(this, "starknetCurrencyMap");
|
|
467
474
|
(0, mobx_utils_1.keepAlive)(this, "bitcoinCurrencyMap");
|
|
475
|
+
(0, mobx_utils_1.keepAlive)(this, "evmCurrencyMap");
|
|
476
|
+
}
|
|
477
|
+
detectAvailableModules() {
|
|
478
|
+
const modules = [];
|
|
479
|
+
if ("bitcoin" in this._embedded)
|
|
480
|
+
modules.push("bitcoin");
|
|
481
|
+
if ("starknet" in this._embedded)
|
|
482
|
+
modules.push("starknet");
|
|
483
|
+
if ("evm" in this._embedded)
|
|
484
|
+
modules.push("evm");
|
|
485
|
+
if ("cosmos" in this._embedded)
|
|
486
|
+
modules.push("cosmos");
|
|
487
|
+
return modules;
|
|
468
488
|
}
|
|
469
489
|
get embedded() {
|
|
470
490
|
return this._embedded;
|
|
471
491
|
}
|
|
472
492
|
setEmbeddedModularChainInfo(embedded) {
|
|
473
493
|
this._embedded = embedded;
|
|
494
|
+
this.availableModules = this.detectAvailableModules();
|
|
474
495
|
}
|
|
475
496
|
get chainId() {
|
|
476
497
|
return this._embedded.chainId;
|
|
477
498
|
}
|
|
478
|
-
|
|
499
|
+
get stakeCurrency() {
|
|
500
|
+
return "cosmos" in this._embedded
|
|
501
|
+
? this._embedded.cosmos.stakeCurrency
|
|
502
|
+
: undefined;
|
|
503
|
+
}
|
|
504
|
+
get feeCurrencies() {
|
|
505
|
+
if ("cosmos" in this._embedded) {
|
|
506
|
+
return this._embedded.cosmos.feeCurrencies;
|
|
507
|
+
}
|
|
508
|
+
if ("evm" in this._embedded) {
|
|
509
|
+
return this._embedded.evm.feeCurrencies;
|
|
510
|
+
}
|
|
511
|
+
if ("starknet" in this._embedded) {
|
|
512
|
+
const feeContractAddress = this._embedded.starknet.strkContractAddress;
|
|
513
|
+
const feeCurrency = this.getCurrenciesByModule("starknet").find((cur) => cur.coinMinimalDenom === `erc20:${feeContractAddress}`);
|
|
514
|
+
if (feeCurrency) {
|
|
515
|
+
return [feeCurrency];
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
if ("bitcoin" in this._embedded) {
|
|
519
|
+
return [this._embedded.bitcoin.currencies[0]];
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
getCurrencies() {
|
|
523
|
+
return this.availableModules
|
|
524
|
+
.map((module) => this.getCurrenciesByModule(module))
|
|
525
|
+
.flat();
|
|
526
|
+
}
|
|
527
|
+
getCurrenciesByModule(module) {
|
|
479
528
|
switch (module) {
|
|
480
529
|
case "cosmos":
|
|
481
530
|
if (!("cosmos" in this._embedded)) {
|
|
@@ -492,6 +541,407 @@ class ModularChainInfoImpl {
|
|
|
492
541
|
throw new Error(`No bitcoin module for this chain: ${this.chainId}`);
|
|
493
542
|
}
|
|
494
543
|
return this._embedded.bitcoin.currencies.concat(this.registeredBitcoinCurrencies);
|
|
544
|
+
case "evm":
|
|
545
|
+
if (!("evm" in this._embedded)) {
|
|
546
|
+
throw new Error(`No evm native module for this chain: ${this.chainId}`);
|
|
547
|
+
}
|
|
548
|
+
return this._embedded.evm.currencies.concat(this.registeredEvmCurrencies);
|
|
549
|
+
default:
|
|
550
|
+
throw new Error(`Unknown module: ${module}`);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Currency를 반환한다.
|
|
555
|
+
* 만약 해당 Currency가 없다면 unknownDenomMap에 추가한다.
|
|
556
|
+
* @param coinMinimalDenom
|
|
557
|
+
*/
|
|
558
|
+
findCurrency(coinMinimalDenom) {
|
|
559
|
+
const normalizedDenom = common_1.DenomHelper.normalizeDenom(coinMinimalDenom);
|
|
560
|
+
const currency = this.findCurrencyByModule(normalizedDenom);
|
|
561
|
+
if (currency) {
|
|
562
|
+
return currency;
|
|
563
|
+
}
|
|
564
|
+
this.availableModules.forEach((module) => {
|
|
565
|
+
// 동적으로 토큰을 발견하고 등록하는 절차는 cosmos, evm 모듈에서만 지원
|
|
566
|
+
if (module === "cosmos" || module === "evm") {
|
|
567
|
+
this.addUnknownDenomsImpl({
|
|
568
|
+
module,
|
|
569
|
+
coinMinimalDenoms: [normalizedDenom],
|
|
570
|
+
reaction: true,
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
// Unknown denom can be registered synchronously in some cases.
|
|
575
|
+
// For this case, re-try to get currency.
|
|
576
|
+
return this.findCurrencyByModule(normalizedDenom);
|
|
577
|
+
}
|
|
578
|
+
findCurrencyByModule(denom) {
|
|
579
|
+
for (const module of this.availableModules) {
|
|
580
|
+
const currency = this.getCurrencyMapByModule(module).get(denom);
|
|
581
|
+
if (currency) {
|
|
582
|
+
return currency;
|
|
583
|
+
}
|
|
584
|
+
if (module === "cosmos" || module === "evm") {
|
|
585
|
+
const noReactionCurrency = this.currencyMapNoReaction.get(denom);
|
|
586
|
+
if (noReactionCurrency) {
|
|
587
|
+
return noReactionCurrency;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
return undefined;
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* findCurrency와 비슷하지만 해당하는 currency가 존재하지 않을 경우 raw currency를 반환한다.
|
|
595
|
+
* @param coinMinimalDenom
|
|
596
|
+
*/
|
|
597
|
+
forceFindCurrency(coinMinimalDenom) {
|
|
598
|
+
const normalizedCoinMinimalDenom = common_1.DenomHelper.normalizeDenom(coinMinimalDenom);
|
|
599
|
+
const currency = this.findCurrency(coinMinimalDenom);
|
|
600
|
+
if (currency) {
|
|
601
|
+
return currency;
|
|
602
|
+
}
|
|
603
|
+
return this.getRawCurrency(normalizedCoinMinimalDenom);
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* 최적화를 위해 reaction 없이 currency를 조회한다.
|
|
607
|
+
* 현재는 IBC asset에서만 사용되고 있어 Cosmos 모듈만 지원한다.
|
|
608
|
+
* @param coinMinimalDenom
|
|
609
|
+
*/
|
|
610
|
+
findCurrencyWithoutReaction(coinMinimalDenom) {
|
|
611
|
+
const normalizedCoinMinimalDenom = common_1.DenomHelper.normalizeDenom(coinMinimalDenom);
|
|
612
|
+
const currency = this.findCurrencyByModule(normalizedCoinMinimalDenom);
|
|
613
|
+
if (currency) {
|
|
614
|
+
return currency;
|
|
615
|
+
}
|
|
616
|
+
this.availableModules.forEach((module) => {
|
|
617
|
+
if (module === "cosmos" || module === "evm") {
|
|
618
|
+
this.addUnknownDenomsImpl({
|
|
619
|
+
module,
|
|
620
|
+
coinMinimalDenoms: [normalizedCoinMinimalDenom],
|
|
621
|
+
reaction: false,
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
});
|
|
625
|
+
// Unknown denom can be registered synchronously in some cases.
|
|
626
|
+
// For this case, re-try to get currency.
|
|
627
|
+
return this.findCurrencyByModule(normalizedCoinMinimalDenom);
|
|
628
|
+
}
|
|
629
|
+
findCurrencyAsync(coinMinimalDenom) {
|
|
630
|
+
const normalizedCoinMinimalDenom = common_1.DenomHelper.normalizeDenom(coinMinimalDenom);
|
|
631
|
+
const currency = this.findCurrencyByModule(normalizedCoinMinimalDenom);
|
|
632
|
+
if (currency) {
|
|
633
|
+
return Promise.resolve(currency);
|
|
634
|
+
}
|
|
635
|
+
this.availableModules.forEach((module) => {
|
|
636
|
+
if (module === "cosmos" || module === "evm") {
|
|
637
|
+
this.addUnknownDenomsImpl({
|
|
638
|
+
module,
|
|
639
|
+
coinMinimalDenoms: [normalizedCoinMinimalDenom],
|
|
640
|
+
reaction: true,
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
let disposal;
|
|
645
|
+
return new Promise((resolve) => {
|
|
646
|
+
disposal = (0, mobx_1.autorun)(() => {
|
|
647
|
+
const registration = this.registrationInProgressCurrencyMap.get(normalizedCoinMinimalDenom);
|
|
648
|
+
if (!registration) {
|
|
649
|
+
const result = this.findCurrencyByModule(normalizedCoinMinimalDenom);
|
|
650
|
+
resolve(result);
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
}).finally(() => {
|
|
654
|
+
if (disposal) {
|
|
655
|
+
disposal();
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
forceFindCurrencyWithoutReaction(coinMinimalDenom) {
|
|
660
|
+
const normalizedCoinMinimalDenom = common_1.DenomHelper.normalizeDenom(coinMinimalDenom);
|
|
661
|
+
const currency = this.findCurrencyWithoutReaction(normalizedCoinMinimalDenom);
|
|
662
|
+
if (currency) {
|
|
663
|
+
return currency;
|
|
664
|
+
}
|
|
665
|
+
return this.getRawCurrency(normalizedCoinMinimalDenom);
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* raw currency를 반환한다. ref을 유지하기 위해서 cache를 사용한다.
|
|
669
|
+
*/
|
|
670
|
+
getRawCurrency(denom) {
|
|
671
|
+
if (forceFindCurrencyCache.has(denom)) {
|
|
672
|
+
return forceFindCurrencyCache.get(denom);
|
|
673
|
+
}
|
|
674
|
+
const currency = {
|
|
675
|
+
coinMinimalDenom: denom,
|
|
676
|
+
coinDenom: denom,
|
|
677
|
+
coinDecimals: 0,
|
|
678
|
+
};
|
|
679
|
+
forceFindCurrencyCache.set(denom, currency);
|
|
680
|
+
return currency;
|
|
681
|
+
}
|
|
682
|
+
addUnknownDenoms({ module, coinMinimalDenoms, }) {
|
|
683
|
+
this.addUnknownDenomsImpl({
|
|
684
|
+
module,
|
|
685
|
+
coinMinimalDenoms,
|
|
686
|
+
reaction: true,
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
addUnknownDenomsWithoutReaction({ module, coinMinimalDenoms, }) {
|
|
690
|
+
this.addUnknownDenomsImpl({
|
|
691
|
+
module,
|
|
692
|
+
coinMinimalDenoms,
|
|
693
|
+
reaction: false,
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
/**
|
|
697
|
+
* 해당되는 denom의 currency를 모를 때 이 메소드를 사용해서 등록을 요청할 수 있다.
|
|
698
|
+
*
|
|
699
|
+
* - balance 쿼리 결과 등에서 모르는 denom이 나타날 때
|
|
700
|
+
* - IBC denom을 동적으로 등록해야 할 때
|
|
701
|
+
* ---
|
|
702
|
+
* - action 데코레이터가 사용되지 않은 이유: action 내부에서 autorun을 생성하면, autorun의 첫 실행이 action이 끝날 때까지 지연된다.
|
|
703
|
+
* autorun을 사용하는 startCurrencyRegistration 내부에서 불필요한 지연이 발생할 수 있어 action 없이 구현하여 autorun을 즉시 실행한다.
|
|
704
|
+
* 하지만 이 메소드를 action 안에서 호출하게 되는 경우가 있다면 여전히 즉시 실행되지 않으므로 고려가 필요하다.
|
|
705
|
+
*/
|
|
706
|
+
addUnknownDenomsImpl({ module, coinMinimalDenoms, reaction, }) {
|
|
707
|
+
for (const coinMinimalDenom of coinMinimalDenoms) {
|
|
708
|
+
const normalizedDenom = common_1.DenomHelper.normalizeDenom(coinMinimalDenom);
|
|
709
|
+
// 이미 등록 중인 경우 reaction 모드만 업데이트하고 스킵
|
|
710
|
+
if (this.shouldSkipUnknownDenom(normalizedDenom, reaction)) {
|
|
711
|
+
continue;
|
|
712
|
+
}
|
|
713
|
+
// 이미 currency가 존재하면 스킵
|
|
714
|
+
if (reaction &&
|
|
715
|
+
this.getCurrencyMapByModule(module).has(normalizedDenom)) {
|
|
716
|
+
continue;
|
|
717
|
+
}
|
|
718
|
+
// noreaction 맵 확인
|
|
719
|
+
if (!reaction && this.currencyMapNoReaction.has(normalizedDenom)) {
|
|
720
|
+
continue;
|
|
721
|
+
}
|
|
722
|
+
// unknownDenomMap에 등록 및 등록진행중 상태로 변경
|
|
723
|
+
const isNewUnknownDenom = this.addToUnknownDenomMapAndReturnIsNew(normalizedDenom, reaction);
|
|
724
|
+
// 새로운 unknown denom인 경우에만 autorun 시작
|
|
725
|
+
if (isNewUnknownDenom) {
|
|
726
|
+
this.startCurrencyRegistration(module, normalizedDenom);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
// module별 currency map 제공
|
|
731
|
+
getCurrencyMapByModule(module) {
|
|
732
|
+
switch (module) {
|
|
733
|
+
case "cosmos":
|
|
734
|
+
return this.cosmosCurrencyMap;
|
|
735
|
+
case "starknet":
|
|
736
|
+
return this.starknetCurrencyMap;
|
|
737
|
+
case "bitcoin":
|
|
738
|
+
return this.bitcoinCurrencyMap;
|
|
739
|
+
case "evm":
|
|
740
|
+
return this.evmCurrencyMap;
|
|
741
|
+
default:
|
|
742
|
+
throw new Error(`Unknown module: ${module}`);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* 이미 등록 중인 unknown denom인지 체크하고, reaction 업데이트
|
|
747
|
+
*/
|
|
748
|
+
shouldSkipUnknownDenom(normalizedDenom, reaction) {
|
|
749
|
+
const prior = this.unknownDenomMap.get(normalizedDenom);
|
|
750
|
+
if (!prior) {
|
|
751
|
+
return false;
|
|
752
|
+
}
|
|
753
|
+
// 같은 reaction 모드면 스킵
|
|
754
|
+
if (prior.reaction === reaction) {
|
|
755
|
+
return true;
|
|
756
|
+
}
|
|
757
|
+
// noReaction을 reaction으로 변경하는 경우
|
|
758
|
+
if (reaction) {
|
|
759
|
+
// 로직상 reaction은 reactive할 필요가 없기 때문에 직접 변경
|
|
760
|
+
prior.reaction = reaction;
|
|
761
|
+
}
|
|
762
|
+
return true;
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* unknownDenomMap에 등록 및 등록진행중 상태로 변경
|
|
766
|
+
* @returns 새로 추가된 경우 true, 이미 있던 경우 false
|
|
767
|
+
*/
|
|
768
|
+
addToUnknownDenomMapAndReturnIsNew(denom, reaction) {
|
|
769
|
+
const prior = this.unknownDenomMap.get(denom);
|
|
770
|
+
if (prior) {
|
|
771
|
+
return false; // 이미 존재하면 새로 추가하지 않음
|
|
772
|
+
}
|
|
773
|
+
(0, mobx_1.runInAction)(() => {
|
|
774
|
+
this.unknownDenomMap.set(denom, {
|
|
775
|
+
denom: denom,
|
|
776
|
+
reaction,
|
|
777
|
+
});
|
|
778
|
+
this.registrationInProgressCurrencyMap.set(denom, true);
|
|
779
|
+
});
|
|
780
|
+
return true;
|
|
781
|
+
}
|
|
782
|
+
startCurrencyRegistration(module, denom) {
|
|
783
|
+
let i = 0;
|
|
784
|
+
let disposed = false;
|
|
785
|
+
const disposer = (0, mobx_1.autorun)(() => {
|
|
786
|
+
i++;
|
|
787
|
+
// autorun의 첫 실행에서 즉시 dispose하면 disposer가 아직 undefined이므로
|
|
788
|
+
// setTimeout으로 다음 회차로 안전하게 연기
|
|
789
|
+
const dispose = () => {
|
|
790
|
+
disposed = true;
|
|
791
|
+
if (i === 1) {
|
|
792
|
+
// 첫 실행: 다음 회차에 dispose
|
|
793
|
+
setTimeout(() => {
|
|
794
|
+
disposer === null || disposer === void 0 ? void 0 : disposer();
|
|
795
|
+
}, 1);
|
|
796
|
+
}
|
|
797
|
+
else {
|
|
798
|
+
// 두번째 이후: 즉시 dispose
|
|
799
|
+
disposer === null || disposer === void 0 ? void 0 : disposer();
|
|
800
|
+
}
|
|
801
|
+
};
|
|
802
|
+
// 이미 dispose된 경우 리턴
|
|
803
|
+
if (disposed) {
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
const generator = this.currencyRegistry.getCurrencyRegistrar(this.chainId, denom);
|
|
807
|
+
if (generator) {
|
|
808
|
+
this.handleCurrencyRegistration({
|
|
809
|
+
module,
|
|
810
|
+
denom,
|
|
811
|
+
generator,
|
|
812
|
+
dispose,
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
else {
|
|
816
|
+
// registrar가 없으면 등록 불가능
|
|
817
|
+
if (this.registrationInProgressCurrencyMap.get(denom)) {
|
|
818
|
+
(0, mobx_1.runInAction)(() => {
|
|
819
|
+
this.registrationInProgressCurrencyMap.delete(denom);
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
dispose();
|
|
823
|
+
}
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* currency 등록 진행
|
|
828
|
+
*/
|
|
829
|
+
handleCurrencyRegistration(args) {
|
|
830
|
+
const { module, denom, generator, dispose } = args;
|
|
831
|
+
const currency = generator.value;
|
|
832
|
+
(0, mobx_1.runInAction)(() => {
|
|
833
|
+
// 진행 중 상태 업데이트
|
|
834
|
+
if (!generator.done) {
|
|
835
|
+
this.registrationInProgressCurrencyMap.set(denom, true);
|
|
836
|
+
}
|
|
837
|
+
// currency가 있으면 등록
|
|
838
|
+
if (currency) {
|
|
839
|
+
const unknownDenom = this.findAndRemoveUnknownDenom(denom, generator.done);
|
|
840
|
+
// reaction 모드에 따라 적절한 메서드로 추가
|
|
841
|
+
if (!unknownDenom || unknownDenom.reaction) {
|
|
842
|
+
this.addOrReplaceCurrency(module, currency);
|
|
843
|
+
}
|
|
844
|
+
else {
|
|
845
|
+
this.addOrReplaceCurrencyNoReaction(module, currency);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
// 완료되면 진행 중 상태 제거
|
|
849
|
+
if (generator.done) {
|
|
850
|
+
this.registrationInProgressCurrencyMap.delete(denom);
|
|
851
|
+
}
|
|
852
|
+
});
|
|
853
|
+
// 완료되면 dispose
|
|
854
|
+
if (generator.done) {
|
|
855
|
+
dispose();
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* unknownDenomMap에서 해당 denom 찾고, 완료되었으면 제거
|
|
860
|
+
* @returns 찾은 unknownDenom 정보 (없으면 undefined)
|
|
861
|
+
*/
|
|
862
|
+
findAndRemoveUnknownDenom(denom, shouldRemove) {
|
|
863
|
+
const unknownDenom = this.unknownDenomMap.get(denom);
|
|
864
|
+
if (!unknownDenom) {
|
|
865
|
+
return undefined;
|
|
866
|
+
}
|
|
867
|
+
if (shouldRemove) {
|
|
868
|
+
this.unknownDenomMap.delete(denom);
|
|
869
|
+
}
|
|
870
|
+
return unknownDenom;
|
|
871
|
+
}
|
|
872
|
+
addOrReplaceCurrency(module, currency) {
|
|
873
|
+
const currencyMap = this.getCurrencyMapByModule(module);
|
|
874
|
+
const normalizedCoinMinimalDenom = common_1.DenomHelper.normalizeDenom(currency.coinMinimalDenom);
|
|
875
|
+
const newRegisteredCurrencies = this.getRegisteredCurrencies(module).slice();
|
|
876
|
+
if (currencyMap.has(normalizedCoinMinimalDenom)) {
|
|
877
|
+
const index = newRegisteredCurrencies.findIndex((cur) => cur.coinMinimalDenom === normalizedCoinMinimalDenom);
|
|
878
|
+
if (index >= 0) {
|
|
879
|
+
const prev = newRegisteredCurrencies[index];
|
|
880
|
+
if (
|
|
881
|
+
// If same, do nothing
|
|
882
|
+
(0, common_1.sortedJsonByKeyStringify)(prev) !== (0, common_1.sortedJsonByKeyStringify)(currency)) {
|
|
883
|
+
newRegisteredCurrencies.splice(index, 1, currency);
|
|
884
|
+
this.replaceRegisteredCurrencies(module, newRegisteredCurrencies);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
else {
|
|
889
|
+
newRegisteredCurrencies.push(currency);
|
|
890
|
+
this.replaceRegisteredCurrencies(module, newRegisteredCurrencies);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
addOrReplaceCurrencyNoReaction(module, currency) {
|
|
894
|
+
if (module !== "cosmos" && module !== "evm") {
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
const normalizedCoinMinimalDenom = common_1.DenomHelper.normalizeDenom(currency.coinMinimalDenom);
|
|
898
|
+
const currencyMap = this.getCurrencyMapByModule(module);
|
|
899
|
+
const newRegisteredCurrencies = this.registeredCurrenciesNoReaction.slice();
|
|
900
|
+
if (currencyMap.has(normalizedCoinMinimalDenom)) {
|
|
901
|
+
const index = newRegisteredCurrencies.findIndex((cur) => cur.coinMinimalDenom === normalizedCoinMinimalDenom);
|
|
902
|
+
if (index >= 0) {
|
|
903
|
+
const prev = newRegisteredCurrencies[index];
|
|
904
|
+
if (
|
|
905
|
+
// If same, do nothing
|
|
906
|
+
(0, common_1.sortedJsonByKeyStringify)(prev) !== (0, common_1.sortedJsonByKeyStringify)(currency)) {
|
|
907
|
+
newRegisteredCurrencies.splice(index, 1, currency);
|
|
908
|
+
this.registeredCurrenciesNoReaction = newRegisteredCurrencies;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
else {
|
|
913
|
+
newRegisteredCurrencies.push(currency);
|
|
914
|
+
this.registeredCurrenciesNoReaction = newRegisteredCurrencies;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
getRegisteredCurrencies(module) {
|
|
918
|
+
switch (module) {
|
|
919
|
+
case "cosmos":
|
|
920
|
+
return this.registeredCosmosCurrencies;
|
|
921
|
+
case "starknet":
|
|
922
|
+
return this.registeredStarkentCurrencies;
|
|
923
|
+
case "bitcoin":
|
|
924
|
+
return this.registeredBitcoinCurrencies;
|
|
925
|
+
case "evm":
|
|
926
|
+
return this.registeredEvmCurrencies;
|
|
927
|
+
default:
|
|
928
|
+
throw new Error(`Unknown module: ${module}`);
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
replaceRegisteredCurrencies(module, currencies) {
|
|
932
|
+
switch (module) {
|
|
933
|
+
case "cosmos":
|
|
934
|
+
this.registeredCosmosCurrencies = currencies;
|
|
935
|
+
break;
|
|
936
|
+
case "starknet":
|
|
937
|
+
this.registeredStarkentCurrencies = currencies;
|
|
938
|
+
break;
|
|
939
|
+
case "bitcoin":
|
|
940
|
+
this.registeredBitcoinCurrencies = currencies;
|
|
941
|
+
break;
|
|
942
|
+
case "evm":
|
|
943
|
+
this.registeredEvmCurrencies = currencies;
|
|
944
|
+
break;
|
|
495
945
|
default:
|
|
496
946
|
throw new Error(`Unknown module: ${module}`);
|
|
497
947
|
}
|
|
@@ -536,6 +986,17 @@ class ModularChainInfoImpl {
|
|
|
536
986
|
}
|
|
537
987
|
}
|
|
538
988
|
break;
|
|
989
|
+
case "evm":
|
|
990
|
+
if (!("evm" in this._embedded)) {
|
|
991
|
+
throw new Error(`No evm module for this chain: ${this.chainId}`);
|
|
992
|
+
}
|
|
993
|
+
for (const currency of currencies) {
|
|
994
|
+
const normalizedCoinMinimalDenom = common_1.DenomHelper.normalizeDenom(currency.coinMinimalDenom);
|
|
995
|
+
if (!this.evmCurrencyMap.has(normalizedCoinMinimalDenom)) {
|
|
996
|
+
this.registeredEvmCurrencies.push(currency);
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
break;
|
|
539
1000
|
default:
|
|
540
1001
|
throw new Error(`Unknown module: ${module}`);
|
|
541
1002
|
}
|
|
@@ -570,6 +1031,12 @@ class ModularChainInfoImpl {
|
|
|
570
1031
|
this.registeredBitcoinCurrencies =
|
|
571
1032
|
this.registeredBitcoinCurrencies.filter((currency) => !map.get(currency.coinMinimalDenom));
|
|
572
1033
|
break;
|
|
1034
|
+
case "evm":
|
|
1035
|
+
if (!("evm" in this._embedded)) {
|
|
1036
|
+
throw new Error(`No evm module for this chain: ${this.chainId}`);
|
|
1037
|
+
}
|
|
1038
|
+
this.registeredEvmCurrencies = this.registeredEvmCurrencies.filter((currency) => !map.get(currency.coinMinimalDenom));
|
|
1039
|
+
break;
|
|
573
1040
|
default:
|
|
574
1041
|
throw new Error(`Unknown module: ${module}`);
|
|
575
1042
|
}
|
|
@@ -581,6 +1048,16 @@ class ModularChainInfoImpl {
|
|
|
581
1048
|
result.set(currency.coinMinimalDenom, currency);
|
|
582
1049
|
}
|
|
583
1050
|
}
|
|
1051
|
+
for (const currency of this.registeredCosmosCurrencies) {
|
|
1052
|
+
result.set(common_1.DenomHelper.normalizeDenom(currency.coinMinimalDenom), currency);
|
|
1053
|
+
}
|
|
1054
|
+
return result;
|
|
1055
|
+
}
|
|
1056
|
+
get currencyMapNoReaction() {
|
|
1057
|
+
const result = new Map();
|
|
1058
|
+
for (const currency of this.registeredCurrenciesNoReaction) {
|
|
1059
|
+
result.set(currency.coinMinimalDenom, currency);
|
|
1060
|
+
}
|
|
584
1061
|
return result;
|
|
585
1062
|
}
|
|
586
1063
|
get starknetCurrencyMap() {
|
|
@@ -590,6 +1067,9 @@ class ModularChainInfoImpl {
|
|
|
590
1067
|
result.set(currency.coinMinimalDenom, currency);
|
|
591
1068
|
}
|
|
592
1069
|
}
|
|
1070
|
+
for (const currency of this.registeredStarkentCurrencies) {
|
|
1071
|
+
result.set(common_1.DenomHelper.normalizeDenom(currency.coinMinimalDenom), currency);
|
|
1072
|
+
}
|
|
593
1073
|
return result;
|
|
594
1074
|
}
|
|
595
1075
|
get bitcoinCurrencyMap() {
|
|
@@ -599,8 +1079,51 @@ class ModularChainInfoImpl {
|
|
|
599
1079
|
result.set(currency.coinMinimalDenom, currency);
|
|
600
1080
|
}
|
|
601
1081
|
}
|
|
1082
|
+
for (const currency of this.registeredBitcoinCurrencies) {
|
|
1083
|
+
result.set(common_1.DenomHelper.normalizeDenom(currency.coinMinimalDenom), currency);
|
|
1084
|
+
}
|
|
602
1085
|
return result;
|
|
603
1086
|
}
|
|
1087
|
+
get evmCurrencyMap() {
|
|
1088
|
+
const result = new Map();
|
|
1089
|
+
if ("evm" in this._embedded) {
|
|
1090
|
+
for (const currency of this._embedded.evm.currencies) {
|
|
1091
|
+
result.set(common_1.DenomHelper.normalizeDenom(currency.coinMinimalDenom), currency);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
for (const currency of this.registeredEvmCurrencies) {
|
|
1095
|
+
result.set(common_1.DenomHelper.normalizeDenom(currency.coinMinimalDenom), currency);
|
|
1096
|
+
}
|
|
1097
|
+
return result;
|
|
1098
|
+
}
|
|
1099
|
+
hasFeature(feature) {
|
|
1100
|
+
var _a, _b;
|
|
1101
|
+
if ("evm" in this._embedded) {
|
|
1102
|
+
return !!("features" in this._embedded.evm &&
|
|
1103
|
+
((_a = this._embedded.evm.features) === null || _a === void 0 ? void 0 : _a.includes(feature)));
|
|
1104
|
+
}
|
|
1105
|
+
if ("cosmos" in this._embedded) {
|
|
1106
|
+
return !!("features" in this._embedded.cosmos &&
|
|
1107
|
+
((_b = this._embedded.cosmos.features) === null || _b === void 0 ? void 0 : _b.includes(feature)));
|
|
1108
|
+
}
|
|
1109
|
+
return false;
|
|
1110
|
+
}
|
|
1111
|
+
isCurrencyRegistrationInProgress(coinMinimalDenom) {
|
|
1112
|
+
return (this.registrationInProgressCurrencyMap.get(coinMinimalDenom) || false);
|
|
1113
|
+
}
|
|
1114
|
+
/**
|
|
1115
|
+
* @description Check if the chain matches the given modules. Either `or` or `and` condition must be provided.
|
|
1116
|
+
* @param or - If any of the modules in the array is available, return true.
|
|
1117
|
+
* @param and - If all of the modules in the array are available, return true.
|
|
1118
|
+
*/
|
|
1119
|
+
matchModules({ and, or, }) {
|
|
1120
|
+
var _a, _b;
|
|
1121
|
+
return (((_a = or === null || or === void 0 ? void 0 : or.some((module) => this.matchModule(module))) !== null && _a !== void 0 ? _a : true) &&
|
|
1122
|
+
((_b = and === null || and === void 0 ? void 0 : and.every((module) => this.matchModule(module))) !== null && _b !== void 0 ? _b : true));
|
|
1123
|
+
}
|
|
1124
|
+
matchModule(module) {
|
|
1125
|
+
return this.availableModules.includes(module);
|
|
1126
|
+
}
|
|
604
1127
|
}
|
|
605
1128
|
__decorate([
|
|
606
1129
|
mobx_1.observable.ref
|
|
@@ -614,9 +1137,30 @@ __decorate([
|
|
|
614
1137
|
__decorate([
|
|
615
1138
|
mobx_1.observable.shallow
|
|
616
1139
|
], ModularChainInfoImpl.prototype, "registeredBitcoinCurrencies", void 0);
|
|
1140
|
+
__decorate([
|
|
1141
|
+
mobx_1.observable.shallow
|
|
1142
|
+
], ModularChainInfoImpl.prototype, "registeredEvmCurrencies", void 0);
|
|
1143
|
+
__decorate([
|
|
1144
|
+
mobx_1.observable.shallow
|
|
1145
|
+
], ModularChainInfoImpl.prototype, "registeredCurrenciesNoReaction", void 0);
|
|
1146
|
+
__decorate([
|
|
1147
|
+
mobx_1.computed
|
|
1148
|
+
], ModularChainInfoImpl.prototype, "unknownDenomMap", null);
|
|
1149
|
+
__decorate([
|
|
1150
|
+
mobx_1.observable.shallow
|
|
1151
|
+
], ModularChainInfoImpl.prototype, "registrationInProgressCurrencyMap", void 0);
|
|
1152
|
+
__decorate([
|
|
1153
|
+
mobx_1.observable.shallow
|
|
1154
|
+
], ModularChainInfoImpl.prototype, "availableModules", void 0);
|
|
617
1155
|
__decorate([
|
|
618
1156
|
mobx_1.action
|
|
619
1157
|
], ModularChainInfoImpl.prototype, "setEmbeddedModularChainInfo", null);
|
|
1158
|
+
__decorate([
|
|
1159
|
+
mobx_1.action
|
|
1160
|
+
], ModularChainInfoImpl.prototype, "addOrReplaceCurrency", null);
|
|
1161
|
+
__decorate([
|
|
1162
|
+
mobx_1.action
|
|
1163
|
+
], ModularChainInfoImpl.prototype, "addOrReplaceCurrencyNoReaction", null);
|
|
620
1164
|
__decorate([
|
|
621
1165
|
mobx_1.action
|
|
622
1166
|
], ModularChainInfoImpl.prototype, "addCurrencies", null);
|
|
@@ -626,12 +1170,18 @@ __decorate([
|
|
|
626
1170
|
__decorate([
|
|
627
1171
|
mobx_1.computed
|
|
628
1172
|
], ModularChainInfoImpl.prototype, "cosmosCurrencyMap", null);
|
|
1173
|
+
__decorate([
|
|
1174
|
+
mobx_1.computed
|
|
1175
|
+
], ModularChainInfoImpl.prototype, "currencyMapNoReaction", null);
|
|
629
1176
|
__decorate([
|
|
630
1177
|
mobx_1.computed
|
|
631
1178
|
], ModularChainInfoImpl.prototype, "starknetCurrencyMap", null);
|
|
632
1179
|
__decorate([
|
|
633
1180
|
mobx_1.computed
|
|
634
1181
|
], ModularChainInfoImpl.prototype, "bitcoinCurrencyMap", null);
|
|
1182
|
+
__decorate([
|
|
1183
|
+
mobx_1.computed
|
|
1184
|
+
], ModularChainInfoImpl.prototype, "evmCurrencyMap", null);
|
|
635
1185
|
exports.ModularChainInfoImpl = ModularChainInfoImpl;
|
|
636
1186
|
class ChainStore {
|
|
637
1187
|
constructor(embedChainInfos) {
|
|
@@ -644,6 +1194,9 @@ class ChainStore {
|
|
|
644
1194
|
(0, mobx_utils_1.keepAlive)(this, "chainInfoMap");
|
|
645
1195
|
(0, mobx_utils_1.keepAlive)(this, "modularChainInfoMap");
|
|
646
1196
|
}
|
|
1197
|
+
/**
|
|
1198
|
+
* @deprecated Use `modularChainInfos` instead
|
|
1199
|
+
*/
|
|
647
1200
|
get chainInfos() {
|
|
648
1201
|
return this._chainInfos;
|
|
649
1202
|
}
|
|
@@ -660,6 +1213,9 @@ class ChainStore {
|
|
|
660
1213
|
}
|
|
661
1214
|
return result;
|
|
662
1215
|
}
|
|
1216
|
+
/**
|
|
1217
|
+
* @deprecated Use `getmodularChain` or `getModularChainInfoImpl` instead
|
|
1218
|
+
*/
|
|
663
1219
|
getChain(chainId) {
|
|
664
1220
|
const chainIdentifier = cosmos_1.ChainIdHelper.parse(chainId);
|
|
665
1221
|
const chainInfo = this.chainInfoMap.get(chainIdentifier.identifier);
|
|
@@ -668,6 +1224,9 @@ class ChainStore {
|
|
|
668
1224
|
}
|
|
669
1225
|
return chainInfo;
|
|
670
1226
|
}
|
|
1227
|
+
/**
|
|
1228
|
+
* @deprecated Use `hasModularChain` instead
|
|
1229
|
+
*/
|
|
671
1230
|
hasChain(chainId) {
|
|
672
1231
|
const chainIdentifier = cosmos_1.ChainIdHelper.parse(chainId);
|
|
673
1232
|
return this.chainInfoMap.has(chainIdentifier.identifier);
|
|
@@ -726,25 +1285,31 @@ class ChainStore {
|
|
|
726
1285
|
return new ChainInfoImpl(chainInfo, this);
|
|
727
1286
|
});
|
|
728
1287
|
this._modularChainInfos = chainInfos.map((chainInfo) => {
|
|
729
|
-
if ("
|
|
1288
|
+
if ("evm" in chainInfo &&
|
|
1289
|
+
chainInfo.evm &&
|
|
1290
|
+
"currencies" in chainInfo && // clarify if it's ChainInfo type
|
|
1291
|
+
this.isEvmOnlyChainForInit(chainInfo.chainId)) {
|
|
730
1292
|
return {
|
|
731
1293
|
chainId: chainInfo.chainId,
|
|
732
1294
|
chainName: chainInfo.chainName,
|
|
733
1295
|
chainSymbolImageUrl: chainInfo.chainSymbolImageUrl,
|
|
734
|
-
|
|
1296
|
+
isTestnet: chainInfo.isTestnet,
|
|
1297
|
+
isNative: true,
|
|
1298
|
+
evm: Object.assign(Object.assign({}, chainInfo.evm), { currencies: chainInfo.currencies, feeCurrencies: chainInfo.feeCurrencies, bip44: chainInfo.bip44, features: chainInfo.features }),
|
|
735
1299
|
};
|
|
736
1300
|
}
|
|
737
|
-
|
|
1301
|
+
if ("currencies" in chainInfo) {
|
|
1302
|
+
return Object.assign({ chainId: chainInfo.chainId, chainName: chainInfo.chainName, chainSymbolImageUrl: chainInfo.chainSymbolImageUrl, isNative: true, cosmos: chainInfo }, (chainInfo.evm && {
|
|
1303
|
+
evm: Object.assign(Object.assign({}, chainInfo.evm), { currencies: chainInfo.currencies, bip44: chainInfo.bip44 }),
|
|
1304
|
+
}));
|
|
1305
|
+
}
|
|
1306
|
+
return Object.assign(Object.assign({}, chainInfo), { isNative: true });
|
|
738
1307
|
});
|
|
739
1308
|
this._modularChainInfoImpls = chainInfos.map((chainInfo) => {
|
|
740
|
-
const modularChainInfo =
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
chainSymbolImageUrl: chainInfo.chainSymbolImageUrl,
|
|
745
|
-
cosmos: chainInfo,
|
|
746
|
-
}
|
|
747
|
-
: chainInfo;
|
|
1309
|
+
const modularChainInfo = this._modularChainInfos.find((c) => c.chainId === chainInfo.chainId);
|
|
1310
|
+
if (!modularChainInfo) {
|
|
1311
|
+
throw new Error(`Unknown modular chain info: ${chainInfo.chainId}`);
|
|
1312
|
+
}
|
|
748
1313
|
const prev = this.modularChainInfoImplMap.get(cosmos_1.ChainIdHelper.parse(chainInfo.chainId).identifier);
|
|
749
1314
|
if (prev) {
|
|
750
1315
|
prev.setEmbeddedModularChainInfo(modularChainInfo);
|
|
@@ -768,31 +1333,17 @@ class ChainStore {
|
|
|
768
1333
|
if (!cosmos) {
|
|
769
1334
|
throw new Error("Can't find cosmos chain info");
|
|
770
1335
|
}
|
|
771
|
-
return {
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
chainSymbolImageUrl: cosmos.chainSymbolImageUrl,
|
|
775
|
-
cosmos,
|
|
776
|
-
};
|
|
1336
|
+
return Object.assign({ chainId: cosmos.chainId, chainName: cosmos.chainName, chainSymbolImageUrl: cosmos.chainSymbolImageUrl, isNative: chainInfo.isNative || !cosmos.beta, cosmos }, (cosmos.evm && {
|
|
1337
|
+
evm: Object.assign(Object.assign({}, cosmos.evm), { currencies: cosmos.currencies, bip44: cosmos.bip44 }),
|
|
1338
|
+
}));
|
|
777
1339
|
}
|
|
778
1340
|
return chainInfo;
|
|
779
1341
|
});
|
|
780
1342
|
this._modularChainInfoImpls = infos.modulrChainInfos.map((chainInfo) => {
|
|
781
|
-
const modularChainInfo = (() =>
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
throw new Error("Can't find cosmos chain info");
|
|
786
|
-
}
|
|
787
|
-
return {
|
|
788
|
-
chainId: cosmos.chainId,
|
|
789
|
-
chainName: cosmos.chainName,
|
|
790
|
-
chainSymbolImageUrl: cosmos.chainSymbolImageUrl,
|
|
791
|
-
cosmos,
|
|
792
|
-
};
|
|
793
|
-
}
|
|
794
|
-
return chainInfo;
|
|
795
|
-
})();
|
|
1343
|
+
const modularChainInfo = this._modularChainInfos.find((c) => c.chainId === chainInfo.chainId);
|
|
1344
|
+
if (!modularChainInfo) {
|
|
1345
|
+
throw new Error(`Unknown modular chain info: ${chainInfo.chainId}`);
|
|
1346
|
+
}
|
|
796
1347
|
const prev = this.modularChainInfoImplMap.get(cosmos_1.ChainIdHelper.parse(chainInfo.chainId).identifier);
|
|
797
1348
|
if (prev) {
|
|
798
1349
|
prev.setEmbeddedModularChainInfo(modularChainInfo);
|
|
@@ -815,8 +1366,8 @@ class ChainStore {
|
|
|
815
1366
|
this.currencyRegistrars.push(registrar);
|
|
816
1367
|
}
|
|
817
1368
|
isEvmChain(chainId) {
|
|
818
|
-
const chainInfo = this.
|
|
819
|
-
return chainInfo.evm != null;
|
|
1369
|
+
const chainInfo = this.getModularChain(chainId);
|
|
1370
|
+
return "evm" in chainInfo && chainInfo.evm != null;
|
|
820
1371
|
}
|
|
821
1372
|
isEvmOnlyChain(chainId) {
|
|
822
1373
|
const chainIdLikeCAIP2 = chainId.split(":");
|
|
@@ -824,16 +1375,26 @@ class ChainStore {
|
|
|
824
1375
|
chainIdLikeCAIP2.length === 2 &&
|
|
825
1376
|
chainIdLikeCAIP2[0] === "eip155");
|
|
826
1377
|
}
|
|
1378
|
+
// 초기화 시 isEvmOnlyChain 확인하면 _modularChainInfos 할당 전이라 오류가 발생할 수 밖에 없어서 별도 추가
|
|
1379
|
+
isEvmOnlyChainForInit(chainId) {
|
|
1380
|
+
const chainIdLikeCAIP2 = chainId.split(":");
|
|
1381
|
+
return chainIdLikeCAIP2.length === 2 && chainIdLikeCAIP2[0] === "eip155";
|
|
1382
|
+
}
|
|
827
1383
|
isEvmOrEthermintLikeChain(chainId) {
|
|
828
|
-
var _a, _b;
|
|
1384
|
+
var _a, _b, _c, _d;
|
|
829
1385
|
const b = this.isEvmChain(chainId);
|
|
830
1386
|
if (b) {
|
|
831
1387
|
return true;
|
|
832
1388
|
}
|
|
833
|
-
const chainInfo = this.
|
|
834
|
-
const isEthermintLike =
|
|
835
|
-
|
|
836
|
-
|
|
1389
|
+
const chainInfo = this.getModularChain(chainId);
|
|
1390
|
+
const isEthermintLike = ("cosmos" in chainInfo &&
|
|
1391
|
+
(chainInfo.cosmos.bip44.coinType === 60 ||
|
|
1392
|
+
!!((_a = chainInfo.cosmos.features) === null || _a === void 0 ? void 0 : _a.includes("eth-address-gen")) ||
|
|
1393
|
+
!!((_b = chainInfo.cosmos.features) === null || _b === void 0 ? void 0 : _b.includes("eth-key-sign")))) ||
|
|
1394
|
+
("evm" in chainInfo &&
|
|
1395
|
+
(chainInfo.evm.bip44.coinType === 60 ||
|
|
1396
|
+
!!((_c = chainInfo.evm.features) === null || _c === void 0 ? void 0 : _c.includes("eth-address-gen")) ||
|
|
1397
|
+
!!((_d = chainInfo.evm.features) === null || _d === void 0 ? void 0 : _d.includes("eth-key-sign"))));
|
|
837
1398
|
return isEthermintLike;
|
|
838
1399
|
}
|
|
839
1400
|
}
|