import { ChainStore } from "./chain" ; import { AnalyticsStore } from "./analytics" ; import { EmbedChainInfos } from "../config" ; import { FiatCurrencies } from "../config.ui" ; import { KeyRingStore , InteractionStore , QueriesStore , CoinGeckoPriceStore , AccountStore , PermissionStore , SignInteractionStore , LedgerInitStore , TokensStore , ChainSuggestStore , IBCChannelStore , IBCCurrencyRegsitrar , QueriesWithCosmosAndSecretAndCosmwasm , AccountWithAll , getKeplrFromWindow , } from "@keplr-wallet/stores" ; import { ExtensionKVStore } from "@keplr-wallet/common" ; import { ExtensionRouter , ContentScriptEnv , ContentScriptGuards , InExtensionMessageRequester , } from "@keplr-wallet/router-extension" ; import { APP_PORT } from "@keplr-wallet/router" ; import { ChainInfoWithEmbed } from "@keplr-wallet/background" ; import { FiatCurrency } from "@keplr-wallet/types" ; import { UIConfigStore } from "./ui-config" ; export class RootStore { public readonly uiConfigStore : UIConfigStore ; public readonly chainStore : ChainStore ; public readonly keyRingStore : KeyRingStore ; public readonly ibcChannelStore : IBCChannelStore ; protected readonly interactionStore : InteractionStore ; public readonly permissionStore : PermissionStore ; public readonly signInteractionStore : SignInteractionStore ; public readonly ledgerInitStore : LedgerInitStore ; public readonly chainSuggestStore : ChainSuggestStore ; public readonly queriesStore : QueriesStore < QueriesWithCosmosAndSecretAndCosmwasm > ; public readonly accountStore : AccountStore < AccountWithAll > ; public readonly priceStore : CoinGeckoPriceStore ; public readonly tokensStore : TokensStore < ChainInfoWithEmbed > ; public readonly analyticsStore : AnalyticsStore ; protected readonly ibcCurrencyRegistrar : IBCCurrencyRegsitrar < ChainInfoWithEmbed > ; constructor ( ) { this . uiConfigStore = new UIConfigStore ( new ExtensionKVStore ( "store_ui_config" ) ) ; const router = new ExtensionRouter ( ContentScriptEnv . produceEnv ) ; router . addGuard ( ContentScriptGuards . checkMessageIsInternal ) ; this . interactionStore = new InteractionStore ( router , new InExtensionMessageRequester ( ) ) ; this . chainStore = new ChainStore ( EmbedChainInfos , new InExtensionMessageRequester ( ) ) ; this . keyRingStore = new KeyRingStore ( { dispatchEvent : ( type ) => { window . dispatchEvent ( new Event ( type ) ) ; } , } , "scrypt" , this . chainStore , new InExtensionMessageRequester ( ) , this . interactionStore ) ; this . ibcChannelStore = new IBCChannelStore ( new ExtensionKVStore ( "store_ibc_channel" ) ) ; this . permissionStore = new PermissionStore ( this . interactionStore , new InExtensionMessageRequester ( ) ) ; this . signInteractionStore = new SignInteractionStore ( this . interactionStore ) ; this . ledgerInitStore = new LedgerInitStore ( this . interactionStore , new InExtensionMessageRequester ( ) ) ; this . chainSuggestStore = new ChainSuggestStore ( this . interactionStore ) ; this . queriesStore = new QueriesStore ( new ExtensionKVStore ( "store_queries" ) , this . chainStore , getKeplrFromWindow , QueriesWithCosmosAndSecretAndCosmwasm ) ; const chainOpts = this . chainStore . chainInfos . map ( ( chainInfo ) => { if ( chainInfo . chainId . startsWith ( "shentu-" ) ) { return { chainId : chainInfo . chainId , msgOpts : { send : { native : { type : "bank/MsgSend" , } , } , } , } ; } if ( chainInfo . chainId . startsWith ( "akashnet-" ) || chainInfo . chainId . startsWith ( "sifchain" ) ) { return { chainId : chainInfo . chainId , msgOpts : { send : { native : { gas : 120000 , } , } , } , } ; } if ( chainInfo . chainId . startsWith ( "secret-" ) ) { return { chainId : chainInfo . chainId , msgOpts : { send : { native : { gas : 20000 , } , secret20 : { gas : 50000 , } , } , withdrawRewards : { gas : 25000 , } , createSecret20ViewingKey : { gas : 50000 , } , } , } ; } return { chainId : chainInfo . chainId } ; } ) ; chainOpts . push ( { chainId : "bombay-12" , prefetching : false , msgOpts : { send : { native : { type : "bank/MsgSend" , } , } , } , } , { chainId : "columbus-5" , prefetching : false , msgOpts : { send : { native : { type : "bank/MsgSend" , } , } , } , } ) ; this . accountStore = new AccountStore ( window , AccountWithAll , this . chainStore , this . queriesStore , { defaultOpts : { prefetching : ! window . location . href . includes ( "#/unlock" ) , suggestChain : false , autoInit : true , getKeplr : getKeplrFromWindow , } , chainOpts , } ) ; this . priceStore = new CoinGeckoPriceStore ( new ExtensionKVStore ( "store_prices" ) , FiatCurrencies . reduce < { [ vsCurrency ] : FiatCurrency ; } > ( ( obj , fiat ) => { obj [ fiat . currency ] = fiat ; return obj ; } , { } ) , "usd" ) ; this . tokensStore = new TokensStore ( window , this . chainStore , new InExtensionMessageRequester ( ) , this . interactionStore ) ; this . ibcCurrencyRegistrar = new IBCCurrencyRegsitrar < ChainInfoWithEmbed > ( new ExtensionKVStore ( "store_ibc_curreny_registrar" ) , 24 * 3600 * 1000 , this . chainStore , this . accountStore , this . queriesStore ) ; this . analyticsStore = new AnalyticsStore ( "KeplrExtension" , { amplitudeConfig : { platform : "Extension" , includeUtm : true , includeReferrer : true , includeFbclid : true , includeGclid : true , saveEvents : true , saveParamsReferrerOncePerSession : false , } , } , this . accountStore , this . keyRingStore ) ; router . listen ( APP_PORT ) ; } } export function createRootStore ( ) { return new RootStore ( ) ; }