Skip to content

Commit

Permalink
Sometimes handleConfirmWalletDeployPrompt needs to act even when sequ…
Browse files Browse the repository at this point in the history
…enceVerified true
  • Loading branch information
Agusx1211 committed Jun 28, 2023
1 parent 83e8bf7 commit 9ccfc03
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions packages/provider/src/transports/wallet-request-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
// prompter is null, so we'll sign from here
sig = await account.signMessage(prefixedMessage, chainId ?? this.defaultNetworkId)
} else {
const promptResultForDeployment = request.method === 'sequence_sign' || await this.handleConfirmWalletDeployPrompt(this.prompter, account, chainId)
const promptResultForDeployment = await this.handleConfirmWalletDeployPrompt(this.prompter, account, request.method === 'sequence_sign', chainId)
if (promptResultForDeployment) {
sig = await this.prompter.promptSignMessage({ chainId: chainId, message: prefixedMessage }, this.connectOptions)
}
Expand Down Expand Up @@ -394,7 +394,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
// prompter is null, so we'll sign from here
sig = await account.signTypedData(typedData.domain, typedData.types, typedData.message, chainId ?? this.defaultNetworkId)
} else {
const promptResultForDeployment = request.method === 'sequence_signTypedData_v4' || await this.handleConfirmWalletDeployPrompt(this.prompter, account, chainId)
const promptResultForDeployment = await this.handleConfirmWalletDeployPrompt(this.prompter, account, request.method === 'sequence_signTypedData_v4', chainId)
if (promptResultForDeployment) {
sig = await this.prompter.promptSignMessage({ chainId: chainId, typedData: typedData }, this.connectOptions)
}
Expand Down Expand Up @@ -803,29 +803,38 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
private async handleConfirmWalletDeployPrompt(
prompter: WalletUserPrompter,
account: Account,
sequenceVerified: boolean,
chainId?: number
): Promise<boolean> {
// check if wallet is deployed and up to date, if not, prompt user to deploy
// if no chainId is provided, we'll assume the wallet is auth chain wallet and is up to date
if (!chainId) {
return true
}

const skipsDeploy = (status: AccountStatus) => {
return status.canOnchainValidate || (status.original.version === 2 && sequenceVerified)
}

const status = await account.status(chainId)
if (status.canOnchainValidate) {
if (skipsDeploy(status)) {
return true
}

const promptResult = await prompter.promptConfirmWalletDeploy(chainId, this.connectOptions)

// if client returned true, check again to make sure wallet is deployed and up to date
if (promptResult) {
const status2 = await account.status(chainId)
const isPromptResultCorrect = isWalletUpToDate(status2)
if (!isPromptResultCorrect) {

if (skipsDeploy(status2)) {
return true
} else {
logger.error('WalletRequestHandler: result for promptConfirmWalletDeploy is not correct')
return false
} else {
return true
}
}

return false
}
}
Expand Down

0 comments on commit 9ccfc03

Please sign in to comment.