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

sending credits to existing user #91

Open
whatSocks opened this issue Jan 22, 2022 · 7 comments
Open

sending credits to existing user #91

whatSocks opened this issue Jan 22, 2022 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@whatSocks
Copy link
Contributor

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 alexrandaccio added the bug Something isn't working label Feb 3, 2022
@alexrandaccio
Copy link
Member

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
Copy link
Contributor

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
Copy link
Member

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

@alexrandaccio
Copy link
Member

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
Copy link
Contributor

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

@ChrisCoastal
Copy link
Contributor

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
Copy link
Member

alexrandaccio commented Mar 16, 2022

@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

  • when the logged in user selects an event/process from the Home page, that Process object is loaded and stored in StateContext. See the selectProcess() function call in ProcessPage.tsx and definition in AppProvider.tsx.
  • You will see that in selectProcess(), we also set a value for delegate. The value of delegate is then passed as a prop to DelegationPage, and from there, it is passed as a prop to TransferModal. When it appears in props, it is called userDelegate to differentiate it from the delegate objects corresponding to other participants in the selected event/process. i.e. delegate = someone participating in this event | userDelegate = the logged in user.
  • Finally, props.userDelegate gets passed as an argument to maybeSubmit().

What is recipient

  • recipient is passed as a prop to TransferModal. It represents the person to whom the logged in user is trying to send a transfer.
  • recipient can be one of two types:
    1. a Delegate object selected by the logged in user
    2. a string typed in by the logged in user, representing an email address (for inviting new participants to the event)

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants