Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

refactor: swap with state machines #283

Merged
merged 40 commits into from Jun 27, 2022
Merged

refactor: swap with state machines #283

merged 40 commits into from Jun 27, 2022

Conversation

pedronauck
Copy link
Member

@pedronauck pedronauck commented Jun 11, 2022

Fix #282
Fix #234

@pedronauck pedronauck added the enhancement New feature or request label Jun 11, 2022
@pedronauck pedronauck self-assigned this Jun 11, 2022
@pedronauck pedronauck marked this pull request as draft June 11, 2022 06:42
@pedronauck
Copy link
Member Author

Just missing to fix/add tests now, the state machine is done

Copy link
Contributor

@LuizAsFight LuizAsFight left a comment

Choose a reason for hiding this comment

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

refact looks great. just minor comments

packages/app/src/systems/Core/utils/helpers.ts Outdated Show resolved Hide resolved
packages/app/src/systems/Pool/utils/helpers.ts Outdated Show resolved Hide resolved
packages/app/src/systems/Swap/hooks/useSwapButton.tsx Outdated Show resolved Hide resolved
packages/app/src/systems/Swap/hooks/useSwapCoinInput.tsx Outdated Show resolved Hide resolved
packages/app/src/systems/Swap/utils/helpers.ts Outdated Show resolved Hide resolved
* 'master' of github.com:FuelLabs/swayswap:
  feat: move check branch to commit step (#292)
  feat: add agreement and update copy (#290)
  fix: correct behavior when typing only "." in the coin input (#291)
  fix: coin input value being cut by bottom line balance (#286)
@pedronauck pedronauck changed the title refac: add first version of refactoring on swap refactor: add first version of refactoring on swap Jun 17, 2022
* 'master' of github.com:FuelLabs/swayswap:
  fix: avoid resize during image loading (#349)
@pedronauck pedronauck marked this pull request as ready for review June 24, 2022 20:19
* 'master' of github.com:FuelLabs/swayswap:
  fix: add a fixed size for captcha to avoid size change after load (#348)
@pedronauck pedronauck enabled auto-merge (squash) June 24, 2022 20:21
@pedronauck pedronauck changed the title refactor: add first version of refactoring on swap refactor: swap refactoring Jun 24, 2022
@pedronauck pedronauck changed the title refactor: swap refactoring refactor: swap with state machines Jun 24, 2022
@luizstacio luizstacio linked an issue Jun 24, 2022 that may be closed by this pull request
* 'master' of github.com:FuelLabs/swayswap:
  fix: clean inputs after add liquidity (#347)
packages/app/scripts/contracts-init/initializePool.ts Outdated Show resolved Hide resolved
packages/app/src/systems/Core/components/CoinInput.tsx Outdated Show resolved Hide resolved
packages/app/src/systems/Core/hooks/useTokensMethods.ts Outdated Show resolved Hide resolved
packages/app/src/systems/Core/hooks/useTokensMethods.ts Outdated Show resolved Hide resolved
packages/app/src/systems/Swap/utils/queries.ts Outdated Show resolved Hide resolved
packages/app/src/systems/Swap/utils/queries.ts Outdated Show resolved Hide resolved
};

export const swapMachine =
/** @xstate-layout N4IgpgJg5mDOIC5QAoC2BDAxgCwJYDswBKAOgDMwAXHAqAIXQBt19M4BiCAe0JIIDcuAazAk0WPIVIVqk+kxZtYCAV0zpKuHgG0ADAF1EoAA5dYuTTyMgAHogCsAZgCMJABzOATPef37ANjcATl1ggBoQAE9ER3sAFhIgpKDPOLdHRwB2N11-AF88iPEaKXIqEvlmVg4wACdarlqSY2ZKMkbUMQwS4jLZWgYqpRV8QXVLfD1DJBBTcwnrOwQXfxJnTKDAt28ff0z-COiET0ddEjjnf2c4oLj7XUzLtwKi7slemQqAJTguAFdako+hUACo2ADCZkonB4olUIi6EgIH3Kch+sH+gLgwLkYMhsEoIzGGi0kwM1jmFlJi0QzlybncbmyTluQTc-iyhwcaRITjicV0ujiqTSTJeIGK72kqNo6MxQM+uIhUPYdQaTRaGnatU6kuR0v6+CgcoBCplRrxUKJahJOnJM0pCxmS3Z9l5bOC9jc9hSws8XIQ-ISukccUcwSuXs8t0y4r1pUVst+pux-CYuAgJKNAEl8MY-pRYOwKWYqVZnbSTo5ef57v4OUF7KkOQH-JsSJlMgLBZ5HgE4299TikxiU7ASDgwJghAAFLhcRjg2pgDSQGG8eGieMow3G5NY8eT6dzhdLleUSDW8akqYl+bUisIS4+EhtkKnAV93T2Vvtzvd3Re18fxdGcAckQTc091HA8J2wKdZ3nRdl1XCBVXqRpmlabVdUHSDdxNWCj0Q08UIvCAr1t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a reason for hiding this comment

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

Why do we need this comment here?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is generated from xstate visualizer vscode addon in order to have correctly visualization layout of the machine

packages/app/src/systems/Core/hooks/useTokensMethods.ts Outdated Show resolved Hide resolved
packages/app/src/systems/Core/hooks/useTokensMethods.ts Outdated Show resolved Hide resolved
Copy link
Member

@luizstacio luizstacio left a comment

Choose a reason for hiding this comment

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

  1. The First state should be select token.
  2. Network fee is not using the price factor correctly take a look on the hook useTransactionCost and show the user the txCost.fee
  3. When inverting the inputs the transition should be smoother, without elements appearing and changing the screen size, and sober components are flicking.

Note: item 3 can be done another issue.

Images:

  1. https://user-images.githubusercontent.com/3941923/175982796-238dc177-0095-4a71-8c1a-3162d6f950ff.png
  2. https://user-images.githubusercontent.com/3941923/175982764-423b2148-e959-4191-af28-b8a49b50032a.png
  3. https://user-images.githubusercontent.com/3941923/175982890-748081bd-ae24-49e1-b4f1-0554ff3db8ee.mov

luizstacio
luizstacio previously approved these changes Jun 27, 2022
@pedronauck pedronauck merged commit 652c83b into master Jun 27, 2022
@pedronauck pedronauck deleted the refac/swap branch June 27, 2022 22:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactoring swap logics Input blinks "Insufficient Liquidity" before calculating swap value
4 participants