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

Paul/fiat provider fixes #5225

Merged
merged 6 commits into from
Sep 3, 2024
Merged

Paul/fiat provider fixes #5225

merged 6 commits into from
Sep 3, 2024

Conversation

paullinator
Copy link
Member

@paullinator paullinator commented Aug 30, 2024

CHANGELOG

Does this branch warrant an entry to the CHANGELOG?

  • Yes
  • No

Dependencies

none

Requirements

If you have made any visual changes to the GUI. Make sure you have:

  • Tested on iOS device
  • Tested on Android device
  • Tested on small-screen device (iPod Touch)
  • Tested on large-screen device (tablet)

@paullinator paullinator force-pushed the paul/fiatProviderFixes branch 2 times, most recently from 84f061c to d4e216a Compare August 30, 2024 17:36
Copy link
Contributor

@samholmes samholmes left a comment

Choose a reason for hiding this comment

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

This all makes sense apart from some parts where I had questions (about the reverse quotes). Also, just some suggestions to make things read clearer.

src/plugins/gui/providers/moonpayProvider.ts Show resolved Hide resolved

if (isDailyCheckDue(lastChecked)) {
if (Object.keys(assetMap.crypto).length === 0 || isDailyCheckDue(lastChecked)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why would there be 0 keys after a query to the moonpay API?

Copy link
Member Author

Choose a reason for hiding this comment

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

there wouldn't be, but this check occurs before the query on the first mount

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, isn't that handled by isDailyCheckDue though (isDailyCheckDue(lastChecked) === false on first mount).

Copy link
Member Author

Choose a reason for hiding this comment

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

That's fair. Assuming there wasn't a glitch in the fetch that allowed for an empty set of assets, then removing the check should be fine. I'll make the update

src/plugins/gui/providers/moonpayProvider.ts Outdated Show resolved Hide resolved
src/plugins/gui/providers/moonpayProvider.ts Show resolved Hide resolved
src/plugins/gui/providers/moonpayProvider.ts Show resolved Hide resolved
src/plugins/gui/providers/moonpayProvider.ts Show resolved Hide resolved
src/plugins/gui/util/initializeProviders.ts Outdated Show resolved Hide resolved
src/plugins/gui/util/initializeProviders.ts Outdated Show resolved Hide resolved
src/plugins/gui/providers/kadoProvider.ts Show resolved Hide resolved
Comment on lines +562 to +586
const { baseAmount } = quote.data.quote

let fiatAmount: string
let cryptoAmount: string
const { totalFee } = quote.data.quote
const { amount, unitCount } = quote.data.quote.receive
if (direction === 'buy') {
const { unitCount } = quote.data.quote.receive
cryptoAmount = unitCount.toString()
fiatAmount = exchangeAmount
if (amountType === 'fiat') {
cryptoAmount = unitCount.toString()
fiatAmount = exchangeAmount
} else {
// For some reason, the totalFee is not included in the fiatAmount on buy reverse quotes
fiatAmount = (amount + totalFee.amount).toString()
cryptoAmount = exchangeAmount
}
} else {
const { amount } = quote.data.quote.receive
cryptoAmount = exchangeAmount
fiatAmount = amount.toString()
if (amountType === 'crypto') {
cryptoAmount = exchangeAmount
fiatAmount = amount.toString()
} else {
fiatAmount = exchangeAmount
// The unitCount is 0 for sell reverse quotes but seems to be in
// the baseAmount.amount so use that
cryptoAmount = baseAmount.amount.toString()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

const quote = asQuoteResponse(result).data
// ...
cryptoAmount = quote.baseAmount.amount.toString()

Removing the destructuring will keep the context of where baseAmount came from.

It would also avoid the need to rename things like minAmount and minUnit when you can just use quote.minValue.amount and quote.minValue.unit. It's more to read where it's used, but it avoids needing to read paragraphs of destructuring and renaming.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree. I left the minAmount and minUnit as is to reduce modification of the existing code. For the baseAmount, the destructuring seems harmless as there is no ambiguity as to where it came from.

@paullinator paullinator force-pushed the paul/fiatProviderFixes branch 2 times, most recently from c5c5bbd to 43d724b Compare September 2, 2024 22:08
Copy link
Contributor

@samholmes samholmes left a comment

Choose a reason for hiding this comment

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

I got tripped up on the new findTokenIdByNetworkLocation.

Comment on lines 62 to 66
if (edgeToken?.networkLocation?.contractAddress?.toLowerCase() === networkLocation?.contractAddress?.toLowerCase()) {
return tokenId
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like contractAddress is assumed to be the key within the query param params.networkLocation? Did you mean to do this?

If not, and instead you meant to use whatever keys are defined on params.networkLocation, then it seems like that could skip the whole "first key" validation song and dance:

export const findTokenIdByNetworkLocation = (params: FindTokenParams): EdgeTokenId | undefined => {
  const { networkLocation } = params
  let allTokens: EdgeTokenMap
  if ('allTokens' in params) {
    allTokens = params.allTokens
  } else {
    allTokens = params.account.currencyConfig[params.pluginId]?.allTokens
    if (allTokens == null) return
  }

  // eslint-disable-next-line no-labels
  outer: for (const tokenId in allTokens) {
    const edgeToken = allTokens[tokenId]
    for (const key in networkLocation) {
      const left = edgeToken?.networkLocation?.[key]
      if (typeof left !== 'string') {
        // Perhaps this should be an error throw?
        console.warn(`findTokenIdByNetworkLocation: Unsupported networkLocation key: ${key}`)
        return
      }
      const right = networkLocation[key]
      if (typeof right !== 'string') {
        // Perhaps this should be an error throw?
        console.warn(`findTokenIdByNetworkLocation: Unsupported networkLocation key: ${key}`)
        return
      }

      if (left.toLowerCase() !== right.toLowerCase()) {
        // eslint-disable-next-line no-labels
        continue outer
      }
    }
    // Found because it passed the checks in the inner loop
    return tokenId
  }
}

Maybe I misunderstand the function implementation?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. Let me update as I had intended and just never completed.

@paullinator paullinator force-pushed the paul/fiatProviderFixes branch 2 times, most recently from d790f6c to 19862c0 Compare September 3, 2024 17:06
@paullinator
Copy link
Member Author

/rebase

@paullinator paullinator merged commit 6b063a9 into develop Sep 3, 2024
2 checks passed
@paullinator paullinator deleted the paul/fiatProviderFixes branch September 3, 2024 18:39
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.

2 participants