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

frontend: only show buyable coins in moonpay dropdown #1135

Merged

Conversation

thisconnect
Copy link
Collaborator

The dropdown checks now each coin if buying is supported and
only shows those accounts.

@thisconnect thisconnect requested a review from x1ddos January 13, 2021 17:39
@thisconnect thisconnect self-assigned this Jan 13, 2021
frontends/web/src/routes/buy/info.tsx Outdated Show resolved Hide resolved
))
)
.then(results => results.filter(result => result))
// @ts-ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

what's ignored here exactly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So in the filter before it filters out all results that are false (the ones that returned false in buy-supported), so on the next line TypeScript still thinks there could be false

Similar issue "filter should narrow down output type"
microsoft/TypeScript#20812

Couldn't manage as suggested to do "User-Defined Type Guards"
https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. So, something like this wouldn't work?

function isSupported(a: Account | bool): a is Account {
  return a !== false
}

.then(results => results.filter<Account>(isSupported))

}
onChange={e => this.setState({ selected: e.target.value})}
value={selected}
value={options.length ? selected : 'choose'}
Copy link
Contributor

Choose a reason for hiding this comment

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

if you kept it as is, value={selected}, would it still work?
I'm confused betwee this and the text: t(options.length ? 'buy.info.selectPlaceholder' : 'loading') above. seems like they're doing similar thing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

text: t(options.length ? 'buy.info.selectPlaceholder' : 'loading') is the text of the first grayed out option, this works if there is no preselected coin.

If there is a preselected coin, i.e. 'btc', the loading message would never show as the dropdown wants to show the option with the value 'btc'. But all accounts are checked asynchronously for if they can be bought, while checking options is an empty array, and value should point to the first grayed out option with the value 'choose' .... actually if there was a coin or token called 'choose' this wouldn't work .

does that make sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

but while the accounts are being checked, there's no way to select anything regardless of whether a coin is preselected, right.

what happens if the value remains as is, value={selected}, and selected is preset to say btc?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

then it doesn't show loading, but to be honest it happens so fast, I doubt that anyone would ever see the loading text.

@thisconnect thisconnect force-pushed the moonpay-filter-only-buyable-coins branch from a8008dd to 9c2c669 Compare January 14, 2021 08:43
Copy link
Contributor

@x1ddos x1ddos left a comment

Choose a reason for hiding this comment

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

LGTM. Can improve later.

@thisconnect thisconnect force-pushed the moonpay-filter-only-buyable-coins branch 2 times, most recently from 6c15047 to d5d8334 Compare January 14, 2021 12:22
The dropdown now asynchroniously checks each account if buying is
supported and only shows those accounts. This happens so fast
that a loading indicator looks like a bad flicker therefore
dropping the loading message.

If there is only one account/coin it will now go straight to the
Moonpay view. Note this now happens in testmode as tltc is disabled
and there is only tbtc. To test the account dropdown enable
legacy split accounts feature, to have multiple tbtc accounts.

If 'legacy separate accounts by address type' is enabled the
MoonPay disclaimer should show 'Buy Bitcoin' for any btc
style scriptTpyes else it shows 'Buy crypto'.
@thisconnect thisconnect force-pushed the moonpay-filter-only-buyable-coins branch from d5d8334 to fe61543 Compare January 14, 2021 12:37
@thisconnect thisconnect merged commit 36d5cd5 into BitBoxSwiss:moonpay Jan 14, 2021
@thisconnect thisconnect deleted the moonpay-filter-only-buyable-coins branch August 8, 2021 07:54
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