-
Notifications
You must be signed in to change notification settings - Fork 87
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
frontend: only show buyable coins in moonpay dropdown #1135
Conversation
)) | ||
) | ||
.then(results => results.filter(result => result)) | ||
// @ts-ignore |
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.
what's ignored here exactly?
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.
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
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.
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'} |
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.
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.
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.
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?
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.
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
?
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.
then it doesn't show loading, but to be honest it happens so fast, I doubt that anyone would ever see the loading text.
a8008dd
to
9c2c669
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.
LGTM. Can improve later.
6c15047
to
d5d8334
Compare
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'.
d5d8334
to
fe61543
Compare
The dropdown checks now each coin if buying is supported and
only shows those accounts.