Skip to content

Commit 3fd5386

Browse files
committed
fix(SafeTypes): update SafeInfoResponse type
1 parent df3a378 commit 3fd5386

File tree

7 files changed

+58
-32
lines changed

7 files changed

+58
-32
lines changed

components/TenderlySimulation/SafeTenderlySimulationButton.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default function SafeTenderlySimulationButton({
2828

2929
const chain = useChainConfigOfSpace();
3030
const { data: safeInfo } = useSafeInfo(address, !!address);
31-
const firstOwnerAddress = safeInfo?.owners?.[0] || zeroAddress;
31+
const firstOwnerAddress = safeInfo?.owners?.[0].value || zeroAddress;
3232
const { encodedTransaction, safeTransaction, error } =
3333
useCreateTransactionForSimulation(address, transactions, true);
3434

components/Transaction/SafeTransactionCreator.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export default function SafeTransactionCreator({
3939
useHistoryTransactions(safeAddress, 1, safeAddress !== "");
4040
const { data: walletClient } = useWalletClient();
4141

42+
const nextNonce =
43+
(historyTxs?.results?.[0].transaction.executionInfo.nonce || -1) + 1;
4244
const queueNotReady =
4345
!walletClient || !safeTransaction || !nonce || !safeAddress || loading;
4446

@@ -54,10 +56,10 @@ export default function SafeTransactionCreator({
5456
}
5557

5658
useEffect(() => {
57-
if (nonce === "" && historyTxs?.results.length) {
58-
setNonce(historyTxs?.results.length.toString());
59+
if (nonce === "" && nextNonce) {
60+
setNonce(nextNonce.toString());
5961
}
60-
}, [historyTxs]);
62+
}, [nextNonce]);
6163

6264
return (
6365
<div className="flex flex-col space-y-2 sm:space-y-0 space-x-0 sm:space-x-2 sm:flex-row">
@@ -87,7 +89,7 @@ export default function SafeTransactionCreator({
8789
<input
8890
type="number"
8991
step={1}
90-
min={historyTxs?.results.length || 0}
92+
min={nextNonce}
9193
value={nonce}
9294
onChange={(e) => setNonce(e.target.value)}
9395
className="relative -ml-px inline-flex w-20 items-center rounded-r-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-10"

components/Transaction/SafeTransactionSelector.tsx

+20-15
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
import { formatDistanceToNowStrict, parseISO } from "date-fns";
1+
import { formatDistanceToNowStrict, toDate } from "date-fns";
22
import { useMultisigTransactions } from "@/utils/hooks/Safe/SafeHooks";
33
import SearchableComboBox, {
44
Option,
55
} from "@/components/common/SearchableComboBox";
6-
import { SafeMultisigTransactionListResponse } from "@safe-global/api-kit";
7-
import { RevisedSafeMultisigTransactionResponse } from "@/models/SafeTypes";
6+
import {
7+
SafeTransactionsResponse,
8+
SafetransactionsResponseResult,
9+
} from "@/models/SafeTypes";
810
import { useQueryParams, withDefault, StringParam } from "next-query-params";
911
import { useEffect } from "react";
1012

11-
export type TxOption = Option & { tx: RevisedSafeMultisigTransactionResponse };
13+
export type TxOption = Option & { tx: SafetransactionsResponseResult };
1214
export type AddressMap = { [address: string]: string };
1315

1416
export function SafeTransactionSelector({
@@ -29,21 +31,24 @@ export function SafeTransactionSelector({
2931
const { data: txns, isLoading } = useMultisigTransactions(safeAddress, 20);
3032

3133
const convertToOptions = (
32-
res: SafeMultisigTransactionListResponse | undefined,
33-
status: boolean,
34+
res: SafeTransactionsResponse | undefined,
35+
status: boolean
3436
) => {
3537
if (!res) return [];
36-
return res.results.map((_tx) => {
37-
const tx = _tx as any as RevisedSafeMultisigTransactionResponse;
38-
const addressLabel = addressMap[tx.to] ? `${addressMap[tx.to]}.` : "";
38+
return res.results.map((tx) => {
39+
const txTo = tx.transaction.txInfo.to.value;
40+
const addressLabel = addressMap[txTo] ? `${addressMap[txTo]}.` : "";
3941
return {
40-
id: tx.safeTxHash,
41-
label: `Tx ${tx.nonce} ${addressLabel}${
42-
tx.dataDecoded ? tx.dataDecoded.method : "unknown"
42+
id: tx.transaction.id,
43+
label: `Tx ${tx.transaction.executionInfo.nonce} ${addressLabel}${
44+
tx.transaction.txInfo.methodName || "unknown"
4345
}`,
44-
extraLabel: formatDistanceToNowStrict(parseISO(tx.submissionDate), {
45-
addSuffix: true,
46-
}),
46+
extraLabel: formatDistanceToNowStrict(
47+
toDate(tx.transaction.timestamp),
48+
{
49+
addSuffix: true,
50+
}
51+
),
4752
status,
4853
tx: tx,
4954
};

models/SafeTypes.ts

+21-6
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,19 @@ export interface SafeBalanceUsdResponse {
6868
}
6969

7070
export interface SafeInfoResponse {
71-
address: string;
71+
address: {
72+
value: string;
73+
};
7274
nonce: number;
75+
chainId: string;
7376
threshold: number;
74-
owners: string[];
75-
masterCopy: string;
76-
modules: string[];
77-
fallbackHandler: string;
77+
owners: { value: string }[];
78+
modules: string[] | null;
79+
fallbackHandler: {
80+
name: string;
81+
value: string;
82+
};
7883
version: string;
79-
guard: string;
8084
}
8185

8286
export interface SafeDelegatesResponse {
@@ -131,6 +135,17 @@ export interface SafetransactionsResponseResult {
131135
id: string;
132136
timestamp: number;
133137
txHash: string;
138+
executionInfo: {
139+
nonce: number;
140+
};
141+
txInfo: {
142+
methodName: string;
143+
humanDescription: string | null;
144+
to: {
145+
value: string;
146+
name: string;
147+
};
148+
};
134149
};
135150
}
136151

pages/review.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
withDefault,
99
} from "next-query-params";
1010
import useProjectInfo from "../utils/hooks/juicebox/ProjectInfo";
11-
import { RevisedSafeMultisigTransactionResponse } from "../models/SafeTypes";
11+
import { SafetransactionsResponseResult } from "../models/SafeTypes";
1212
import parseSafeJuiceboxTx from "../utils/functions/SafeJuiceboxParser";
1313
import { useReconfigurationOfProject } from "../utils/hooks/juicebox/ReconfigurationOfProject";
1414
import DiffTableWithSection from "../components/form/DiffTableWithSection";
@@ -25,6 +25,7 @@ import {
2525
} from "@/components/Transaction/SafeTransactionSelector";
2626
import ProjectSearch from "@/components/ProjectSearch";
2727
import JBProjectInfo from "@/components/JuiceboxCard/JBProjectInfo";
28+
import { toDate } from "date-fns";
2829

2930
const CONTRACT_MAP: AddressMap = {
3031
"0xFFdD70C318915879d5192e8a0dcbFcB0285b3C98": "JBController_V3",
@@ -115,13 +116,16 @@ function Compare({
115116
tx,
116117
}: {
117118
projectId: number;
118-
tx: RevisedSafeMultisigTransactionResponse;
119+
tx: SafetransactionsResponseResult;
119120
}) {
120121
const { value: currentConfig, loading: loading } =
121122
useReconfigurationOfProject(projectId);
122123
const newConfig = parseSafeJuiceboxTx(
123-
tx.data || "",
124-
tx?.submissionDate || "",
124+
//tx.data || "",
125+
// FIXME new Safe endpoint doesn't return data anymore
126+
// which makes Review page no longer working
127+
"",
128+
toDate(tx.transaction.timestamp).toISOString() || "",
125129
currentConfig.fundingCycle.fee || BigInt(0),
126130
currentConfig.fundingCycle.configuration || BigInt(0)
127131
);

utils/hooks/ContractHooks.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function useContractType(rawAddress: string) {
7575
return ContractType.Unknown;
7676
}
7777

78-
if (!safeError && safeInfo?.masterCopy) {
78+
if (!safeError && safeInfo?.owners) {
7979
return ContractType.Safe;
8080
} else {
8181
// there is no way to be sure if this is a governor contract

utils/hooks/Safe/SafeHooks.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export function useCreateTransactionForSimulation(
161161

162162
const { value: safe, error: safeError } = useSafe(safeAddress);
163163
const { data: safeInfo } = useSafeInfo(safeAddress, !!safeAddress);
164-
const firstOwnerAddress = safeInfo?.owners?.[0] || zeroAddress;
164+
const firstOwnerAddress = safeInfo?.owners?.[0].value || zeroAddress;
165165

166166
useEffect(() => {
167167
const fetch = async () => {

0 commit comments

Comments
 (0)