Skip to content

Commit

Permalink
fix: internal wallet connected status (#10942)
Browse files Browse the repository at this point in the history
* fix: internal wallet connected status

* chore: i18n
  • Loading branch information
nuanyang233 authored and guanbinrui committed Oct 11, 2023
1 parent 425e1e5 commit 34eb13f
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 4 deletions.
23 changes: 22 additions & 1 deletion packages/mask/background/services/wallet/services/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,28 @@ export async function grantEIP2255Permission(id: string, grantedWalletAddress: I
}
promise[1](EIP2255PermissionsOfWallets(origin, grantedWalletAddress))
}

export async function connectWalletFromOrigin(wallet: string, origin: string) {
assertOrigin(origin)
const data = await walletDatabase.get('granted_permission', wallet)
const newData = produce<WalletGrantedPermission>(
data || {
type: 'granted_permission',
id: wallet,
origins: new Map(),
},
(draft) => {
if (!draft.origins.has(origin)) draft.origins.set(origin, new Set())
const permissions = draft.origins.get(origin)!
if (Array.from(permissions).some((data) => hasEthAccountsPermission(origin, data))) return
permissions.add({
invoker: origin,
parentCapability: 'eth_accounts',
caveats: [],
})
},
)
if (data !== newData) await walletDatabase.add(newData)
}
export async function disconnectWalletFromOrigin(wallet: string, origin: string) {
assertOrigin(origin)
const origins = new Map((await walletDatabase.get('granted_permission', wallet))?.origins)
Expand Down
7 changes: 6 additions & 1 deletion packages/mask/background/services/wallet/services/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ export interface MaskAccount {
/**
* @param chainId Chain ID
*/
export async function selectMaskAccount(chainId: ChainId, defaultAddress: string): Promise<MaskAccount[]> {
export async function selectMaskAccount(
chainId: ChainId,
defaultAddress: string,
source: string,
): Promise<MaskAccount[]> {
await openPopupWindow(Providers[ProviderType.MaskWallet].wallets ? PopupRoutes.SelectWallet : PopupRoutes.Wallet, {
chainId,
address: defaultAddress,
source,
})
deferred = defer()
return deferred![0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const SelectLanguageModal = memo<ActionModalBaseProps>(function SelectLan
[LanguageOptions.zhCN]: '简体中文',
[LanguageOptions.zhTW]: '繁体中文',
[LanguageOptions.jaJP]: '日本語',
[LanguageOptions.koKR]: '한국인',
[LanguageOptions.koKR]: '한국어',
}),
[t],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,14 @@ const Interaction = memo(function Interaction() {

return (
<Box flex={1} display="flex" flexDirection="column">
<Box p={2} display="flex" flexDirection="column" flex={1} maxHeight="458px" overflow="auto">
<Box
p={2}
display="flex"
flexDirection="column"
flex={1}
maxHeight="458px"
overflow="auto"
data-hide-scrollbar>
{content}
{currentRequest && !signRequest.includes(currentRequest?.request.arguments.method) ? (
<Box
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const SelectWallet = memo(function SelectWallet() {
const navigate = useNavigate()
const [params] = useSearchParams()
const external_request_id = params.get('external_request')
const source = params.get('source')
const { value: external_request } = useAsync(async () => {
if (!external_request_id) return null
return Services.Wallet.getEIP2255PermissionDetail(external_request_id)
Expand Down Expand Up @@ -110,6 +111,8 @@ const SelectWallet = memo(function SelectWallet() {

const wallet = wallets.find((x) => isSameAddress(x.address, selected))

if (wallet && source && !external_request_id)
await Services.Wallet.connectWalletFromOrigin(wallet?.address, source)
await Services.Wallet.resolveMaskAccount([
wallet?.owner
? {
Expand All @@ -132,6 +135,7 @@ const SelectWallet = memo(function SelectWallet() {
}
return Services.Helper.removePopupWindow()
}, [
source,
external_request,
external_request_id,
isVerifyWalletFlow,
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-infra/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export namespace Plugin.Shared {
selectMaskWalletAccount(
chainId: ChainId,
defaultAccount?: string,
source?: string,
): Promise<Array<{ address: string; owner?: string; identifier?: ECKeyIdentifier }>>

/** Open Dashboard with a new window */
Expand Down
8 changes: 8 additions & 0 deletions packages/shared-base/src/types/Routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@ export enum DashboardRoutes {
SignIn = '/sign-in',
PrivacyPolicy = '/privacy-policy',
Personas = '/personas',
Wallets = '/wallets',
WalletsTransfer = '/wallets/transfer',
WalletsSwap = '/wallets/swap',
WalletsRedPacket = '/wallets/red-packet',
WalletsSell = '/wallets/sell',
WalletsHistory = '/wallets/history',
CreateMaskWallet = '/create-mask-wallet',
CreateMaskWalletForm = '/create-mask-wallet/form',
RecoveryMaskWallet = '/create-mask-wallet/recovery',
CreateMaskWalletMnemonic = '/create-mask-wallet/mnemonic',
AddDeriveWallet = '/create-mask-wallet/add-derive-wallet',
SignUpMaskWalletOnboarding = '/create-mask-wallet/onboarding',
Settings = '/settings',
}

export enum PopupModalRoutes {
Expand Down Expand Up @@ -101,6 +108,7 @@ export interface PopupRoutesParamsMap {
chainId?: number
address?: string
external_request?: string
source?: string
}
[PopupRoutes.Personas]: {
providerType?: string
Expand Down

0 comments on commit 34eb13f

Please sign in to comment.