-
Notifications
You must be signed in to change notification settings - Fork 58
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
Swapbox 2.0 #1778
base: develop
Are you sure you want to change the base?
Swapbox 2.0 #1778
Conversation
I was testing this, this issue occurs in state transaction updater. It was there before, I can check und change this but I would need a bit more time. Maybe we can create a ticket and leave it for later as it is unrelated to the swapbox pull request. |
Hey @wixzi, I just finished inspecting this, this functionality works fine. I was able to reproduce this only in one case, and that doesn't work both in the old and new swapbox. I will take a look, the issue lies in one of the old hooks, I would assume this one => |
All right, found what is causing the issue... When the input currency is the native currency, this hook |
fb69230
to
0c5053c
Compare
ff47650
to
b3b3815
Compare
91e4f23
to
af06da1
Compare
Summary
This pull request contains fully finished and functioning
Swapbox 2.0
. I've tested swapping multiple times with various tokens with classical flow, approve flow and wrapping. I tried swapping through multiple platforms such as Swapr, Uniswap, 1Inch, CoW, Curve, Honeswap, etc. With the latest version, everything was working fine. I guess some dedicated, thorough testing should be done before going to the production.Closes #1655.
What's Done
After Zett created the designs, I started with the implementation. The idea was to go gradually, finish core functionalities, iterate through it and later add some of the features which were planned to be included, as well.
I started working on the swapbox in the middle of January, the first thing in line was to create the whole new UI. I do not like the implementation of the current swapbox as it contains many context providers and wrappers in the process of the component creation which makes it difficult to be read, understood and maintained. Each of those levels often contains pieces of logic. I've tried to make it as simple as possible, as flat as possible with as less logic kept in the components. This process took me about three weeks as I was a part-time
Swapr
contributor.After this I started working on understanding the current logic and the way swapbox is functioning in order to know how I should approach this. I tried a few approaches but the best to me seemed to create a hook (
useSwapbox
) which would contain ~all of the logic in itself and it would further export all the necessary references for the functioning. I figured out it would be easier to maintain it in the future and UI components should achieve the level of reusability that way. This took me two weeks, I still was a part-timeSwapr
contributor.The last step was to implement
useSwapbox
hook, connect the logic to the previously created UI components. I started working on this end of February. I had to add some logic to the components which concerns only those. I've also suggested a solution on how this can be improved in the future inREADME.md
added to theSwapbox 2.0
folder. During this process I've updated some things, made some tweaks in order to achieve the desired output and functionality. I was lacking some clarification about certain things so I've finished them at my own discretion; I've also created some missing pieces of the design. All of those can be easily updated.Inside the folder containing all of the code written is
README.md
which provides further clarification and understanding of implementation details. The contents of theREADME.md
will be added after this paragraph.README.md
Introduction
Welcome friend! 👋
This folder contains a new, re-designed swapbox,
Swapbox 2023
bydxDAO
. Current version is the first iteration and further plan is to continue working on this, designing new things, updating the current ones, adding new features and improving the existing ones.SwapContext
It is important to mention, the
Swapbox 2023
is wrapped withSwapContext
which takes care of some states of the swapbox. It tracks currencies, currency balances, currency amounts, available swapping platforms, currently selected swapping platform, loading state, etc.SwapContext
is located outside of this folder, its data model is presented below:Folder Structure
The folder contains a few other folders and files, I'll go through them and try to explain the responsibility of each and the idea behind it. Folder tree presented below:
models
This folder contains some of the models that are being used in the swapbox.
useSwapbox.ts
useSwapbox.ts
is the hook which powers theSwapbox 2023
; it contains 90% of the implementation logic that is being used to operate the swapbox. This hook is derived from the previous swapbox implementation with the idea to group the logic, keep it in the same place and in that way enable modularity, readability, maintainability and further development by isolation.The hook keeps track of some state values in itself, it uses the values from above mentioned
SwapContext
, extends them, derives new values from them and uses other external hooks to create functionalities through the functions which are exported from the hook for further usage in theSwapbox 2023
. Exported values / functions presented below:constants
This folder currently contains only UI related stuff. The idea behind is to extract UI values which provide styling for the
Swapbox 2023
into the variables. Those are the colors that are being used across the components, the swapbox dimensions, border stylings, elements spacing, indicator types and styling helper functions. If necessary in the future, since all of these are in the same place and all values are being referenced from it, it is really easy to change the looks of the swapbox and it would be really easy to introduce theming with minimal amount of work.components
components
folder contains all of the components that are being used in theSwapbox 2023
. The components are split by the functionalities they are responsible for. Root level components are assigned its own folder and their sub-components are kept inside it. Root level components areCurrencyItem
,SwitchCurrenciesButton
,SwapInfo
,SwapboxButton
andTokenPicker
. As mentioned above, the idea for the components is to mainly focus them on the UI part and keep as little logic as possible inside them. The only logic that can be kept inside is something specific for them and only used in that one place. The components should receive everything necessary for their functioning through the props.In future, in order to avoid prop drilling with values and functions, everything can be taken to the next level with dedicated state management solution. We should keep track both of the values and functions in one place and in that case ensure that each of the components can be independent and take everything they need directly from the centralized storage.
Swapbox.tsx
Swapbox.tsx
is the root component which basically assembles theSwapbox 2023
. This is where the references fromuseSwapbox.ts
hook are being unpacked and further fed to the components which need them for functioning.index.tsx
index.tsx
is the main file exported from this folder. It doesn't contain much, the only functionality it has is the composition of theSwapbox 2023
withHero
andLandingSections
components into the page. This page is exported as the main component.Screenshots
1Inch
Swapr
Curve
Uniswap
Sushiswap
Wrapping
Approve Flow
Token Picker
Successfully Made Swaps
🍀🍀🍀