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

Add form when failing to register with low balance #1092

Merged
merged 5 commits into from
Jul 6, 2021

Conversation

vctt94
Copy link
Member

@vctt94 vctt94 commented May 17, 2021

Resolves #768

Copy link
Member

@JoeGruffins JoeGruffins left a comment

Choose a reason for hiding this comment

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

I get Looks like you do not have enough funds even if the failure is because I put in the wrong app password. The popup looks good to me, but it would really be better if it didn't have the possibility of showing misleading information.

client/webserver/site/src/html/register.tmpl Outdated Show resolved Hide resolved
@vctt94
Copy link
Member Author

vctt94 commented May 18, 2021

Thanks for the review joe, fixed it.

Copy link
Member

@JoeGruffins JoeGruffins left a comment

Choose a reason for hiding this comment

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

It seems I only get the new form if I have exactly 0 in the account. If I have, say, .01 and the dex want's 1, I do not see the form, although I do have insufficient funds.

@vctt94
Copy link
Member Author

vctt94 commented May 19, 2021

Are you trying to register to dex-test.ssgen.io:7232? Because if that is the case, the fee is 0.1 dcr (10000000 atoms), so you have sufficient funds, but no sufficient funds for the tx fee.

I added an insuficient funds into the message, so the form also shows in this case.

@@ -2444,7 +2444,7 @@ func (dcr *ExchangeWallet) sendRegFee(addr dcrutil.Address, regFee, netFeeRate u
}
coins, _, _, _, err := dcr.fund(enough)
if err != nil {
return nil, 0, fmt.Errorf("unable to pay registration fee of %s DCR with fee rate of %d atoms/byte: %w",
return nil, 0, fmt.Errorf("Insufficient funds for fee rate. Unable to pay registration fee of %s DCR with fee rate of %d atoms/byte: %w",
Copy link
Member

Choose a reason for hiding this comment

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

I think must be lowercase i in order to match the string.

But really, would be good to have an error code or something, as matching strings is very fragile.

Also, one day fees may be payable by different coins. So, other assets must also pay attention to their error messages. Also, this may cause problems with internationalization.

client/webserver/site/src/js/register.js Outdated Show resolved Hide resolved
@vctt94 vctt94 changed the title Add form when failing to register with low balance [wip] Add form when failing to register with low balance May 27, 2021
Copy link
Member

@chappjc chappjc left a comment

Choose a reason for hiding this comment

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

Yup, this approach is what I had in mind. Just a little clean-up and docs, and maybe consider something for js not to fail if code is undefined.

client/webserver/site/src/js/register.js Outdated Show resolved Hide resolved
client/webserver/site/src/js/register.js Outdated Show resolved Hide resolved
Comment on lines 94 to 102
<div class="bg2 px-2 py-1 text-center fs18">Insuficient funds</div>
<div class="p-4">
<div class="fs16">
Looks like you do not have enough funds for paying the fee in the
selected account. Please fund the account and try again.
</div>
<div class="fs15 pt-3 text-center d-hide errcolor" id="regFundsErr"></div>
<hr class="dashed mt-4">
</div>
Copy link
Member

@chappjc chappjc May 27, 2021

Choose a reason for hiding this comment

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

This is still just a guess that it's insufficient funds, but really it's any error from wallet.PayFee, which causes (*Core).Register to return a feeSendErr-coded error.

It could be many things including a bad fee address, or an error from sendWithReturn such as failure to sign the tx or failure to broadcast with sendrawtransaction.

Thus, I think it's warranted to soften the language in this dialog to indicate an error, but suggest the most likely cause of insufficient funds, and ofc show the whole error message as you are doing.

We could make it that specific with changes to the each asset's PayFee implementation to return a new error defined in client/asset/interface.go, which (*Core).Register recognizes and replaces with a more specific error code. But the most likely scenario is balance, and the form does show the full error, so I'm OK with simply framing this dialog as a suggestion rather than definitively saying it is balance.

@vctt94 vctt94 changed the title [wip] Add form when failing to register with low balance Add form when failing to register with low balance May 28, 2021
@vctt94
Copy link
Member Author

vctt94 commented Jun 7, 2021

This PR is ready for another review.

Msg string `json:"msg,omitempty"`
OK bool `json:"ok"`
Msg string `json:"msg,omitempty"`
Code int `json:"code,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Since walletErr = iota (0), this first code in the enumeration will not be marshalled. Nothing breaks in this PR, but it should allow 0.

-       Code int    `json:"code,omitempty"`
+       Code *int   `json:"code,omitempty"`
-               Code: code,
+               Code: &code,

In retrospect, it would have been better to define walletErr = iota + 1, but I'm hesitant to make that change now.

client/core/errors.go Outdated Show resolved Hide resolved
client/asset/dcr/dcr.go Show resolved Hide resolved
client/webserver/site/src/js/constants.js Outdated Show resolved Hide resolved
client/core/errors.go Outdated Show resolved Hide resolved
client/webserver/api.go Outdated Show resolved Hide resolved
@vctt94
Copy link
Member Author

vctt94 commented Jun 9, 2021

Thanks for the review chapp. Addressed your comments

client/webserver/api.go Outdated Show resolved Hide resolved
client/webserver/api.go Outdated Show resolved Hide resolved
@chappjc
Copy link
Member

chappjc commented Jun 9, 2021

I've revised the PR description so it doesn't close #768 when merged.

This PR will recognize an error from PayFee and then show the following:

image

However, because the above comes after confirming the following dialog, the issue isn't quite resolved.

image

In #768, @buck54321 was pointing out that instead of showing them this dialog when the frontend already knows the balance is insufficient, it should show a different dialog that prevents the registration and fee payment attempt entirely. (or modifies this Confirm Registration dialog with a clear note about balance and a disabled Register button).

Detecting a certain fee payment error code and displaying an appropriate dialog, as done in this PR, makes complete sense, but it does not quite resolve #768. Note that instead of getfee, we are now using getdexinfo

@vctt94
Copy link
Member Author

vctt94 commented Jun 14, 2021

okay, now it goes directly to the registration failed form, if there are not enough funds.

If available funds are equal the reg fee, than the process occurs and only fails in the end, as we do not check for the network fee.

Copy link
Member

@JoeGruffins JoeGruffins left a comment

Choose a reason for hiding this comment

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

Working well for me now.

Copy link
Member

@chappjc chappjc left a comment

Choose a reason for hiding this comment

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

Working well.

UI after entering dex address:

image

(doesn't have you try to confirm payment first -- good)

dexcctl register:

error paying registration fee: Unable to pay registration fee of 1 DCR with fee rate of 11 atoms/byte: insufficient funds. 0 DCR available to spend in "broke" account

Msg: errMsg,
OK: false,
Msg: err.Error(),
Code: code,
Copy link
Member

Choose a reason for hiding this comment

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

Good. Code is omitted when there is no error (just OK=true).

@chappjc chappjc merged commit cb0e295 into decred:master Jul 6, 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.

ui: tell user when Decred balance can't cover registration
3 participants