Skip to content
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

Swaps: logic, data flow, and performance fixes #5787

Merged
merged 39 commits into from
Jun 1, 2024

Conversation

christianbaroni
Copy link
Member

@christianbaroni christianbaroni commented May 30, 2024

What changed (plus any additional context for devs)

  • Will add details in a bit

Screen recordings / screenshots

What to test

Fixes APP-1463
Fixes APP-1523
Fixes APP-1513
Fixes APP-1502
Fixes APP-1492
Fixes APP-1505
Fixes APP-1536
Fixes APP-1535
Fixes APP-1352
Fixes APP-1488
Fixes APP-1330

Need to replace with proper currency formatting
Used for a migration but it doesn't look like we're actually using the userAssetsStore favorites anywhere — may want to instead remove the migration
Shields it from WalletScreen re-renders
sliderXPosition: SLIDER_WIDTH / 2,
})
);
const initialInputNativeValue = addCommasToNumber((initialInputAmount * (initialSelectedInputAsset?.price?.value ?? 0)).toFixed(2));
Copy link
Member

Choose a reason for hiding this comment

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

we should have native formatter functions with the bigint work Bruno is doing

const inputValues = useSharedValue<{ [key in inputKeys]: number | string }>({
inputAmount: 0,
inputNativeValue: 0,
inputAmount: initialInputAmount,
Copy link
Member

Choose a reason for hiding this comment

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

open question / note to self: what's happening for the scenario for internal deeplinks if we want to "BUY" a specific token

Copy link
Contributor

Choose a reason for hiding this comment

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

Follow-up question before I can answer that one, but if we're prefilling an asset to buy, are we prefilling the asset to sell as the largest asset on the same network?

In not: We can do this no problem and just leave the output values as 0
If so: We'll have to prefetch a quote to show the initial output values based on that quote.

@@ -87,20 +129,20 @@ export function useSwapInputsController({
if (inputMethod.value === 'outputAmount') {
return valueBasedDecimalFormatter({
amount: inputValues.value.inputAmount,
usdTokenPrice: internalSelectedInputAsset.value.nativePrice,
usdTokenPrice: inputNativePrice.value,
roundingMode: 'up',
precisionAdjustment: -1,
isStablecoin: internalSelectedInputAsset.value?.type === 'stablecoin' ?? false,
Copy link
Member

Choose a reason for hiding this comment

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

note to check: are we sure this type for stablecoin is actually set? (wasn't seeing it locally a few commits ago)


return niceIncrementFormatter({
incrementDecimalPlaces: incrementDecimalPlaces.value,
inputAssetBalance: balance,
inputAssetUsdPrice: internalSelectedInputAsset.value.nativePrice,
inputAssetUsdPrice: inputNativePrice.value,
niceIncrement: niceIncrement.value,
percentageToSwap: percentageToSwap.value,
sliderXPosition: sliderXPosition.value,
Copy link
Member

@jinchung jinchung May 30, 2024

Choose a reason for hiding this comment

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

github won't let me add a comment on unchanged code for line 154: in formattedInputNativeValue and same for formattedOutputNativeValue: we need to remove USD specific hardcoded fallback values ($0.00)

}: {
data: Quote | CrosschainQuote | QuoteError | null;
outputAmount?: number;
inputAmount?: number;
inputPrice?: number | null;
outputPrice?: number | null;
}) => {
'worklet';

Copy link
Member

@jinchung jinchung May 30, 2024

Choose a reason for hiding this comment

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

for lines 234 - 245: for discussion: we're doing this slider update in multiple places - what if we turned the slider into an animated reaction and react when: the input amount changes and the input method is not the slider

Copy link

linear bot commented May 30, 2024

Copy link

linear bot commented May 31, 2024

Copy link

linear bot commented May 31, 2024

Copy link
Member

@jinchung jinchung left a comment

Choose a reason for hiding this comment

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

🌮
this review is for the useSwapInputsController file only from me.
also, there are comments that will be addressed later.

@walmat walmat self-requested a review May 31, 2024 19:01
@christianbaroni christianbaroni merged commit d8f7fec into develop Jun 1, 2024
6 checks passed
@christianbaroni christianbaroni deleted the @christian/swaps-fixes branch June 1, 2024 00:04
BrodyHughes added a commit that referenced this pull request Jun 1, 2024
…nt-test-3

* 'develop' of github.com:rainbow-me/rainbow:
  Bring in flashbots functionality for networks that support it (#5800)
  Swaps: logic, data flow, and performance fixes (#5787)
  remove limit from token to buy list (#5795)
  [e2e] Brody/e2e parallel (#5786)
BrodyHughes added a commit that referenced this pull request Jun 3, 2024
* 'develop' of github.com:rainbow-me/rainbow:
  Bring in flashbots functionality for networks that support it (#5800)
  Swaps: logic, data flow, and performance fixes (#5787)
  remove limit from token to buy list (#5795)
  [e2e] Brody/e2e parallel (#5786)
Copy link

sentry-io bot commented Jun 5, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ Error: private key must be 32 bytes, hex or bigint, not string start(src/hooks/reanimated/useAnimatedTime) View Issue

Did you find this useful? React with a 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants