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

feat: user hub updated with streams #3018

Open
wants to merge 1 commit into
base: feat/streaming-payments-ui
Choose a base branch
from

Conversation

joanna-pagepro
Copy link
Contributor

@joanna-pagepro joanna-pagepro commented Aug 28, 2024

Description

User hub updates that are related to the streams

Unfortunately, I couldn't test the claim functionality because there was an error stating that some permissions were missing.

Testing

  • Step 1. Make sure that you have streaming payments extension installed
  • Step 2. Create streaming payments using different options for end condition, start time and interval using a form from action sidebar or from the temporary one that you can find on the dashboard page
  • Step 3. Open user hub and check Balance tab and reputation tab

Diffs

New stuff

  • Streams section inside BalanceTab
  • AvailableToClaimCounter

Changes 🏗

  • BalanceTab
  • ReputationTab

Deletions ⚰️

  • Removed redundant components like Balance.tsx because there's a new structure in user hub now

TODO

Contributes to #3016

@joanna-pagepro joanna-pagepro self-assigned this Aug 28, 2024
@AdrianDudko AdrianDudko linked an issue Aug 28, 2024 that may be closed by this pull request
@joanna-pagepro joanna-pagepro force-pushed the feat/streaming-payments-ui branch 2 times, most recently from 0c19e06 to af8a4f5 Compare August 30, 2024 10:43
@joanna-pagepro joanna-pagepro force-pushed the feat/16038847-streaming-hub branch 3 times, most recently from 0f90696 to 4256eb6 Compare September 3, 2024 12:13
@joanna-pagepro joanna-pagepro marked this pull request as ready for review September 3, 2024 12:29
@joanna-pagepro joanna-pagepro requested review from a team as code owners September 3, 2024 12:29
Copy link
Contributor

@iamsamgibbs iamsamgibbs left a comment

Choose a reason for hiding this comment

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

Nice work on this so far! I've left a few comments.

The UI looks good and I can see the number ticking up here:

Screen.Recording.2024-09-04.at.09.53.46.mov

This is probably a personal preference thing, but the numbers all jumping into place when opening the balance tab is a bit distracting and might be better to just be static when it loads and only animate on update:

Screen.Recording.2024-09-04.at.09.55.02.mov

Reputation tab also looks good:

Screenshot 2024-09-04 at 09 54 27

On mobile I wasn't sure if these buttons should be stacked or not, it seems like the figma mobile design might need updating as there are a few differences.

Screenshot 2024-09-04 at 11 14 54

Figma:
Screenshot 2024-09-04 at 11 15 09

One thing I wanted to check as it isn't clear from this PR or the original issue - is the 'total claimed' and 'available to claim' supposed to be for specifically within that colony? The "Your overview in Wayne Enterprises" to me suggests it should be for just this colony.

Screenshot 2024-09-04 at 11 13 10

Currently it shows the same value in any colony and is fetching streaming payments for all colonies I believe - see the comment I left regarding this.

I am also experiencing the permissions issue with claiming payments which makes this hard to test fully.

src/components/common/Extensions/UserHub/UserHub.tsx Outdated Show resolved Hide resolved
return null;
}

// @TODO: handle empty state <EmptyContent />
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this TODO out of scope for this PR?

Comment on lines 91 to 98
const { totalAvailable, totalClaimed } = await calculateTotalsFromStreams(
{
streamingPayments: items,
currentTimestamp: Math.floor(blockTime ?? Date.now() / 1000),
currency,
colony,
},
);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this works as it assumes all streaming payments are from the current colony. It seems like the useGetStreamingPaymentsQuery gets all the streaming payments for that user from every colony, so we should instead group the streaming payments by colony before passing them to this function - or something like that, there may be a better way to do it.

@joanna-pagepro
Copy link
Contributor Author

@iamsamgibbs thanks for your review!
I've updated everything and added a filter to get streaming payments for the current colony. I've also added a few more todo comments because those imports will be needed when part of the code will be uncommented.

Copy link
Contributor

@iamsamgibbs iamsamgibbs left a comment

Choose a reason for hiding this comment

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

Nice work! Thank you for making those changes and adding the comment re imports.

Tested with a streaming payment in planex:

Screenshot 2024-09-05 at 12 19 36

And without in Wayne:

Screenshot 2024-09-05 at 12 19 27

Copy link
Collaborator

@jakubcolony jakubcolony left a comment

Choose a reason for hiding this comment

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

Thanks for your PR @joanna-pagepro, I left some code comments for you to look at.

image

I was not able to test the UI using action form as it's still affected by the bug raised in #2938 regarding wrong units the start/end time is set in, but using the testing UI I can confirm the amounts look correct, and they update every second:

Screen.Recording.2024-09-17.at.11.00.45.mov

Comment on lines 8 to 25
listStreamingPayments(
filter: {
recipientAddress: { eq: $recipientAddress }
id: { beginsWith: $colonyId }
}
) {
items {
...StreamingPayment
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • Can you rebase and change this query to getStreamingPaymentsByColony?
  • The query needs to be paginated since it's likely a colony will have many streams, please have a look at how nextToken pagination is implemented elsewhere

}
};

export const getStatus = ({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
export const getStatus = ({
export const getStreamingPaymentStatus = ({

}

const balanceInWeiToEth = new Decimal(amount).div(
10 ** getTokenDecimalsWithFallback(decimals, nativeToken?.decimals),
Copy link
Collaborator

Choose a reason for hiding this comment

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

native token decimals shouldn't be used as fallback here

return startTimeValue.lt(currentTimestamp);
};

export const checkIfEnded = ({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
export const checkIfEnded = ({
export const checkIfStreamingPaymentEnded = ({

};
};

export const checkIfStarted = ({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please keep the names streaming payment specific as it's hard to follow if outside this file

Comment on lines 2 to 6
Active = 'Active',
Cancelled = 'Cancelled',
NotStarted = 'Not started',
Ended = 'Ended',
LimitReached = 'Limit reached',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you make the values match the keys? E.g. NotStarted = 'NotStarted'. This is so that people don't accidentally use it as labels instead of i18n messages.

Comment on lines 95 to 100
await calculateTotalsFromStreams({
streamingPayments: items,
currentTimestamp: Math.floor(blockTime ?? Date.now() / 1000),
currency,
colony,
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Feels like this could be a hook that manages its own state and data fetching, instead of the component having to call it inside useEffect and then put the results into state.

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 moved this code to a separate hooks.ts file for better readability.
Can you explain more? I'm not sure what you'd like me to do here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's exactly what I meant, thank you


const getTotalFunds = useCallback(
async (items: StreamingPaymentItems) => {
const { totalAvailable, totalClaimed, isActive } =
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think isActive lacks context, it's not clear what it refers to based on the method.

const AvailableToClaimCounter: FC<AvailableToClaimCounterProps> = ({
amountAvailableToClaim,
getTotalFunds,
isActive,
Copy link
Collaborator

Choose a reason for hiding this comment

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

as below, can it specify what is active? (at least one stream presumably?)

@joanna-pagepro joanna-pagepro force-pushed the feat/16038847-streaming-hub branch 2 times, most recently from 8bcdc01 to 56c18b2 Compare September 18, 2024 09:42
@joanna-pagepro
Copy link
Contributor Author

@jakubcolony code updated. Please also check my question regarding the hook that you've suggested.

Copy link
Member

@arrenv arrenv left a comment

Choose a reason for hiding this comment

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

Thank you @joanna-pagepro for your work and your patience. Nice work, I have noticed a couple of things.

  1. After creating a streaming payment, the UI did not update, I had to reload the app. Can we have it update without requiring an upload.

  2. The value does not appear to be aligned correctly on my end.

    image

  3. I am not able to test completely as the claim is not working for me. I am getting a permissions error.

    image

Copy link
Collaborator

@jakubcolony jakubcolony left a comment

Choose a reason for hiding this comment

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

Code-wise all looks good, nice work. I can confirm I'm getting the same issues Arren reported, I was only able to claim by manually assigning permissions.

@joanna-pagepro
Copy link
Contributor Author

@jakubcolony I think that there's a problem when installing the extension because the enable action is not called if there are no initializationParams and if I understand it correctly, the extension is installed without correct permissions. Can you help me with this one?

@iamsamgibbs
Copy link
Contributor

Ah, seems like this is likely related to #3027 (I'm assuming it made it's way onto a parent branch somewhere further up the chain) - looks like I mistakenly assumed having no initializationParams meant it shouldn't be automatically enabled. Should be an easy fix to just check for neededColonyPermissions and still make the setUserRoles transaction even if there is no initialise step. I'll put up a fix for this today.

@joanna-pagepro
Copy link
Contributor Author

@arrenv can you check 1. and 2. again?

@iamsamgibbs
Copy link
Contributor

iamsamgibbs commented Sep 19, 2024

Actually on further inspection, the changes in #3027 don't appear to be on this branch, so won't be the cause of any issues here. Apologies for any confusion! (And on even further inspection, #3027 will make the setUserRoles transaction even if there are no initializationParams, so long as enabledAutomaticallyAfterInstall is true)

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.

Streams balance in Userhub
4 participants