Skip to content

Commit 293f7ae

Browse files
committed
perf(juicebox-hooks): replace old useContractReadValue with wagmi.useReadContract; replace BigNumber with BigInt; replace ethers.parseTransaction with viem.decodeFunctionData
1 parent d27fc86 commit 293f7ae

17 files changed

+985
-637
lines changed

components/JuiceboxCard/JBSplitEntry.stories.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as wagmi from "wagmi";
44

55
import JBSplitEntry from "./JBSplitEntry";
66
import { ZERO_ADDRESS } from "@/constants/Contract";
7-
import { BigNumber } from "ethers";
87
import { JBSplit } from "@/models/JuiceboxTypes";
98

109
const meta: Meta<typeof JBSplitEntry> = {
@@ -17,19 +16,19 @@ type Story = StoryObj<typeof JBSplitEntry>;
1716

1817
const DEFAULT_SPLIT: JBSplit = {
1918
allocator: ZERO_ADDRESS,
20-
projectId: BigNumber.from(0),
19+
projectId: BigInt(0),
2120
beneficiary: ZERO_ADDRESS,
22-
percent: BigNumber.from(0),
21+
percent: BigInt(0),
2322
preferAddToBalance: false,
2423
preferClaimed: false,
25-
lockedUntil: BigNumber.from(0),
24+
lockedUntil: BigInt(0),
2625
};
2726

2827
export const Project: Story = {
2928
args: {
3029
mod: {
3130
...DEFAULT_SPLIT,
32-
projectId: BigNumber.from(1),
31+
projectId: BigInt(1),
3332
beneficiary: "0xAF28bcB48C40dBC86f52D459A6562F658fc94B1e",
3433
},
3534
},

components/JuiceboxCard/JBSplitEntry.tsx

+17-7
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,29 @@ export default function JBSplitEntry({
1515
}) {
1616
const { allocator, projectId, beneficiary } = mod;
1717

18-
const { data: ensName } = useEnsName({ address: beneficiary as `0x${string}`, chainId: 1 });
18+
const { data: ensName } = useEnsName({
19+
address: beneficiary as `0x${string}`,
20+
chainId: 1,
21+
});
1922

2023
let splitMode = "address";
2124
if (allocator !== "0x0000000000000000000000000000000000000000") {
2225
splitMode = "allocator";
23-
} else if (projectId.toNumber() !== 0) {
26+
} else if (projectId !== BigInt(0)) {
2427
splitMode = "project";
2528
}
2629

2730
const mainStyle = "text-base font-semibold";
2831

29-
3032
if (splitMode === "project") {
3133
return (
3234
<div className="mx-1 inline-block">
3335
<ProjectLink
34-
projectId={projectId.toNumber()}
36+
projectId={Number(projectId)}
3537
style={`${mainStyle} text-amber-600`}
36-
subText={`Beneficiary of project payment tokens: ${ensName || shortenAddress(beneficiary)}`}
38+
subText={`Beneficiary of project payment tokens: ${
39+
ensName || shortenAddress(beneficiary)
40+
}`}
3741
minified
3842
/>
3943
</div>
@@ -55,15 +59,21 @@ export default function JBSplitEntry({
5559

5660
return (
5761
<div className="mx-1 inline-block">
58-
<FormattedAddress address={beneficiary} style={`${mainStyle} text-blue-800`} minified link copyable={false} />
62+
<FormattedAddress
63+
address={beneficiary}
64+
style={`${mainStyle} text-blue-800`}
65+
minified
66+
link
67+
copyable={false}
68+
/>
5969
</div>
6070
);
6171
}
6272

6373
export function diff2TableEntry(
6474
index: number,
6575
status: Status,
66-
tableData: SectionTableData[],
76+
tableData: SectionTableData[]
6777
) {
6878
return (v: SplitDiffEntry) => {
6979
tableData[index].entries.push({

components/ProposalEdit/ReserveActionForm.tsx

+14-6
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,30 @@ export default function ReserveActionForm({
3333
}>({ name: genFieldName("splits") });
3434

3535
const { data: spaceInfo } = useSpaceInfo({ space });
36-
const projectId = spaceInfo?.data?.juiceboxProjectId;
37-
const { value: _fc, loading: fcIsLoading } =
36+
const projectId = parseInt(spaceInfo?.data?.juiceboxProjectId || "0");
37+
const { data: _fc, isLoading: fcIsLoading } =
3838
useCurrentFundingCycle(projectId);
3939
const [fc, metadata] = _fc || [];
40-
const { value: ticketMods, loading: ticketModsIsLoading } = useCurrentSplits(
40+
const { data: ticketMods, isLoading: ticketModsIsLoading } = useCurrentSplits(
4141
projectId,
4242
fc?.configuration,
43-
JBConstants.SplitGroup.RESERVED_TOKEN,
43+
BigInt(JBConstants.SplitGroup.RESERVED_TOKEN)
4444
);
4545
// TODO: reserve rate, percent / total_percentage JBConstants
4646

4747
useEffect(() => {
4848
if (fields.length === 0) {
4949
// if no splits in proposal (not editing) then load from JB project
5050
const arr = ticketMods ? [...ticketMods] : [];
51-
arr.sort((a, b) => b.percent.sub(a.percent).toNumber());
51+
arr.sort((a, b) => {
52+
if (a.percent > b.percent) {
53+
return -1;
54+
} else if (a.percent < b.percent) {
55+
return 1;
56+
} else {
57+
return 0;
58+
}
59+
});
5260
arr.forEach((ticket) => {
5361
const split: JBSplitStruct = {
5462
preferClaimed: ticket.preferClaimed,
@@ -194,7 +202,7 @@ export default function ReserveActionForm({
194202
</div>
195203
</Disclosure.Panel>
196204
</Disclosure>
197-
),
205+
)
198206
)}
199207
</div>
200208
);

components/Transaction/QueueReconfiguration.tsx

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Fragment, useRef } from "react";
22
import { Dialog, Transition } from "@headlessui/react";
3-
import { BigNumber, utils } from "ethers";
3+
import { utils } from "ethers";
44
import { useReconfig } from "@/utils/hooks/NanceHooks";
55
import {
66
calcDiffTableData,
@@ -34,7 +34,7 @@ export default function QueueReconfigurationModal({
3434
// Get configuration of current fundingCycle
3535
const projectId = juiceboxProjectId;
3636
const owner = transactorAddress ? utils.getAddress(transactorAddress) : "";
37-
const { value: controller, loading: controllerIsLoading } =
37+
const { data: controllerAddress, isLoading: controllerIsLoading } =
3838
useControllerOfProject(projectId);
3939
const { value: currentConfig, loading: configIsLoading } =
4040
useReconfigurationOfProject(projectId);
@@ -46,21 +46,20 @@ export default function QueueReconfigurationModal({
4646
encodeReconfiguration,
4747
"",
4848
currentConfig.fundingCycle.fee,
49-
BigNumber.from(Math.floor(Date.now() / 1000))
49+
BigInt(Math.floor(Date.now() / 1000))
5050
);
5151

5252
// Splits with changes
5353
const payoutsDiff = comparePayouts(
5454
currentConfig,
5555
newConfig,
56-
currentConfig.payoutMods || [],
57-
newConfig?.payoutMods || []
56+
[...currentConfig.payoutMods] || [],
57+
[...(newConfig?.payoutMods || [])]
5858
);
5959

60-
const reservesDiff = compareReserves(
61-
currentConfig.ticketMods || [],
62-
newConfig?.ticketMods || []
63-
);
60+
const reservesDiff = compareReserves([...currentConfig.ticketMods] || [], [
61+
...(newConfig?.ticketMods || []),
62+
]);
6463

6564
const loading = controllerIsLoading || configIsLoading || reconfigIsLoading;
6665

@@ -72,11 +71,13 @@ export default function QueueReconfigurationModal({
7271
);
7372

7473
const reconfigTx: GenericTransactionData = {
75-
to: controller?.address || "",
74+
to: controllerAddress || "",
7675
value: "0",
7776
data: encodeReconfiguration,
7877
};
7978

79+
console.debug("tableData", { currentConfig, newConfig, tableData });
80+
8081
return (
8182
<Transition.Root show={open} as={Fragment}>
8283
<Dialog

0 commit comments

Comments
 (0)