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

Jon/fix/light-acc-default-buy #5280

Merged
merged 2 commits into from
Oct 3, 2024
Merged

Conversation

Jon-edge
Copy link
Collaborator

@Jon-edge Jon-edge commented Sep 27, 2024

Original Amount Calculations (Light Acc):

3 steps were originally performed resulting in:
image
image

Changes:

image
image
image

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)


if (isLightAccount) {
// Round down
initialValue1 = floor(initialValue1, 0)
Copy link
Member

Choose a reason for hiding this comment

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

What's the point of this? The rounding should be the same for light account or not.

Copy link
Collaborator Author

@Jon-edge Jon-edge Sep 30, 2024

Choose a reason for hiding this comment

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

See the description - in the original implementation it was possible to potentially round up, so I wanted to retain that behavior for full accounts to get a little more revenue from full accounts

Copy link
Member

Choose a reason for hiding this comment

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

@Jon-edge so why not for light accounts?

Copy link
Collaborator Author

@Jon-edge Jon-edge Sep 30, 2024

Choose a reason for hiding this comment

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

In the euro case, our original rounding rules rounds up to 50 euros, >$50 usd. If we're OK
with light accounts buying a little more than $50 then that would be even
better.

I'll make the change.

@@ -523,8 +523,13 @@ export const amountQuoteFiatPlugin: FiatPluginFactory = async (params: FiatPlugi
quoteFiatCurrencyCode === 'iso:USD' ? '1' : (await getHistoricalRate(`${quoteFiatCurrencyCode}_iso:USD`, new Date().toISOString())).toString()
const quoteDollarValue = mul(bestQuote.fiatAmount, quoteFiatRate)

if (gt(quoteDollarValue, '50')) {
stateManager.update({ statusText: { content: lstrings.fiat_plugin_purchase_limit_error, textType: 'error' } })
if (gt(quoteDollarValue, DEFAULT_FIAT_AMOUNT_LIGHT_ACCOUNT)) {
Copy link
Member

Choose a reason for hiding this comment

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

I see this can work since in the previous commit you floored the last decimal place instead of rounding, but this is not clean logic. This is prone to break in the future if anyone touches either code location without knowing about the other. The logic of each don't even equal each other. The other commit takes $50 converted to the fiat currency then floors it. This code takes the EXACT exchange rate conversion.

Better to create a shared function that both places can call. Something like

getDefaultFiatValue(startingAmount, isoFiatCurrencyCode, isoNow) => fiatAmount

Copy link
Collaborator Author

@Jon-edge Jon-edge Sep 30, 2024

Choose a reason for hiding this comment

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

It was intentional to have the exact exchange rate shown because that's ultimately what we check against. We want users to be able to buy as much as possible, but for the initial value we make it look nice with a rounder number

Edit: Statement was incorrect, we're showing the rounded amount in the error message, but checking against an exact amount, to give wiggle room for the user. Moot point per latest comments.

Copy link
Member

Choose a reason for hiding this comment

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

It's a big ugly to show a value that's down to the penny. Just match the actual default fiat amount which can both go up or down based on round instead of floor

async function getInitialFiatValue(startingFiatAmount: string, isoFiatCurrencyCode: string) {
let initialValue1: string | undefined
if (isoFiatCurrencyCode !== 'iso:USD') {
const isoNow = new Date().toISOString()
Copy link
Member

Choose a reason for hiding this comment

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

You need to get the date or rate once and pass this into the function each time it's used. Otherwise you may get a different exchange rate for the default vs the limit. I put this in my comment as the function declaration example.

Copy link
Member

Choose a reason for hiding this comment

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

I just realized this can be super simplified by saving the initialValue and using that as the limit in the limit code at the bottom.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I had it like that in a prior revision where I just reuse the initial default, but thought you wanted the most recent exchange rate each time this was called.

Copy link
Member

Choose a reason for hiding this comment

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

I dont think I ever requested a fresh exchange rate. The only important thing is that it's consistent between the default and the limit

No longer relevant
@Jon-edge Jon-edge force-pushed the jon/fix/light-acc-default-buy branch from e3a9b00 to ebafa39 Compare October 3, 2024 01:25
Copy link
Member

@paullinator paullinator left a comment

Choose a reason for hiding this comment

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

See my fixup (untested) and retest. Merge if good.

@@ -61,15 +61,18 @@ const MAX_QUOTE_VALUE = '10000000000'

const NO_PROVIDER_TOAST_DURATION_MS = 10000

/** Make sure to use the same timestamp for rates throughout the lifetime of the
* module. */
const ISO_NOW = new Date().toISOString()
Copy link
Member

Choose a reason for hiding this comment

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

Ack. Don't get the date once for the lifetime of the app. Get it at least when the plugin is started. The app could stay running for days and weeks at which point the rate could drift a lot. Once per plugin launch would be much better. Please see my fixup. It's untested so please verify. If good then merge.

@Jon-edge Jon-edge force-pushed the jon/fix/light-acc-default-buy branch from cbcd3f4 to fe5659f Compare October 3, 2024 17:50
@Jon-edge Jon-edge merged commit 68b8c47 into develop Oct 3, 2024
2 checks passed
@Jon-edge Jon-edge deleted the jon/fix/light-acc-default-buy branch October 3, 2024 18:05
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