-
Notifications
You must be signed in to change notification settings - Fork 254
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
Paul/fiat provider fixes #5225
Conversation
84f061c
to
d4e216a
Compare
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.
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.
|
||
if (isDailyCheckDue(lastChecked)) { | ||
if (Object.keys(assetMap.crypto).length === 0 || isDailyCheckDue(lastChecked)) { |
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.
Why would there be 0 keys after a query to the moonpay API?
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.
there wouldn't be, but this check occurs before the query on the first mount
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.
Oh, isn't that handled by isDailyCheckDue
though (isDailyCheckDue(lastChecked) === false
on first mount).
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.
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
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() | ||
} |
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.
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.
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.
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.
c5c5bbd
to
43d724b
Compare
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.
I got tripped up on the new findTokenIdByNetworkLocation
.
src/util/CurrencyInfoHelpers.ts
Outdated
if (edgeToken?.networkLocation?.contractAddress?.toLowerCase() === networkLocation?.contractAddress?.toLowerCase()) { | ||
return tokenId | ||
} |
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.
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?
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.
Good catch. Let me update as I had intended and just never completed.
d790f6c
to
19862c0
Compare
/rebase |
19862c0
to
3b79256
Compare
Not supported anymore
3b79256
to
95872be
Compare
CHANGELOG
Does this branch warrant an entry to the CHANGELOG?
Dependencies
noneRequirements
If you have made any visual changes to the GUI. Make sure you have: