-
Notifications
You must be signed in to change notification settings - Fork 59
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
refactor: update homepage to typescript and hooks #921
Conversation
# Conflicts: # src/containers/Ledgers/LedgerMetrics.jsx # src/containers/Ledgers/Ledgers.jsx
# Conflicts: # src/containers/Network/Hexagons.jsx
</b> | ||
</div> | ||
)} | ||
<LedgerEntryTransactions transactions={ledger.transactions} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<LedgerEntryTransactions transactions={ledger.transactions} /> | |
<LedgerEntryTransactions transactions={ledger.transactions || []} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose not to always make it an array to differentiate between 0 transactions and it not loaded in.
…h ledger instead of all ledgers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
|
||
Object.keys(validators).forEach((pubkey) => { | ||
if (validators[pubkey].unl) { | ||
unl[pubkey] = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we set this to false instead of the unl value? It seems similar to undefined
and I took a second to re-read to confirm that false
just seems to be a sentinel value that's main trait is that it is NOT undefined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I honestly dont know this code was written this way before I just broke it out into its own component. I did rewrite it in the streams refactor though to this
const status = useMemo(() => {
const missing = [...(unl || [])]
validations.forEach((v) => {
if (!validators?.[v.validation_public_key]) {
return
}
const missingIndex = missing.findIndex(
(assumedMissing) => assumedMissing === v.validation_public_key,
)
if (missingIndex !== -1) {
missing.splice(missingIndex, 1)
}
})
return {
missing: missing.map((v) => validators?.[v]),
trustedCount: (unl?.length || 0) - missing.length,
}
}, [unl, validations])
# Conflicts: # src/containers/Ledgers/LedgerMetrics.jsx # src/containers/Ledgers/Ledgers.jsx # src/containers/Network/Hexagons.jsx # src/containers/PayStrings/PayStringHeader/index.tsx
} | ||
|
||
export const LedgerMetrics = ({ | ||
data: suppliedData, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see where suppliedData
is defined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data
is the props name but the linter prevents redefining a prop so i name it differently locally scoped to the function to make it shorter instead of having a longer name ever where i reference all the metrics
onPause: any | ||
paused: boolean | ||
}) => { | ||
const data = { ...DEFAULTS, ...suppliedData } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this cause a name collision with the input parameter data
for LedgerMetrics? I'm a bit confused on the naming here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See previous comment
let content: any = null | ||
|
||
let className = 'label' | ||
if (data[key] === undefined && key !== 'nUnl') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment explaining why nUnl
is special here? It's getting a lot of special treatment in this if/else - maybe there's a better way to separate out that logic? (ie. similar to how you deal with base_fee
beforehand then delete it from the object?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has special rules i think because it has a link to another page and a tooltip. This code existed before this refactor.
> | ||
<a | ||
key={`link ${key}`} | ||
href="https://xrpl.org/negative-unl.html" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this link be "localized" to point to the proper language if the explorer is in Japanese for example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't link anywhere else based on the language. I wouldn't know where to start since every site might have different rules like localstorage based or path based.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One open question, but otherwise looks good to me :)
High Level Overview of Change
Update homepage to typescript and hooks and break out aspects of the homepage's scrolling ledgers into smaller components. This also adds a new hook
useTooltip
that cleans up tooltip logic when many places are updating tooltips.A small change to move the transaction iteration into its own component reduced render times of the homepage due by between 30ms to 60ms each re-render.
Type of Change
TypeScript/Hooks Update
Future Work
Optimize the component into a hook that causes way fewer re-renders.