-
Notifications
You must be signed in to change notification settings - Fork 588
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
refactor: wallets #1869
Open
magiziz
wants to merge
11
commits into
main
Choose a base branch
from
@mago/connectors
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
refactor: wallets #1869
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fd97f6a
chore: simplify wallets / connectors
magiziz e9089e4
chore: changeset and docs
magiziz 3570597
chore: append walletConnect metadata to the default modal option
magiziz a0057ba
Merge branch 'main' into @mago/connectors
magiziz 169e209
chore: add id and name to bybit and gateWallet
magiziz 4ee7e2e
merge, fix kaikas wallet
DanielSinclair 161c22e
chore: refactor wallet test files, cleanup prepare connector files an…
magiziz a1af332
Merge branch 'main' into @mago/connectors
DanielSinclair b674952
Merge branch 'main' into @mago/connectors
DanielSinclair 0e004de
Merge branch 'main' into @mago/connectors
DanielSinclair 392f1aa
fix: merge conflicts
magiziz File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@rainbow-me/rainbowkit": minor | ||
"site": patch | ||
--- | ||
|
||
Refactored and improved custom wallets for much easier implementation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,19 @@ | ||
import { createConnector } from 'wagmi'; | ||
import { CreateConnectorFn } from 'wagmi'; | ||
import { injected } from 'wagmi/connectors'; | ||
import { CreateConnector, WalletDetailsParams } from './Wallet'; | ||
|
||
interface CreateInjectedConnectorParameters { | ||
id: string; | ||
name: string; | ||
provider?: any; | ||
} | ||
|
||
interface GetInjectedConnectorParameters { | ||
id: string; | ||
name: string; | ||
flag?: string; | ||
namespace?: string; | ||
target?: any; | ||
} | ||
|
||
/* | ||
* Returns the explicit window provider that matches the flag and the flag is true | ||
|
@@ -75,36 +88,32 @@ function getInjectedProvider({ | |
return window.ethereum; | ||
} | ||
|
||
function createInjectedConnector(provider?: any): CreateConnector { | ||
return (walletDetails: WalletDetailsParams) => { | ||
// Create the injected configuration object conditionally based on the provider. | ||
const injectedConfig = provider | ||
? { | ||
target: () => ({ | ||
id: walletDetails.rkDetails.id, | ||
name: walletDetails.rkDetails.name, | ||
provider, | ||
}), | ||
} | ||
: {}; | ||
function createInjectedConnector({ | ||
id, | ||
name, | ||
provider, | ||
}: CreateInjectedConnectorParameters) { | ||
// Create the injected configuration object conditionally based on the provider. | ||
const injectedConfig = provider | ||
? { | ||
target: () => ({ | ||
id, | ||
name, | ||
provider, | ||
}), | ||
Comment on lines
+104
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those return types are required in wagmi. Reference to the docs here. |
||
} | ||
: {}; | ||
|
||
return createConnector((config) => ({ | ||
// Spread the injectedConfig object, which may be empty or contain the target function | ||
...injected(injectedConfig)(config), | ||
...walletDetails, | ||
})); | ||
}; | ||
return injected(injectedConfig); | ||
} | ||
|
||
export function getInjectedConnector({ | ||
id, | ||
name, | ||
flag, | ||
namespace, | ||
target, | ||
}: { | ||
flag?: string; | ||
namespace?: string; | ||
target?: any; | ||
}): CreateConnector { | ||
}: GetInjectedConnectorParameters): CreateConnectorFn { | ||
const provider = target ? target : getInjectedProvider({ flag, namespace }); | ||
return createInjectedConnector(provider); | ||
return createInjectedConnector({ id, name, provider }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to refactor much of the code in the
walletListItems
for loop, as the spread operators and var naming is getting tough to understand. Need comments here too. Rewinding back to v1, it was a bit easier to read and had comments: https://github.com/rainbow-me/rainbowkit/blob/42b0661e622ba99ec98cdb0219431f90ca45d40d/packages/rainbowkit/src/wallets/connectorsForWallets.tsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored 🙏