Page MenuHomePhabricator

[e.cash] Improve network upgrade banner
ClosedPublic

Authored by johnkuney on Nov 14 2023, 22:15.

Details

Reviewers
bytesofman
Group Reviewers
Restricted Project
Commits
rABC09e6fb2a379c: [e.cash] Improve network upgrade banner
Summary

The countdown for the network upgrade banner needed improvement. Im adding it as a seperate component here
It is following the same logic as the countdown on avalanche.cash, and using the avalanche.cash API

The basic idea is it fetches the api on load

  • if it fails it doesnt load the banner
  • if we get a response it sets the timestamp for the countdown, and get the blocksUntilUpgrade
  • once the timestamp is reached there is another method to start polling the API every 60s to get the blocksUntilUpgrade
  • Once this value is < 0 the network upgrade is considerd finished, the final text is shown and the polling stops
Test Plan

preview the site and check it looks good

testing the actual functionality is a bit more invloved as not sure I have time to add tests, but it can be done manually
by running npm run dev

  • add const TESTING_TIMESTAMP = Date.now() + 10000; somewhere
  • replace setTimestamp(data.upgradeTimeStamp * 1000) with setTimestamp(TESTING_TIMESTAMP); in the useEffect
  • replace if ( newBlocksUntilUpgrade !== blocksUntilUpgrade && newBlocksUntilUpgrade !== null ) { setBlocksUntilUpgrade(newBlocksUntilUpgrade); }

with setBlocksUntilUpgrade(blocksUntilUpgrade - 1); in the polling useEffect

  • update the polling interval to a lower number if you like

This should run through every stage of the countdown and stop polling once its complete

Diff Detail

Repository
rABC Bitcoin ABC
Branch
ecash-countdown-update
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 25619
Build 50819: Build Diff
Build 50818: arc lint + arc unit

Event Timeline

bytesofman added a subscriber: bytesofman.
bytesofman added inline comments.
web/e.cash/components/announcement-bar/upgrade-notice.js
62

add comments whereever you are using this suppressHydrationWarning prop ... seems unique to NextJS? I had to look this up, it's not immediately clear what's going on here

96

Are Date.now() and timestamp in the same units here?

Date.now() should be less than timestamp, if the upgrade is in the future.

Maybe this is just happening to work bc the server is giving a timestamp in seconds and date.now() returns milliseconds .. so you happen to be testing "did I get a response from the server"

This revision now requires changes to proceed.Nov 14 2023, 23:41
web/e.cash/components/announcement-bar/upgrade-notice.js
62

For sure, it is in the nextjs docs, but I think actually a React prop. But yeah added a comment with link to next doc

96

So they are both in ms, note when the timestamp is set the api result is * 1000

Shouldn't it be greater than? if its more ms passed than it's later right?

add comment for supress hydrationprop

web/e.cash/components/announcement-bar/upgrade-notice.js
96

oic, in this case you are just looking to do the blocks and not the timer. got it.

bytesofman added inline comments.
web/e.cash/components/announcement-bar/upgrade-notice.js
116 ↗(On Diff #43085)

if the server can handle a tighter interval, imo worth it. Could easily have a flurry of sub-minute blocks, bad UX for countdown watchers.

Say, 10s.

117 ↗(On Diff #43085)
This revision now requires changes to proceed.Nov 15 2023, 00:27

changing polling interval to 10

This revision is now accepted and ready to land.Nov 15 2023, 00:39
This revision was automatically updated to reflect the committed changes.