-
Notifications
You must be signed in to change notification settings - Fork 28
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
feat: hub adapter and refactor wallets store #852
Merged
Merged
Conversation
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
yeager-eren
requested review from
mikasackermn and
Ikari-Shinji-re
as code owners
August 21, 2024 09:49
yeager-eren
force-pushed
the
feat/support-for-both-legacy-and-hub
branch
from
August 24, 2024 06:31
61cfe85
to
4e491e3
Compare
yeager-eren
force-pushed
the
feat/support-for-both-legacy-and-hub
branch
from
August 24, 2024 07:08
4e491e3
to
e1de00f
Compare
yeager-eren
force-pushed
the
feat/support-for-both-legacy-and-hub
branch
2 times, most recently
from
August 24, 2024 08:09
9a88ea9
to
6a94cdb
Compare
yeager-eren
force-pushed
the
feat/support-for-both-legacy-and-hub
branch
from
August 24, 2024 09:26
6a94cdb
to
f73e4e5
Compare
5 tasks
yeager-eren
force-pushed
the
feat/support-for-both-legacy-and-hub
branch
from
September 18, 2024 10:39
295f375
to
91a1844
Compare
Ikari-Shinji-re
approved these changes
Oct 30, 2024
yeager-eren
force-pushed
the
feat/support-for-both-legacy-and-hub
branch
2 times, most recently
from
October 30, 2024 09:15
9355468
to
1f9f637
Compare
yeager-eren
force-pushed
the
feat/support-for-both-legacy-and-hub
branch
3 times, most recently
from
November 20, 2024 12:19
f0db76c
to
455bafc
Compare
5 tasks
yeager-eren
force-pushed
the
feat/support-for-both-legacy-and-hub
branch
from
December 1, 2024 06:55
ff14982
to
27f3bbe
Compare
yeager-eren
force-pushed
the
feat/support-for-both-legacy-and-hub
branch
from
December 1, 2024 07:36
27f3bbe
to
63f00c5
Compare
going to merge this. we will fix some reported bugs in separate PRs. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Add adapter to use hub providers alongside legacy providers.
This PR includes adding hub adapter in
/react/
and refactorwallets
store. From now on, we should be able to develop with our new wallet management system, Hub.How did you test this change?
You can test the changes by running
yarn dev:widget
.Details on how to review and what to test has been written in next section.
Notes for reviewers
Store
Assignee: @Ikari-Shinji-re
We had a separate store for
wallets
, in order to continue our work to migrate our stores to a single store and make current stores a slice of that, I completely removedwallets
store and made it an slice.The structure is mostly same, but there are one major difference. Previously, we had a
connectedWallets
which each of them had abalance
itself. To simplify the process, I added a separate_balances
and keep them separate fromconnectedWallet
.This change helps us do calculation much simpler (like calculating total balances) and treat this part differently, for example on connecting wallet it has two phases, one for adding the wallet to
connectedWallets
and another action for getting balances.Other notable changes
shiftedBy
in order to show a correct number to user. There were places likeMax
button needs to be updated which I did. I just mentioned this, maybe there are more places like this I'm unaware.Area of changes
Mostly
embedded/src/store
, you can take a look atembedded
as well and they will be updating usage ofwallets
store.Also removing
balance
fromrango-preset
is related to wallets store.AutoConnect
Assignee: @Ikari-Shinji-re
For having auto connect in
Hub
, in addition to wallet type/name, we neednamespace
as well. So I added a separate key in storage.I tried to reuse the legacy codes as much as I can,
eagerConnectHandler
,LastConnectedWalletsFromStorage
, same filenames are some effort to achieve this.LastConnectedWalletsFromStorage
is actually a shared interface to interact with both legacy and hub storage.Area of changes
You can start by reviewing
react/src/legacy/
, I tried to make the legacy code reusable by separating the logic intoautoConnect
,useAutoConnect
. Auto connect is calling inuseLegacyProvider
.And then you can start taking a look at
react/src/hub/
, I tried to use same filename and structure in legacy to make it more consistent and understandable.When you are reviewing this, you will notice there are some new functions like
LastConnectedWallets
which are actually a general solutions on legacy codes that needs to be reused in adapter.These files should be interested to you:
autoConnect,ts
constancts.ts
lastConnectedWallets.ts
useHubAdapter.ts
In Future
Adapter
__Assignee: @RyukTheCoder __
In previous PRs, we've prepared the filesystem structure for adding an adapter. In this PR, We've added a new
/react/src/hub
directory alongside/react/src/legacy
.The idea here is keeping the legacy interface to not needing to update clients (like embedded), to achieve this I created a new hook called
useProviders
which provides the legacy (ProviderContext
) at the end. It simply will load both hub and legacy providers and it's switch between them. For example you are going to useconnect
inembedded
, when it's going to run, it will check the request wallet is a legacy provider or hub provider, then it will call the method on that one.Each legacy and hub has a hook to implement the legacy interface (
ProviderContext
), they areuseLegacyProviders
anduseHubProviders
.For backward compatibility, there is an special namespace called
DISCOVER_MODE
. AlongsideDISCOVER_MODE
,network
will be set as well. here we are manually matching networks to namespaces. This will help us keep the legacy interface and have what hub needs as well. Explained some more details on next section.Other notable changes
namespace
is required. Since the legacy hasn't this concept, we only havenetwork
there. Adapter has a mapping betweenNetworks
and Hub'sNamespace
. Take a look atdiscoverNamespace
to see the mapping. That would be great if @RanGojo check this mapping as well.Network
can not be passed to wallet's instances (e.g.window.ethereum
) directly, for example for switching network, we need to convertNetwork
enum tochain id
. take a look attryConvertNamespaceNetworkToChainInfo
in this regard.Area of changes
Hub enabled in
widget/app/src/App.tsx
, and there are some update regarding toconnect
, it needs to haveDISCOVER_MODE
( e.gwidget/embedded/src/QueueManager.tsx
).Adapter has been written in
/react/src/hub
. Some parts of the changes is forauto connect
. It separately has been assigned to @Ikari-Shinji-re .Changes to
/react/src/legacy
are mostly for auto connect feature.Breaking Changes
connect
in/react
has changed. I updated the usage inembedded
.Phantom
__Assignee: @RyukTheCoder __
Phantom has been migrated to hub and also in addition to Solana namespace, EVM namespace has been added too.
Area of changes
You can take a look at
/provider-phantom
.Other changes
configs.isExperimentalEnabled
. I made itenable
for now.TODO
utils
from/core/mod.ts
In Future
suggestAndConnect
hasn't implemented in Hub adapter.canSwitchNetworkTo
,canEagerConnect
,getSigners
,getWalletInfo().supportedChains
,getInstance
fromlegacy
provider.Related PRs