-
Notifications
You must be signed in to change notification settings - Fork 50
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(swap): Move calculations to swap package #2697
Conversation
...obile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditBuyAmount/EditBuyAmount.tsx
Outdated
Show resolved
Hide resolved
...reen/CreateOrder/EditBuyAmount/SelectBuyTokenFromListScreen/SelectBuyTokenFromListScreen.tsx
Outdated
Show resolved
Hide resolved
91ffb4f
to
81f8582
Compare
apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditLimitPrice.tsx
Outdated
Show resolved
Hide resolved
...n/CreateOrder/EditSellAmount/SelectSellTokenFromListScreen/SelectSellTokenFromListScreen.tsx
Outdated
Show resolved
Hide resolved
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.
@stackchain related to the price calculation when there is a limit order
, I will propose to use the old formula for now - until we got more clarification specific to why is not taking the pool fee in consideration just to get the PR unblocked and will update it after more tests
- regarding pool.price let's use
tokenB/tokenA
when appropriate 🤔
@@ -46,13 +46,20 @@ export const CreateOrder = () => { | |||
tokenB: createOrder.amounts.buy.tokenId ?? '', | |||
}) | |||
|
|||
const bestPool = useMemo(() => { | |||
if (poolList !== undefined && poolList.length > 0) { | |||
return poolList.map((a) => a).sort((a, b) => a.price - b.price)[0] |
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.
Is the .map
needed?
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.
@MichalSzorad sort
modifies the array, which could affect other things outside this function. toSorted
would be the newer function, but doesn't seem to work in our setup. The map is just to clone it. Could have used any of the ways to do it, come to think of it [...poolList].sort(...)
may have been shorter.
Signed-off-by: Juliano Lazzarotto <30806844+stackchain@users.noreply.github.com>
Signed-off-by: Juliano Lazzarotto <30806844+stackchain@users.noreply.github.com>
Signed-off-by: Juliano Lazzarotto <30806844+stackchain@users.noreply.github.com>
apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/CreateOrder.tsx
Outdated
Show resolved
Hide resolved
…CreateOrder/CreateOrder.tsx Signed-off-by: Juliano Lazzarotto <30806844+stackchain@users.noreply.github.com>
Removes calculations from app
Adds calculations in swap reducer
Limit calculations need discussing
We use in some places the pool.price, which is always tokenA/tokenB. We would have to calculate it instead, to use tokenB/tokenA when appropriate.
Precision, divisions, bigint, binumber, etc. may need a second pass