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

Feat/live 3629 add dex providers #1291

Merged
merged 18 commits into from
Sep 20, 2022
Merged

Conversation

sarneijim
Copy link
Contributor

πŸ“ Description

Add dex provider to the provider list
Out of scope: Filter (it will be developed in the next pr, out of scope next release)

❓ Context

βœ… Checklist

  • Test coverage
  • Atomic delivery
  • No breaking changes

πŸ“Έ Demo

Screenshot 2022-09-15 at 19 49 42

@vercel
Copy link

vercel bot commented Sep 15, 2022

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Updated
live-common-tools βœ… Ready (Inspect) Visit Preview Sep 19, 2022 at 10:05AM (UTC)
3 Ignored Deployments
Name Status Preview Updated
ledger-live-github-bot ⬜️ Ignored (Inspect) Sep 19, 2022 at 10:05AM (UTC)
native-ui-storybook ⬜️ Ignored (Inspect) Sep 19, 2022 at 10:05AM (UTC)
react-ui-storybook ⬜️ Ignored (Inspect) Sep 19, 2022 at 10:05AM (UTC)

@changeset-bot
Copy link

changeset-bot bot commented Sep 15, 2022

πŸ¦‹ Changeset detected

Latest commit: 92b03b1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
ledger-live-desktop Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added common Has changes in live-common desktop Has changes in LLD labels Sep 15, 2022
@github-actions
Copy link

github-actions bot commented Sep 15, 2022

@chabroA

Screenshots: βœ…

There are no changes in the screenshots for this PR. If this is expected, you are good to go.

@codecov
Copy link

codecov bot commented Sep 16, 2022

Codecov Report

Base: 43.84% // Head: 45.91% // Increases project coverage by +2.06% πŸŽ‰

Coverage data is based on head (cd9876c) compared to base (b6a41bf).
Patch has no changes to coverable lines.

❗ Current head cd9876c differs from pull request most recent head 92b03b1. Consider uploading reports for the commit 92b03b1 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1291      +/-   ##
===========================================
+ Coverage    43.84%   45.91%   +2.06%     
===========================================
  Files          609      642      +33     
  Lines        25501    27157    +1656     
  Branches      6947     7250     +303     
===========================================
+ Hits         11180    12468    +1288     
- Misses       14275    14634     +359     
- Partials        46       55       +9     
Flag Coverage Ξ”
test 45.91% <ΓΈ> (+2.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Ξ”
...kages/hw-app-eth/src/services/ledger/loadConfig.ts 100.00% <0.00%> (ΓΈ)
...ibs/ledgerjs/packages/hw-app-algorand/src/utils.ts 38.88% <0.00%> (ΓΈ)
libs/ledgerjs/packages/devices/src/index.ts 63.15% <0.00%> (ΓΈ)
...ibs/ledgerjs/packages/cryptoassets/data/stellar.js 100.00% <0.00%> (ΓΈ)
libs/ledgerjs/packages/hw-app-xrp/src/Xrp.ts 89.09% <0.00%> (ΓΈ)
libs/ledgerjs/packages/hw-app-eth/src/utils.ts 92.59% <0.00%> (ΓΈ)
...s/ledgerjs/packages/cryptoassets/src/currencies.ts 100.00% <0.00%> (ΓΈ)
...ages/hw-app-eth/src/modules/EIP712/EIP712.utils.ts 93.75% <0.00%> (ΓΈ)
...ckages/hw-app-eth/src/services/ledger/contracts.ts 82.60% <0.00%> (ΓΈ)
.../ledgerjs/packages/hw-app-algorand/src/Algorand.ts 29.03% <0.00%> (ΓΈ)
... and 23 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

β˜” View full report at Codecov.
πŸ“’ Do you have feedback about the report comment? Let us know in this issue.

@ggilchrist-ledger
Copy link
Contributor

We need to disable the 'Exchange' button when nothing valid is selected @sarneijim. Otherwise we can proceed and cause a crash

Screen.Recording.2022-09-16.at.11.49.22.mov

@ggilchrist-ledger
Copy link
Contributor

@sarneijim

  • 1inch shouldbe above paraswap
  • 'Oneinch' should be '1inch' (maybe the wording isn't important for this PR though)
    image

Copy link
Contributor

@chabroA chabroA left a comment

Choose a reason for hiding this comment

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

The overall idea is good. Basically what you want to do is handle the static list of DEX providers on the "UI" side for now and only on LLD.

But you need to handle dex static providers differently than centralised / backend provided providers to avoid added complexity and risk. For now you are mixing them in some sort of generic logic when they are actually totally different entities / concepts.

⚠️ You should not update LLC (for now) since it will cause issues with LLM that does not handle static dex providers as of today. When this will be integrated to LLM, you could refacto the common logic and put it in LLC when relevant

{decentralizedSwapAvailable &&
DEX_PROVIDERS.map((rate, index) => (
<Rate
key={rate.rateId || index}
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no rateId for your dex providers objects. You should rather use provider name rate.provider (assuming we have only one entry per dex provider which is the case today).

Also, using index as key should be avoided, especially when the order of items may change in the array (which is the case here since centralised rates are dynamic and are updated every 30 seconds).

cf. here for more details on that -> https://reactjs.org/docs/lists-and-keys.html#keys


Also, and for the same reasons, you should change the key property in the above centralised rate component (line 145).

Not all centralised rates have rateId, you could then construct the unique key for a centralised rate using a combination of the ExchangeRate provider and tradeMethod property, like:

key={`${rate.provider}-${rate.tradeMethod}`}

Copy link
Contributor Author

@sarneijim sarneijim Sep 16, 2022

Choose a reason for hiding this comment

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

Changed

Comment on lines 87 to 142
{centralized && (
<Box>
<Box style={{ height: "19.5px", justifyContent: "center" }}>
<Price
withEquality
withIcon={false}
from={fromCurrency}
to={toCurrency}
rate={value.magnitudeAwareRate}
fontWeight="600"
/>
</Box>
<Text fontSize={3} color="palette.text.shade40">
<Trans
i18nKey={
value.tradeMethod === "fixed"
? "swap2.form.rates.fixed"
: "swap2.form.rates.float"
}
/>
</Text>
</Box>
)}
</Box>
<Box alignItems="flex-end" flex={1}>
{centralized ? (
<>
<FormattedVal
inline
fontSize={4}
val={amount}
currency={toCurrency}
unit={toCurrency?.units[0]}
showCode={true}
color="palette.text.shade100"
fontWeight="600"
/>
</Box>
<Text fontSize={3} color="palette.text.shade40">
<Trans
i18nKey={
value.tradeMethod === "fixed"
? "swap2.form.rates.fixed"
: "swap2.form.rates.float"
}
<CounterValue
fontSize={3}
inline
currency={toCurrency}
value={amount}
disableRounding
showCode
color="palette.text.shade40"
/>
</>
) : (
<Text
fontSize={3}
color="palette.text.shade40"
style={{ width: "110px", textAlign: "right" }}
>
<Trans i18nKey={"swap.providers.noQuote"} />
</Text>
</Box>
</Box>
<Box alignItems="flex-end" flex={1}>
<FormattedVal
inline
fontSize={4}
val={amount}
currency={toCurrency}
unit={toCurrency?.units[0]}
showCode={true}
color="palette.text.shade100"
fontWeight="600"
/>
<CounterValue
fontSize={3}
inline
currency={toCurrency}
value={amount}
disableRounding
showCode
color="palette.text.shade40"
/>
)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Your Rate component is getting quite complex and messy by trying to handle centralised and decentralised providers in the same place. Especially since both centralised and decentralised rates have different sets of props.

You should rather break it down and use composition to have 2 different end components, a CentralisedRate (or CentralisedProvider) and a DecentralisedRate (or DecentralisedProvider, because for DEX we don't actually have rate).
You could have a generic Rate component for all the common logic / style and have the centralised and decentralised ones being specialised version of this generic Rate one.

cf. https://reactjs.org/docs/composition-vs-inheritance.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally agree. Done.

@@ -492,10 +508,9 @@ const SwapForm = () => {
)}

<Box>
<Button primary disabled={!isSwapReady} onClick={onSubmit} data-test-id="exchange-button">
<Button primary onClick={onSubmit} data-test-id="exchange-button">
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you get rid of the disable prop?

Now the button is enabled even if the user can't swap (for example in the nominal state when no rate is provided or when the user needs to do login or KYC).

To enable the button when a dex provided is selected, you should rather update the isSwapReady const, which starts to become a bit convoluted / complex so it could also be a good opportunity to break it down in an aggregation os smaller individual conditions, for example:

const hasError = error || providersError || swapError;
const isLoading = swapTransaction.bridgePending ||Β exchangeRatesState.status !== "loading";

const isSwapReady = !hasError && !isLoading && (...)

Screenshot 2022-09-16 at 12 01 39
Screenshot 2022-09-16 at 12 01 50

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extra change to test. This change has been already removed.

@@ -1,5 +1,5 @@
import { useCallback, useEffect, useReducer, useState } from "react";
import { getExchangeRates } from "..";
import { dex, getExchangeRates } from "..";
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ I would not update live-common for this task (or at least not for now) since it will cause issues with LLM that does not handle dex providers in the swap as of today.

Also, there is some logic duplication since you handle the list of dex providers in LLC and in LLD
There is therefore no single source of truth.

I would rather only handle this static dex list on the UI side (LLD as of today), like it was done for the original banner.
The main difference being that now you are appending these 2 states providers entries (they are actually not rates per say) to the dynamic list of providers returned by the API.

Which, by the way, seems to already be what you are doing in your Rates.index.tsx component (cf. here)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any logic has been removed from LLC

@@ -100,7 +100,7 @@ const swapProviders: Record<string, SwapProviderConfig> = {
};

const getProviderConfig = (providerName: string): SwapProviderConfig => {
const res = swapProviders[providerName.toLowerCase()];
const res = swapProviders[providerName.toLowerCase()] || {};
Copy link
Contributor

Choose a reason for hiding this comment

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

This is error prone and also not really necessary once you rework / break down your Rate component since the DEXs should not require / need registration nor KYC

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any logic has been removed from LLC

@ggilchrist-ledger
Copy link
Contributor

@sarneijim The 1inch text has been fixed but 1inch is still below Paraswap in the list. Other than that it looks look. I'll test again once Alex's comments have been addressed.
image

@chabroA
Copy link
Contributor

chabroA commented Sep 16, 2022

@sarneijim quick question / feedback that I forgot in my first review, I didn't see the category (all / centralised / decentralised) filter present in the Figma. Is it an oversight or is it out of scope for this PR?

@sarneijim
Copy link
Contributor Author

sarneijim commented Sep 16, 2022

@sarneijim quick question / feedback that I forgot in my first review, I didn't see the category (all / centralised / decentralised) filter present in the Figma. Is it an oversight or is it out of scope for this PR?

Yes, it is out of scope. The filter will be addressed in the future.

Copy link
Contributor

@chabroA chabroA left a comment

Choose a reason for hiding this comment

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

Looks good to me overall

@ggilchrist-ledger
Copy link
Contributor

Looks good to me too. Still some things to be added/fixed but this will come in future iterations:

@sarneijim sarneijim merged commit badf7fb into develop Sep 20, 2022
@sarneijim sarneijim deleted the feat/LIVE-3629-add-dex-providers branch September 20, 2022 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
desktop Has changes in LLD
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants