Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to pass scwOnboardMode to eth_requestAccounts #1383

Merged
merged 3 commits into from
Sep 5, 2024

Conversation

nateReiners
Copy link
Contributor

@nateReiners nateReiners commented Sep 5, 2024

Summary

Adding the option for dapps to take users directly to Smart Wallet creation by passing a custom scwOnboardMode param to eth_requestAccounts

const [address] = await provider.request({ method: 'eth_requestAccounts', params: [{scwOnboardMode: 'create'}] })

How did you test your changes?

unit tests & locally

Create Button manual test

Screen.Recording.2024-09-04.at.6.50.26.PM.mov

Manual test of all 3 param possibilities

Screen.Recording.2024-09-05.at.10.23.15.AM.mov

@cb-heimdall
Copy link
Collaborator

cb-heimdall commented Sep 5, 2024

✅ Heimdall Review Status

Requirement Status More Info
Reviews 1/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

Comment on lines 58 to 64
const scwOnboardMode = Array.isArray(args?.params)
? (args.params[0]?.scwOnboardMode as ScwOnboardMode)
: undefined;
const options: { scwOnboardMode: ScwOnboardMode } = scwOnboardMode
? { scwOnboardMode }
: { scwOnboardMode: 'default' };
const signerType = await this.requestSignerSelection(options);
Copy link
Contributor

@spencerstock spencerstock Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, this should work. potentially more clear

Suggested change
const scwOnboardMode = Array.isArray(args?.params)
? (args.params[0]?.scwOnboardMode as ScwOnboardMode)
: undefined;
const options: { scwOnboardMode: ScwOnboardMode } = scwOnboardMode
? { scwOnboardMode }
: { scwOnboardMode: 'default' };
const signerType = await this.requestSignerSelection(options);
const scwOnboardMode = args?.params?.[0]?.scwOnboardMode;
const options = { scwOnboardMode: scwOnboardMode ?? 'default' as ScwOnboardMode };
const signerType = await this.requestSignerSelection(options);

Copy link
Contributor Author

@nateReiners nateReiners Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah this is much cleaner! For line 58 though, TS complains because expression of type '0' can't be used to index type 'object | readonly unknown[]'. Even though in practice eth request params are usually (always?) structured as an object inside an array, the eip-1193 provider spec say params is an array or object so we gotta respect the possibility than an object could be passed as params

Line 59 is nice! Here's that change. 5c9c0ac

Copy link
Contributor

@spencerstock spencerstock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, one comment to consider. Could you run a manual test on the final version for each:

  1. create passed in
  2. default passed in
  3. nothing passed in
    and cover each by unit tests as well?

Copy link
Contributor

@spencerstock spencerstock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great

@nateReiners nateReiners merged commit 5d54a0a into master Sep 5, 2024
8 checks passed
@nateReiners nateReiners deleted the nate/scwOnboardMode branch September 5, 2024 17:45
bangtoven added a commit that referenced this pull request Sep 5, 2024
bangtoven added a commit that referenced this pull request Sep 5, 2024
bangtoven pushed a commit that referenced this pull request Sep 6, 2024
* add option to pass scwOnboardMode to eth_requestAccounts

* readability

* add default / no params test cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants