Skip to content

Commit

Permalink
fix: mask sdk crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Jan 8, 2024
1 parent 7809b68 commit 86db5fb
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
13 changes: 4 additions & 9 deletions packages/mask/background/services/wallet/services/connect.ts
Expand Up @@ -9,7 +9,6 @@ import { walletDatabase } from '../database/Plugin.db.js'
import { produce, enableMapSet } from 'immer'
import { ChainId } from '@masknet/web3-shared-evm'
import { openPopupWindow } from '../../helper/popup-opener.js'
import { MaskWalletProvider } from '@masknet/web3-providers'
import { PopupRoutes } from '@masknet/shared-base'
import { defer, type DeferTuple } from '@masknet/kit'
import type { WalletGrantedPermission } from '../database/types.js'
Expand Down Expand Up @@ -49,14 +48,10 @@ export async function sdk_EIP2255_wallet_requestPermissions(
promise: defer(),
})

if (!MaskWalletProvider.wallets) {
await openPopupWindow(PopupRoutes.Wallet, { external_request: id })
} else {
await openPopupWindow(PopupRoutes.SelectWallet, {
chainId: ChainId.Mainnet,
external_request: id,
})
}
await openPopupWindow(PopupRoutes.SelectWallet, {
chainId: ChainId.Mainnet,
external_request: id,
})
return requests.get(id)!.promise[0]
}
export async function sdk_getEIP2255PermissionRequestDetail(id: string) {
Expand Down
3 changes: 1 addition & 2 deletions packages/mask/background/services/wallet/services/select.ts
@@ -1,7 +1,6 @@
import { defer, type DeferTuple } from '@masknet/kit'
import { PopupRoutes, type ECKeyIdentifier } from '@masknet/shared-base'
import { type ChainId } from '@masknet/web3-shared-evm'
import { MaskWalletProvider } from '@masknet/web3-providers'
import { openPopupWindow } from '../../helper/popup-opener.js'

let deferred: DeferTuple<MaskAccount[], Error> | undefined
Expand All @@ -19,7 +18,7 @@ export async function selectMaskAccount(
defaultAddress?: string,
source?: string,
): Promise<MaskAccount[]> {
await openPopupWindow(MaskWalletProvider.wallets ? PopupRoutes.SelectWallet : PopupRoutes.Wallet, {
await openPopupWindow(PopupRoutes.SelectWallet, {
chainId,
address: defaultAddress,
source,
Expand Down
2 changes: 1 addition & 1 deletion packages/mask/entry-sdk/bridge/eth.ts
Expand Up @@ -215,7 +215,7 @@ export async function eth_request(request: unknown): Promise<{ e?: MaskEthereumP
if (result instanceof Err) throw result.error
if (result instanceof Ok) result = result.value
} catch (error: any) {
if (error instanceof MaskEthereumProviderRpcError) return { e: result.error }
if (error instanceof MaskEthereumProviderRpcError) return { e: error }
if (error.message === 'User rejected the message.') return { e: err.user_rejected_the_request() }

console.error(error)
Expand Down
9 changes: 5 additions & 4 deletions packages/mask/entry-sdk/bridge/eth/validator.ts
Expand Up @@ -89,6 +89,7 @@ namespace _ {
export const block_object = z.any()
export const EIP2255_PermissionList = z.array(
z.object({
parentCapability: z.string().optional(),
id: z.string().optional(),
invoker: z.string(),
caveats: z.array(
Expand Down Expand Up @@ -146,8 +147,8 @@ export const ParamsValidate = {
wallet_switchEthereumChain: z.tuple([
z.object({ chainId: _.chainId }).strict().describe('SwitchEthereumChainParameter'),
]),
wallet_requestPermissions: z.tuple([z.object({}).describe('requestPermissionsObject')]),
wallet_revokePermissions: z.tuple([z.object({}).describe('revokePermissionObject')]),
wallet_requestPermissions: z.tuple([z.object({}).passthrough().describe('requestPermissionsObject')]),
wallet_revokePermissions: z.tuple([z.object({}).passthrough().describe('revokePermissionObject')]),
wallet_getPermissions: z.tuple([]),
wallet_watchAsset: z.tuple([
z.enum(['ERC20', 'ERC721', 'ERC1155']).describe('type'),
Expand Down Expand Up @@ -175,9 +176,9 @@ export const ParamsValidate = {
EIP712Domain: z.array(z.unknown()),
})
.describe('types'),
domain: z.object({}),
domain: z.object({}).passthrough(),
primaryType: z.string(),
message: z.object({}),
message: z.object({}).passthrough(),
})
.describe('TypedData'),
]),
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-providers/src/Web3/EVM/providers/MaskWallet.ts
Expand Up @@ -52,8 +52,8 @@ export class MaskWalletProvider extends BaseEIP4337WalletProvider {
// Fetching info of SmartPay wallets is slow, update provider wallets eagerly here.
await this.updateImmediately()

const allPersonas = this.context.allPersonas.getCurrentValue() ?? EMPTY_LIST
const wallets = this.context.wallets.getCurrentValue() ?? EMPTY_LIST
const allPersonas = this.context.allPersonas.getCurrentValue()
const wallets = this.context.wallets.getCurrentValue()

const chainId = await this.Bundler.getSupportedChainId()
const accounts = await SmartPayOwner.SmartPayOwner.getAccountsByOwners(chainId, [
Expand Down

0 comments on commit 86db5fb

Please sign in to comment.