Skip to content

Conversation

@jackburrus
Copy link
Contributor

@jackburrus jackburrus commented Oct 12, 2023

This PR updates the open short table to use react-table. It implements 3 of the 5 columns that will ultimately be present for the trading competition. Those missing are hy-token price at open, and accrued yield. This also make the whole row clickable and removes the close position button in favor of the one on the modal.
image

@vercel
Copy link

vercel bot commented Oct 12, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hyperdrive-fixed-borrow ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 12, 2023 7:44pm
hyperdrive-monorepo-hyperdrive-trading ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 12, 2023 7:44pm
hyperdrive-sdk-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 12, 2023 7:44pm

});
},
}),
columnHelper.accessor("hyperdriveAddress", {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doesn't use the hyperdrive address, but an accessor string is required for the columnhelper.

Copy link
Contributor

Choose a reason for hiding this comment

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

Curious where this comes from, can we not call it "currentValue"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Found the issue here, column helper has a display method that just renders whatever you want and you don't have to provide an accessor, which for us comes from OpenShort type.

return (
<>
{children({ showModal })}
{children && children({ showModal })}
Copy link
Contributor

Choose a reason for hiding this comment

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

total nit, but optional calling is nice here: {children?.()}

header: `Size (hy${hyperdrive.baseToken.symbol})`,
cell: (bondAmount) => {
const bondAmountValue = bondAmount.getValue();
return dnum.format([bondAmountValue, hyperdrive.baseToken.decimals], {
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: We can use our formatBalance() utility for this, it's meant to help keep the dnum dependency contained.

});
},
}),
columnHelper.accessor("hyperdriveAddress", {
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious where this comes from, can we not call it "currentValue"?

});
const currentValue =
baseAmountOut &&
dnum.format(
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, formatBalance

return (
<tr
key={row.id}
className="h-16 cursor-pointer grid-cols-4 items-center text-sm text-base-content even:bg-secondary/5 md:text-h6"
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add a hover as well, daisy-hover should do it

Comment on lines 29 to 38
const { address: account } = useAccount();
const readHyperdrive = useReadHyperdrive(hyperdrive.address);
const queryEnabled = !!readHyperdrive && !!account;
const { data: shorts } = useQuery({
queryKey: makeQueryKey("shortPositions", { account }),
queryFn: queryEnabled
? () => readHyperdrive?.getOpenShorts({ account })
: undefined,
enabled: queryEnabled,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we avoid the parent having to fetch all this data and move this into the OpenShortTable intead?

}: OpenOrdersTableProps): ReactElement {
const tableInstance = useReactTable({
columns: columns(hyperdrive),
data: shorts,
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like if we move the data fetching into this commponent, it'd be okay to use [] while shorts is still fetching, wyt?

@jackburrus jackburrus merged commit 21195aa into main Oct 12, 2023
@jackburrus jackburrus deleted the jack-updates-short-table branch October 12, 2023 19:59
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.

2 participants