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

PE-6149: delegated staking landing page and stake/unstake modal #8

Conversation

kunstmusik
Copy link
Collaborator

No description provided.

@kunstmusik kunstmusik requested a review from a team as a code owner May 23, 2024 22:04
Copy link

github-actions bot commented May 23, 2024

Visit the preview URL for this PR (updated for commit fc79c94):

https://ar-io-network-portal-a40ee--pr8-pe-6149-delegated-st-13dnfnio.web.app

(expires Fri, 07 Jun 2024 18:35:36 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 7abfae09c4446982a71cbb94b0cbf4688377a111

return (v: string) => {
const value = parseFloat(v);

if (isNaN(v as unknown as number) || isNaN(value)) {
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
if (isNaN(v as unknown as number) || isNaN(value)) {
if (isNaN(+v) || isNaN(value)) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for pointing that out, I updated to coerce using unary plus in this file and added a unit test.

});

const delegateData = walletAddress
? (gateway?.delegates[walletAddress?.toString()] as any)
Copy link
Collaborator

Choose a reason for hiding this comment

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

won't this be GatewayDelegate - do you need the cast?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for pointing this out, looks like it was a holdover from pre-1.0.7 when it was coming in as unknown. Updated to remove that.

});

// TODO: replace with logger call at INFO level when logger reinstated
console.log('Increase Delegate Stake txID:', txID);
Copy link
Collaborator

Choose a reason for hiding this comment

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

reccomend bunyan for a web friendly logger

Copy link
Collaborator Author

@kunstmusik kunstmusik May 24, 2024

Choose a reason for hiding this comment

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

Been meaning to add it, will plan to finally do it in the next PR that finishes up Phase 2.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FYI: I tried bunyan but found it kind of painful to get a custom stream going for nicely formatted messages in the browser. Ended up switching to loglevel for now, will leave it to a later tech debt ticket to improve further. (Loglevel work done in PE-6150)

@@ -90,7 +90,12 @@ const Profile = () => {
text="Connect"
onClick={() => setIsModalOpen(true)}
/>
<ConnectModal open={isModalOpen} onClose={() => setIsModalOpen(false)} />
{isModalOpen && (
Copy link
Contributor

@atticusofsparta atticusofsparta May 24, 2024

Choose a reason for hiding this comment

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

nit: these params seem redundant no? Atleast with usage - "open" should handle the rendering internally right? If not, then "open" could just always be set to true and you just use this pattern to render it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I started with one style of using the param but then switched to using it with the conditional rendering so that it would get fully unmounted from the DOM when not used. I'll take on refactoring out the open param and require using the && pattern in the next PR to keep this PR moving forward.

<div className="pt-[24px]">
<h1>Staking</h1>
<div className="grow">
{walletAddress ? (
Copy link
Contributor

@atticusofsparta atticusofsparta May 24, 2024

Choose a reason for hiding this comment

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

nit: this is a long ternary making it tricky to understand, consider splitting it out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Already being broken up and refactored in the next PR; will be addressed there.


const EPOCHS_PER_YEAR = 52;
const EPOCH_DISTRIBUTION_RATIO = 0.0025; // 0.25%
const GATEWAY_REWARDS_RATIO = 0.95; // 95%
Copy link
Contributor

Choose a reason for hiding this comment

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

wondering if this should be in the SDK. Either as a constant or retrieved from the contract.

@@ -2,7 +2,7 @@

// import App from '../src/App';

describe('App', () => {
describe.skip('App', () => {
Copy link
Contributor

@atticusofsparta atticusofsparta May 24, 2024

Choose a reason for hiding this comment

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

whats up with this? not test rendering the app?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, took it out as it's not a useful test at this point since things are still very changing a lot and would require often snapshots. Will reinstate when we can get more value out of the test.

expect(result.totalDelegatedStake.valueOf()).toEqual(
new IOToken(50000).valueOf(),
);
expect(result.rewardsSharedPerEpoch.valueOf()).toBeCloseTo(197.91, 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

why not toEqual?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

};
};

export const calculateUserRewards = (
Copy link
Contributor

Choose a reason for hiding this comment

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

feel like this should be a util in the sdk

Copy link
Collaborator

Choose a reason for hiding this comment

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

nit - should this be calculateWalletRewards

@@ -86,7 +86,7 @@ export const useGatewayInfo = () => {
observerWallet ? formatWalletAddress(observerWallet) : '',
],
['Joined at', 'PENDING'],
['Stake (IO)', formatWithCommas(mioToIo(operatorStake))],
['Stake (IO)', formatWithCommas(mioToIo(operatorStake.valueOf()))],
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 use the classes exported by the SDK?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

mioToIo() uses the classes; I can remove mioToIO() altogether. Will do this in PE-6150.

@kunstmusik kunstmusik merged commit 1c24534 into develop May 30, 2024
5 checks passed
@kunstmusik kunstmusik deleted the PE-6149-delegated-staking-landing-page-and-stake-unstake-modal branch May 30, 2024 14:40
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