RadicalxChange / rxc-voice

An app for decentralized democratic governance.
https://voice.radicalxchange.org/
Other
42 stars 14 forks source link

sending credits to existing user #91

Open whatSocks opened 2 years ago

whatSocks commented 2 years ago

not sure if this is expected behavior, but what should happen if I try to send credits to the email that I'm currently logged in with? Right now it seems like credits get taken out, but I can't re-claim them.

alexrandaccio commented 2 years ago

The API should throw a Validation Error and the frontend should display a message saying something like "you can't send voice credits to yourself"

ChrisCoastal commented 2 years ago

Does this issue still need work? I see TransferModal.tsx has code aiming address it upon user submission...

} else if (recipient === userobj().public_username || recipient === userobj().email) {
alert.error("You cannot send credits to yourself");
}

If there is more to be done @alexrandaccio, I can give it a try (maybe with some assistance).

alexrandaccio commented 2 years ago

sorry for the late reply--busy week last week. let me replicate this

alexrandaccio commented 2 years ago

Here's what I'm seeing

Describe the bug

the API is throwing a ValidationError as expected, but the frontend is not displaying an error message to the user. instead, you hit the "submit" button, and nothing happens at all.

Steps to Reproduce

  1. Log into RxC Voice
  2. create an event where transfers are allowed
  3. open the event's delegation page
  4. click the button that says "+ invite someone else"
  5. enter a valid number of voice credits
  6. when the modal shows up, enter the same email address that is registered to the account you are logged into
  7. hit submit
  8. you will see that nothing happens on the frontend. if you are in a testing environment, you will see in your backend server logs that a ValidationError("Invalid transfer.") was thrown.

Expected Behavior

the frontend should display a message saying "you cannot send voice credits to yourself"

Solution

@ChrisCoastal identified the correct code snippet in a comment above. This code snippet checks the id of the recipient against the id of the logged in delegate.

The problem is, when you click "+ Invite Someone Else", you enter an email address, so recipient.id === undefined. As a result, this check does not catch the error.

The solution is to add an additional check:

else if (recipient === userDelegate.profile.user.email) { alert.error("You cannot send credits to yourself"); }

Next Steps

@ChrisCoastal thanks for volunteering! I'll go ahead and assign this to you for now, but feel free to let me know if you need more help or don't have time

@whatSocks if you are following the steps above and seeing a different result, let us know

Thanks both for your help 🤠 🚀

ChrisCoastal commented 2 years ago

Thanks @alexrandaccio; I'll have time for this over the weekend. Very much appreciate your extra guidance and time getting me setup. 🙏

ChrisCoastal commented 2 years ago

Hey @alexrandaccio, was just taking a look at this and unfortunately am a little lost. 🦑

I'm not sure what the userDelegate object you are referring to in your solution is (and subsequently how the check is meant to function).

I checked the props Delegation.tsx is passing to TransferModal.tsx and some of the other imports in TransferModal, but still can't follow your fix.

Thanks for the extra support! 💫

alexrandaccio commented 2 years ago

@ChrisCoastal no problem! Here's some relevant info (disclaimer: I am using "event" and "process" interchangeably here. That's because the model is currently called Process but I am transitioning to Event because it will be clearer. sorry for the confusion)

What is userDelegate

Where is userDelegate loaded

What is recipient

sorry the variable naming is not super clear, I'm gradually trying to fix that. Hope this is helpful, let me know if you have any follow up questions!