diff --git a/packages/mask/src/extension/popups/pages/Wallet/ContractInteraction/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/ContractInteraction/index.tsx index 28cc23efae8d..133fb3bc6204 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/ContractInteraction/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/ContractInteraction/index.tsx @@ -377,7 +377,7 @@ const ContractInteraction = memo(() => { {!isGreaterThan(tokenValueUSD, pow10(9)) ? ( - + ) : null} @@ -412,7 +412,7 @@ const ContractInteraction = memo(() => { - + ) : null} diff --git a/packages/mask/src/extension/popups/pages/Wallet/TokenDetail/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/TokenDetail/index.tsx index 1b4b946a31d4..8b883ee644af 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/TokenDetail/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/TokenDetail/index.tsx @@ -136,7 +136,7 @@ const TokenDetail = memo(() => { /> - +
diff --git a/packages/mask/src/plugin-infra/host.ts b/packages/mask/src/plugin-infra/host.ts index 636505a6f475..8b37170ba81b 100644 --- a/packages/mask/src/plugin-infra/host.ts +++ b/packages/mask/src/plugin-infra/host.ts @@ -20,10 +20,9 @@ import { WalletMessages, WalletRPC } from '../plugins/Wallet/messages' export function createSharedContext(pluginID: string, signal: AbortSignal): Plugin.Shared.SharedContext { return { - createKVStorage(type: 'memory' | 'persistent', name: string, defaultValues: T) { - if (type === 'memory') - return InMemoryStorages.Plugin.createSubScope(`${pluginID}_${name}`, defaultValues, signal) - else return PersistentStorages.Plugin.createSubScope(`${pluginID}_${name}`, defaultValues, signal) + createKVStorage(type: 'memory' | 'persistent', defaultValues: T) { + if (type === 'memory') return InMemoryStorages.Plugin.createSubScope(pluginID, defaultValues, signal) + else return PersistentStorages.Plugin.createSubScope(pluginID, defaultValues, signal) }, nativeType: nativeAPI?.type, diff --git a/packages/mask/src/plugins/PoolTogether/base.tsx b/packages/mask/src/plugins/PoolTogether/base.tsx index 948c07d5d994..94da2f7107a7 100644 --- a/packages/mask/src/plugins/PoolTogether/base.tsx +++ b/packages/mask/src/plugins/PoolTogether/base.tsx @@ -9,7 +9,7 @@ export const base: Plugin.Shared.Definition = { enableRequirement: { architecture: { app: true, web: true }, networks: { type: 'opt-out', networks: {} }, - target: 'stable', + target: 'insider', }, contribution: { postContent: new Set([URL_PATTERN]) }, } diff --git a/packages/mask/src/plugins/Savings/SNSAdaptor/SavingsForm.tsx b/packages/mask/src/plugins/Savings/SNSAdaptor/SavingsForm.tsx index e95fb556534c..478ebdd0b494 100644 --- a/packages/mask/src/plugins/Savings/SNSAdaptor/SavingsForm.tsx +++ b/packages/mask/src/plugins/Savings/SNSAdaptor/SavingsForm.tsx @@ -310,7 +310,7 @@ export function SavingsForm({ chainId, protocol, tab, onClose }: SavingsFormProp ) : ( - ≈ + ≈ {estimatedGas > 0 ? ( + {formatBalance(estimatedGas, 18)} ETH ) : ( diff --git a/packages/mask/src/plugins/Tips/SNSAdaptor/index.tsx b/packages/mask/src/plugins/Tips/SNSAdaptor/index.tsx index a8977d125c60..8800886982fa 100644 --- a/packages/mask/src/plugins/Tips/SNSAdaptor/index.tsx +++ b/packages/mask/src/plugins/Tips/SNSAdaptor/index.tsx @@ -12,7 +12,7 @@ import { TipsEntranceDialog } from './TipsEntranceDialog' const sns: Plugin.SNSAdaptor.Definition = { ...base, init(_, context) { - setupStorage(context.createKVStorage('memory', '', storageDefaultValue)) + setupStorage(context.createKVStorage('memory', storageDefaultValue)) }, ApplicationEntries: [ (() => { diff --git a/packages/mask/src/plugins/Trader/SNSAdaptor/index.tsx b/packages/mask/src/plugins/Trader/SNSAdaptor/index.tsx index 0eba0d4e5d54..53f97f1a3252 100644 --- a/packages/mask/src/plugins/Trader/SNSAdaptor/index.tsx +++ b/packages/mask/src/plugins/Trader/SNSAdaptor/index.tsx @@ -28,7 +28,7 @@ const sns: Plugin.SNSAdaptor.Definition< > = { ...base, init(signal, context) { - setupStorage(context.createKVStorage('persistent', '', storageDefaultValue)) + setupStorage(context.createKVStorage('persistent', storageDefaultValue)) }, SearchResultBox: SearchResultInspector, GlobalInjection: function Component() { diff --git a/packages/mask/src/plugins/Trader/SNSAdaptor/trader/InputTokenPanel.tsx b/packages/mask/src/plugins/Trader/SNSAdaptor/trader/InputTokenPanel.tsx index f3ef7febef83..cef42cd5dec7 100644 --- a/packages/mask/src/plugins/Trader/SNSAdaptor/trader/InputTokenPanel.tsx +++ b/packages/mask/src/plugins/Trader/SNSAdaptor/trader/InputTokenPanel.tsx @@ -182,7 +182,7 @@ export const InputTokenPanel = memo( ), endAdornment: ( - ≈ + ≈ ), }} diff --git a/packages/mask/src/plugins/Trader/SNSAdaptor/trending/TickersTable.tsx b/packages/mask/src/plugins/Trader/SNSAdaptor/trending/TickersTable.tsx index 1a78cd74aa8c..46d64856dc7f 100644 --- a/packages/mask/src/plugins/Trader/SNSAdaptor/trending/TickersTable.tsx +++ b/packages/mask/src/plugins/Trader/SNSAdaptor/trending/TickersTable.tsx @@ -69,11 +69,11 @@ export function TickersTable(props: TickersTableProps) { {ticker.price ? ( - + ) : null} - + {formatElapsed(ticker.updated.getTime())} diff --git a/packages/mask/src/plugins/hooks/usePriceLineChart.ts b/packages/mask/src/plugins/hooks/usePriceLineChart.ts index 201c16690627..79a23beb136c 100644 --- a/packages/mask/src/plugins/hooks/usePriceLineChart.ts +++ b/packages/mask/src/plugins/hooks/usePriceLineChart.ts @@ -10,7 +10,7 @@ export function usePriceLineChart( id: string, opts: { color?: string; sign?: string }, ) { - const { color = 'steelblue', sign = '$' } = opts + const { color = 'steelblue', sign = 'USD' } = opts useLineChart(svgRef, data, dimension, id, { color, diff --git a/packages/plugin-infra/src/types.ts b/packages/plugin-infra/src/types.ts index c601434c8304..5ab8c4eb1e2d 100644 --- a/packages/plugin-infra/src/types.ts +++ b/packages/plugin-infra/src/types.ts @@ -124,11 +124,7 @@ export namespace Plugin.Shared { /** * A lightweight K/V storage used to store some simple data. */ - createKVStorage( - type: 'memory' | 'persistent', - name: string, - defaultValues: T, - ): ScopedStorage + createKVStorage(type: 'memory' | 'persistent', defaultValues: T): ScopedStorage /** The selected account of Mask Wallet */ account: Subscription /** The selected chainId of Mask Wallet */ diff --git a/packages/plugin-infra/src/web3-state/AddressBook.ts b/packages/plugin-infra/src/web3-state/AddressBook.ts index a1e8a4626821..c8ecf4393abd 100644 --- a/packages/plugin-infra/src/web3-state/AddressBook.ts +++ b/packages/plugin-infra/src/web3-state/AddressBook.ts @@ -14,7 +14,7 @@ export class AddressBookState< constructor( protected context: Plugin.Shared.SharedContext, - protected defaultValue: AddressBook, + protected chainIds: ChainId[], protected subscriptions: { chainId?: Subscription }, @@ -24,11 +24,10 @@ export class AddressBookState< formatAddress(a: string): string }, ) { - const { storage } = this.context - .createKVStorage('persistent', 'AddressBook', {}) - .createSubScope('AddressBook', { - value: defaultValue, - }) + const defaultValue = Object.fromEntries(chainIds.map((x) => [x, []] as [ChainId, string[]])) as AddressBook + const { storage } = this.context.createKVStorage('persistent', {}).createSubScope('AddressBook', { + value: defaultValue, + }) this.storage = storage.value if (this.subscriptions.chainId) { diff --git a/packages/plugin-infra/src/web3-state/NameService.ts b/packages/plugin-infra/src/web3-state/NameService.ts index 8a35a60b522e..4c35f0799eed 100644 --- a/packages/plugin-infra/src/web3-state/NameService.ts +++ b/packages/plugin-infra/src/web3-state/NameService.ts @@ -14,7 +14,7 @@ export class NameServiceState< constructor( protected context: Plugin.Shared.SharedContext, - protected defaultValue: DomainBooks, + protected chainIds: ChainId[], protected subscriptions: { chainId?: Subscription }, @@ -24,7 +24,8 @@ export class NameServiceState< formatAddress(a: string): string }, ) { - const { storage } = context.createKVStorage('memory', 'NameService', {}).createSubScope('NameService', { + const defaultValue = Object.fromEntries(chainIds.map((x) => [x, {}])) as DomainBooks + const { storage } = context.createKVStorage('memory', {}).createSubScope('NameService', { value: defaultValue, }) this.storage = storage.value diff --git a/packages/plugin-infra/src/web3-state/Provider.ts b/packages/plugin-infra/src/web3-state/Provider.ts index 49279cfa9571..aa3ef56b8d8d 100644 --- a/packages/plugin-infra/src/web3-state/Provider.ts +++ b/packages/plugin-infra/src/web3-state/Provider.ts @@ -1,6 +1,6 @@ import { clone, first } from 'lodash-unified' import type { Subscription } from 'use-subscription' -import { delay } from '@dimensiondev/kit' +import { delay, getEnumAsArray } from '@dimensiondev/kit' import { EnhanceableSite, ExtensionSite, @@ -38,19 +38,34 @@ export class ProviderState< constructor( protected context: Plugin.Shared.SharedContext, protected providers: Record>, - protected defaultValue: ProviderStorage, ProviderType>, protected options: { isValidAddress(a?: string): boolean isValidChainId(a?: number): boolean isSameAddress(a?: string, b?: string): boolean getDefaultChainId(): ChainId getDefaultNetworkType(): NetworkType + getDefaultProviderType(): ProviderType getNetworkTypeFromChainId(chainId: ChainId): NetworkType }, ) { - const { storage } = this.context - .createKVStorage('memory', 'Provider', {}) - .createSubScope('Provider', defaultValue) + const defaultValue: ProviderStorage, ProviderType> = { + accounts: Object.fromEntries( + Object.keys(providers).map((x) => [ + x, + { + account: '', + chainId: options.getDefaultChainId(), + }, + ]), + ) as Record>, + providers: Object.fromEntries( + [...getEnumAsArray(EnhanceableSite), ...getEnumAsArray(ExtensionSite)].map((x) => [ + x.value, + options.getDefaultProviderType(), + ]), + ) as Record, + } + const { storage } = this.context.createKVStorage('memory', {}).createSubScope('Provider', defaultValue) this.storage = storage this.setupSubscriptions() diff --git a/packages/plugin-infra/src/web3-state/RiskWarning.ts b/packages/plugin-infra/src/web3-state/RiskWarning.ts index 3c368916544d..526c3c7ad573 100644 --- a/packages/plugin-infra/src/web3-state/RiskWarning.ts +++ b/packages/plugin-infra/src/web3-state/RiskWarning.ts @@ -21,7 +21,7 @@ export class RiskWarningState implements Web3RiskWarningState { formatAddress(a: string): string }, ) { - const { storage } = this.context.createKVStorage('memory', 'RiskWarning', {}).createSubScope('RiskWarning', { + const { storage } = this.context.createKVStorage('memory', {}).createSubScope('RiskWarning', { value: {}, }) diff --git a/packages/plugin-infra/src/web3-state/Settings.ts b/packages/plugin-infra/src/web3-state/Settings.ts index 05dd443973fd..e37da9735c70 100644 --- a/packages/plugin-infra/src/web3-state/Settings.ts +++ b/packages/plugin-infra/src/web3-state/Settings.ts @@ -20,7 +20,7 @@ export class SettingsState implements Web3SettingsState { public nonFungibleAssetSourceType?: Subscription constructor(context: Plugin.Shared.SharedContext) { - const { storage } = context.createKVStorage('memory', 'Settings', {}).createSubScope('Settings', { + const { storage } = context.createKVStorage('memory', {}).createSubScope('Settings', { currencyType: CurrencyType.USD, gasOptionType: GasOptionType.NORMAL, fungibleAssetSourceType: SourceType.DeBank, diff --git a/packages/plugin-infra/src/web3-state/Token.ts b/packages/plugin-infra/src/web3-state/Token.ts index 312d003eb0c8..bbe061e4872e 100644 --- a/packages/plugin-infra/src/web3-state/Token.ts +++ b/packages/plugin-infra/src/web3-state/Token.ts @@ -37,7 +37,7 @@ export class TokenState implements Web3TokenState implements Web3TransactionSt constructor( protected context: Plugin.Shared.SharedContext, - protected defaultValue: TransactionStorage, + protected chainIds: ChainId[], protected subscriptions: { account?: Subscription chainId?: Subscription @@ -36,11 +36,13 @@ export class TransactionState implements Web3TransactionSt formatAddress(a: string): string }, ) { - const { storage } = this.context - .createKVStorage('persistent', 'Transaction', {}) - .createSubScope('Transaction', { - value: defaultValue, - }) + const defaultValue = Object.fromEntries(chainIds.map((x) => [x, {}])) as TransactionStorage< + ChainId, + Transaction + > + const { storage } = this.context.createKVStorage('persistent', {}).createSubScope('Transaction', { + value: defaultValue, + }) this.storage = storage.value if (this.subscriptions.chainId && this.subscriptions.account) { diff --git a/packages/plugins/EVM/src/state/AddressBook.ts b/packages/plugins/EVM/src/state/AddressBook.ts index 98aa419b6fd5..4e2c5a6ebd37 100644 --- a/packages/plugins/EVM/src/state/AddressBook.ts +++ b/packages/plugins/EVM/src/state/AddressBook.ts @@ -12,14 +12,15 @@ export class AddressBook extends AddressBookState { chainId?: Subscription }, ) { - const defaultValue = Object.fromEntries( - getEnumAsArray(ChainId).map((x) => [x.value, []] as [ChainId, string[]]), - ) as Record - - super(context, defaultValue, subscriptions, { - isValidAddress, - isSameAddress, - formatAddress: formatEthereumAddress, - }) + super( + context, + getEnumAsArray(ChainId).map((x) => x.value), + subscriptions, + { + isValidAddress, + isSameAddress, + formatAddress: formatEthereumAddress, + }, + ) } } diff --git a/packages/plugins/EVM/src/state/NameService.ts b/packages/plugins/EVM/src/state/NameService.ts index eadb083f3d1b..db348f1c9b9a 100644 --- a/packages/plugins/EVM/src/state/NameService.ts +++ b/packages/plugins/EVM/src/state/NameService.ts @@ -15,16 +15,16 @@ export class NameService extends NameServiceState { chainId?: Subscription }, ) { - const defaultValue = Object.fromEntries(getEnumAsArray(ChainId).map((x) => [x.value, {}])) as Record< - ChainId, - Record - > - - super(context, defaultValue, subscriptions, { - isValidName: (x) => x !== '0x', - isValidAddress: (x) => isValidAddress(x) && !isZeroAddress(x), - formatAddress: formatEthereumAddress, - }) + super( + context, + getEnumAsArray(ChainId).map((x) => x.value), + subscriptions, + { + isValidName: (x) => x !== '0x', + isValidAddress: (x) => isValidAddress(x) && !isZeroAddress(x), + formatAddress: formatEthereumAddress, + }, + ) } private async createENS() { diff --git a/packages/plugins/EVM/src/state/Provider.ts b/packages/plugins/EVM/src/state/Provider.ts index 6f14d951995c..aeec258c46f7 100644 --- a/packages/plugins/EVM/src/state/Provider.ts +++ b/packages/plugins/EVM/src/state/Provider.ts @@ -1,7 +1,5 @@ -import { getEnumAsArray } from '@dimensiondev/kit' import type { Plugin } from '@masknet/plugin-infra' -import { ProviderState, ProviderStorage } from '@masknet/plugin-infra/web3' -import { EnhanceableSite, ExtensionSite } from '@masknet/shared-base' +import { ProviderState } from '@masknet/plugin-infra/web3' import { Account, isSameAddress } from '@masknet/web3-shared-base' import { ChainId, @@ -19,30 +17,13 @@ import { Providers } from './Connection/provider' export class Provider extends ProviderState { constructor(context: Plugin.Shared.SharedContext) { - const defaultValue: ProviderStorage, ProviderType> = { - accounts: Object.fromEntries( - getEnumAsArray(ProviderType).map((x) => [ - x.value, - { - account: '', - chainId: ChainId.Mainnet, - }, - ]), - ) as Record>, - providers: Object.fromEntries( - [...getEnumAsArray(EnhanceableSite), ...getEnumAsArray(ExtensionSite)].map((x) => [ - x.value, - ProviderType.MaskWallet, - ]), - ) as Record, - } - - super(context, Providers, defaultValue, { + super(context, Providers, { isSameAddress, isValidAddress, isValidChainId, getDefaultChainId: () => ChainId.Mainnet, getDefaultNetworkType: () => NetworkType.Ethereum, + getDefaultProviderType: () => ProviderType.MaskWallet, getNetworkTypeFromChainId: (chainId: ChainId) => chainResolver.chainNetworkType(chainId) ?? NetworkType.Ethereum, }) diff --git a/packages/plugins/EVM/src/state/Transaction.ts b/packages/plugins/EVM/src/state/Transaction.ts index 9eddef80b346..a80f1880f90a 100644 --- a/packages/plugins/EVM/src/state/Transaction.ts +++ b/packages/plugins/EVM/src/state/Transaction.ts @@ -1,7 +1,6 @@ import type { Subscription } from 'use-subscription' import { getEnumAsArray } from '@dimensiondev/kit' import type { Plugin } from '@masknet/plugin-infra' -import type { TransactionStorage } from '@masknet/plugin-infra/web3' import { TransactionState } from '@masknet/plugin-infra/web3' import { ChainId, Transaction as EVM_Transaction, formatEthereumAddress } from '@masknet/web3-shared-evm' @@ -13,12 +12,13 @@ export class Transaction extends TransactionState { chainId?: Subscription }, ) { - const defaultValue = Object.fromEntries( - getEnumAsArray(ChainId).map((x) => [x.value, {}]), - ) as TransactionStorage - - super(context, defaultValue, subscriptions, { - formatAddress: formatEthereumAddress, - }) + super( + context, + getEnumAsArray(ChainId).map((x) => x.value), + subscriptions, + { + formatAddress: formatEthereumAddress, + }, + ) } } diff --git a/packages/plugins/Flow/src/state/AddressBook.ts b/packages/plugins/Flow/src/state/AddressBook.ts index 60c547b8bd92..4d372665e974 100644 --- a/packages/plugins/Flow/src/state/AddressBook.ts +++ b/packages/plugins/Flow/src/state/AddressBook.ts @@ -12,14 +12,15 @@ export class AddressBook extends AddressBookState }, ) { - const defaultValue = Object.fromEntries( - getEnumAsArray(ChainId).map((x) => [x.value, []] as [ChainId, string[]]), - ) as Record - - super(context, defaultValue, subscriptions, { - isValidAddress, - isSameAddress, - formatAddress, - }) + super( + context, + getEnumAsArray(ChainId).map((x) => x.value), + subscriptions, + { + isValidAddress, + isSameAddress, + formatAddress, + }, + ) } } diff --git a/packages/plugins/Flow/src/state/Provider.ts b/packages/plugins/Flow/src/state/Provider.ts index 8105eebb6f50..c0e2007a1842 100644 --- a/packages/plugins/Flow/src/state/Provider.ts +++ b/packages/plugins/Flow/src/state/Provider.ts @@ -1,8 +1,6 @@ -import { getEnumAsArray } from '@dimensiondev/kit' import type { Plugin } from '@masknet/plugin-infra' -import { ProviderState, ProviderStorage } from '@masknet/plugin-infra/web3' -import { EnhanceableSite, ExtensionSite } from '@masknet/shared-base' -import { Account, isSameAddress } from '@masknet/web3-shared-base' +import { ProviderState } from '@masknet/plugin-infra/web3' +import { isSameAddress } from '@masknet/web3-shared-base' import { chainResolver, ChainId, @@ -17,29 +15,12 @@ import { Providers } from './Connection/provider' export class Provider extends ProviderState { constructor(override context: Plugin.Shared.SharedContext) { - const defaultValue: ProviderStorage, ProviderType> = { - accounts: Object.fromEntries( - getEnumAsArray(ProviderType).map((x) => [ - x.value, - { - account: '', - chainId: ChainId.Mainnet, - }, - ]), - ) as Record>, - providers: Object.fromEntries( - [...getEnumAsArray(EnhanceableSite), ...getEnumAsArray(ExtensionSite)].map((x) => [ - x.value, - ProviderType.Blocto, - ]), - ) as Record, - } - - super(context, Providers, defaultValue, { + super(context, Providers, { isSameAddress, isValidChainId, isValidAddress, getDefaultChainId: () => ChainId.Mainnet, + getDefaultProviderType: () => ProviderType.Blocto, getDefaultNetworkType: () => NetworkType.Flow, getNetworkTypeFromChainId: (chainId: ChainId) => chainResolver.chainNetworkType(chainId) ?? NetworkType.Flow, diff --git a/packages/plugins/Flow/src/state/Transaction.ts b/packages/plugins/Flow/src/state/Transaction.ts index 34b9d0d18512..4fa2e7a4c679 100644 --- a/packages/plugins/Flow/src/state/Transaction.ts +++ b/packages/plugins/Flow/src/state/Transaction.ts @@ -1,7 +1,7 @@ import type { Subscription } from 'use-subscription' import { getEnumAsArray } from '@dimensiondev/kit' import type { Plugin } from '@masknet/plugin-infra' -import { TransactionStorage, TransactionState } from '@masknet/plugin-infra/web3' +import { TransactionState } from '@masknet/plugin-infra/web3' import { ChainId } from '@masknet/web3-shared-flow' import type { MutateOptions } from '@blocto/fcl' import { formatAddress } from '../helpers' @@ -14,12 +14,13 @@ export class Transaction extends TransactionState { chainId?: Subscription }, ) { - const defaultValue = Object.fromEntries( - getEnumAsArray(ChainId).map((x) => [x.value, {}]), - ) as TransactionStorage - - super(context, defaultValue, subscriptions, { - formatAddress, - }) + super( + context, + getEnumAsArray(ChainId).map((x) => x.value), + subscriptions, + { + formatAddress, + }, + ) } } diff --git a/packages/plugins/Solana/src/state/AddressBook.ts b/packages/plugins/Solana/src/state/AddressBook.ts index d9672715d52c..f09d9b67d412 100644 --- a/packages/plugins/Solana/src/state/AddressBook.ts +++ b/packages/plugins/Solana/src/state/AddressBook.ts @@ -12,14 +12,15 @@ export class AddressBook extends AddressBookState }, ) { - const defaultValue = Object.fromEntries( - getEnumAsArray(ChainId).map((x) => [x.value, []] as [ChainId, string[]]), - ) as Record - - super(context, defaultValue, subscriptions, { - isValidAddress, - isSameAddress, - formatAddress, - }) + super( + context, + getEnumAsArray(ChainId).map((x) => x.value), + subscriptions, + { + isValidAddress, + isSameAddress, + formatAddress, + }, + ) } } diff --git a/packages/plugins/Solana/src/state/Provider.ts b/packages/plugins/Solana/src/state/Provider.ts index 20d8a89aef6d..0978ca243428 100644 --- a/packages/plugins/Solana/src/state/Provider.ts +++ b/packages/plugins/Solana/src/state/Provider.ts @@ -1,8 +1,6 @@ -import { getEnumAsArray } from '@dimensiondev/kit' import type { Plugin } from '@masknet/plugin-infra' -import { Account, isSameAddress } from '@masknet/web3-shared-base' -import { EnhanceableSite, ExtensionSite } from '@masknet/shared-base' -import { ProviderState, ProviderStorage } from '@masknet/plugin-infra/web3' +import { isSameAddress } from '@masknet/web3-shared-base' +import { ProviderState } from '@masknet/plugin-infra/web3' import { isValidChainId, isValidAddress, @@ -17,29 +15,12 @@ import { Providers } from './Connection/provider' export class Provider extends ProviderState { constructor(override context: Plugin.Shared.SharedContext) { - const defaultValue: ProviderStorage, ProviderType> = { - accounts: Object.fromEntries( - getEnumAsArray(ProviderType).map((x) => [ - x.value, - { - account: '', - chainId: ChainId.Mainnet, - }, - ]), - ) as Record>, - providers: Object.fromEntries( - [...getEnumAsArray(EnhanceableSite), ...getEnumAsArray(ExtensionSite)].map((x) => [ - x.value, - ProviderType.Phantom, - ]), - ) as Record, - } - - super(context, Providers, defaultValue, { + super(context, Providers, { isSameAddress, isValidChainId, isValidAddress, getDefaultChainId: () => ChainId.Mainnet, + getDefaultProviderType: () => ProviderType.Phantom, getDefaultNetworkType: () => NetworkType.Solana, getNetworkTypeFromChainId: (chainId: ChainId) => chainResolver.chainNetworkType(chainId) ?? NetworkType.Solana, diff --git a/packages/plugins/Solana/src/state/Transaction.ts b/packages/plugins/Solana/src/state/Transaction.ts index 730670445179..de829ce38b8c 100644 --- a/packages/plugins/Solana/src/state/Transaction.ts +++ b/packages/plugins/Solana/src/state/Transaction.ts @@ -1,7 +1,7 @@ import type { Subscription } from 'use-subscription' import { getEnumAsArray } from '@dimensiondev/kit' import type { Plugin } from '@masknet/plugin-infra' -import { TransactionStorage, TransactionState } from '@masknet/plugin-infra/web3' +import { TransactionState } from '@masknet/plugin-infra/web3' import { ChainId, Transaction as SolanaTransaction, formatAddress } from '@masknet/web3-shared-solana' export class Transaction extends TransactionState { @@ -12,12 +12,13 @@ export class Transaction extends TransactionState { chainId?: Subscription }, ) { - const defaultValue = Object.fromEntries( - getEnumAsArray(ChainId).map((x) => [x.value, {}]), - ) as TransactionStorage - - super(context, defaultValue, subscriptions, { - formatAddress, - }) + super( + context, + getEnumAsArray(ChainId).map((x) => x.value), + subscriptions, + { + formatAddress, + }, + ) } } diff --git a/packages/web3-shared/base/src/specs/index.ts b/packages/web3-shared/base/src/specs/index.ts index a23595c9fb12..f7a8cbd018d3 100644 --- a/packages/web3-shared/base/src/specs/index.ts +++ b/packages/web3-shared/base/src/specs/index.ts @@ -500,9 +500,9 @@ export interface WalletProvider { readonly readyPromise: Promise /** Switch to the designate chain. */ switchChain(chainId?: ChainId): Promise - /** Create an web3 instance. */ + /** Create an instance from the network SDK. */ createWeb3(chainId?: ChainId): Promise - /** Create an provider instance. */ + /** Create an instance that implement the wallet protocol. */ createWeb3Provider(chainId?: ChainId): Promise /** Create the connection. */ connect(chainId?: ChainId): Promise>