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

Small moonpay fixes #1164

Merged
merged 5 commits into from
Jan 27, 2021
Merged

Small moonpay fixes #1164

merged 5 commits into from
Jan 27, 2021

Conversation

benma
Copy link
Contributor

@benma benma commented Jan 26, 2021

Still could not find the 'undefined' issue though...

this.setState({ options });
}
this.setState({ options });
this.maybeProceed();
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is unclear when preact updates the state after this.setState({ options }), use the 2nd argument of setState that is a callback when the state has updated: this.setState({ options }, this.maybeProceed);
or

this.setState({ options }, () => this.maybeProceed());

Copy link
Contributor Author

@benma benma Jan 26, 2021

Choose a reason for hiding this comment

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

Good catch. The preact docs suck though, there is nothing about setState?

https://preactjs.com/guide/v10/components
https://preactjs.com/guide/v10/api-reference

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

@thisconnect thisconnect left a comment

Choose a reason for hiding this comment

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

LGTM

with small nit about calling the next function after setState

@@ -882,7 +882,7 @@ func (handlers *Handlers) getExchangeMoonpayBuySupported(r *http.Request) (inter
break
}
}
return acct != nil && exchanges.IsMoonpaySupported(acct.Coin().Code()), nil
return acct != nil && !acct.Offline() && exchanges.IsMoonpaySupported(acct.Coin().Code()), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't feel semantically correct. The endpoint is supposed to respond whether account's coin is supported. I don't believe you need an account to be "online" in order to get a valid response from IsMoonpaySupported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You don't have to have an online account to call IsMoonpaySupported(), but you need an online account to be able to use the account in moonpay. this is a quick fix / hack to not list offline accounts.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. Add a TODO on top? 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have an idea for a general fix after this:

A higher order component that basically does what account.tsx already does: initialize an account, show spinner while syncing, show 'offline' if offline, etc. Factor that out of account.tsx, apply it there and in moonpay.tsx (and possibly even in the portfolio).

Will add the TODO

@@ -81,7 +81,7 @@ class Moonpay extends Component<Props, State> {
{ height }: State,
) {
const account = this.getAccount();
if (!account) {
if (!account || moonpay.url === '' || moonpay.address === '') {
Copy link
Contributor

@x1ddos x1ddos Jan 26, 2021

Choose a reason for hiding this comment

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

I think only the moonpay.url should be enough? The address is more like an informational field. I think we could even remove it. Initially, I was planning to show the address in the UI during the onramp flow but never got to it...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@x1ddos
Copy link
Contributor

x1ddos commented Jan 26, 2021

Sorry, forgot: typo in commit 3716f60: "this would only happen if he disclaimer ..."

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

Offline accounts have a connection issue.
Previously this would only happen if he disclaimer was already
dismissed. The dropdown would still be shown after you dismiss the
disclaimers.
This case should never happen, but if it did, the moonpay iframe would
inline the whole BitBoxApp again (iframe src="").
Otherwise the function can panic when accessing unused addresses.
@benma
Copy link
Contributor Author

benma commented Jan 26, 2021

@x1ddos added another commit to fix the init, PTAL.

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.

👍

@@ -900,6 +900,11 @@ func (handlers *Handlers) getExchangeMoonpayBuy(r *http.Request) (interface{}, e
if acct == nil {
return nil, fmt.Errorf("unknown account code %q", acctCode)
}

if err := acct.Initialize(); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I get it now. Before, it was in account handlers which I guess was initialized. But now in the main handlers, it might not have been initialized yet. Does that sounds right?

Copy link
Contributor

Choose a reason for hiding this comment

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

(by "it" I meant getExchangeMoonpayBuy handler method)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it was also not initialized before either.

it was accidentally initialized by the portfolio (chart.go), but if you click fast enough, it will not have gotten to Litecoin yet ;)

@benma benma merged commit d1d318a into BitBoxSwiss:master Jan 27, 2021
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.

3 participants