Skip to content

Commit

Permalink
Add new property to SafeInfoResponseWithGuard
Browse files Browse the repository at this point in the history
called `nonceWithPending`, which will be the next nonce to use which takes into account all "pending" transactions on the safe
  • Loading branch information
adamgall committed Apr 4, 2024
1 parent d259700 commit 932fc1b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
16 changes: 10 additions & 6 deletions src/hooks/DAO/loaders/useFractalNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,22 @@ export const useFractalNode = (
currentValidSafe.current = _addressPrefix + _daoAddress;
setErrorLoading(false);

let safeInfo;
let safeInfoResponseWithGuard;

try {
if (!safeAPI) throw new Error('SafeAPI not set');

safeInfo = await safeAPI.getSafeInfo(utils.getAddress(_daoAddress));
const address = utils.getAddress(_daoAddress);
const safeInfo = await safeAPI.getSafeInfo(address);
const allTransactions = await safeAPI.getAllTransactions(address);
safeInfoResponseWithGuard = { ...safeInfo, nonceWithPending: allTransactions.count };
} catch (e) {
reset({ error: true });
return;
}

if (!safeInfo) {
// comment to pick up in review: will `safeInfoResponseWithGuard` ever not be set?
// typescript doesn't think so.
if (!safeInfoResponseWithGuard) {
reset({ error: true });
return;
}
Expand All @@ -116,12 +120,12 @@ export const useFractalNode = (

action.dispatch({
type: NodeAction.SET_FRACTAL_MODULES,
payload: await lookupModules(safeInfo.modules),
payload: await lookupModules(safeInfoResponseWithGuard.modules),
});

action.dispatch({
type: NodeAction.SET_SAFE_INFO,
payload: safeInfo,
payload: safeInfoResponseWithGuard,
});
},
[action, lookupModules, reset, safeAPI],
Expand Down
13 changes: 9 additions & 4 deletions src/hooks/DAO/loaders/useLoadDAONode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,18 @@ export const useLoadDAONode = () => {
logError('graphQL query failed');
return { error: 'errorFailedSearch' };
}
const safe = await safeAPI.getSafeInfo(_daoAddress);
const fractalModules = await lookupModules(safe.modules);
const daoName = await getDaoName(utils.getAddress(safe.address), graphNodeInfo.daoName);
const safeInfo = await safeAPI.getSafeInfo(_daoAddress);
const allTransactions = await safeAPI.getAllTransactions(_daoAddress);
const safeInfoWithGuard = { ...safeInfo, nonceWithPending: allTransactions.count };
const fractalModules = await lookupModules(safeInfo.modules);
const daoName = await getDaoName(
utils.getAddress(safeInfo.address),
graphNodeInfo.daoName,
);

const node: FractalNode = Object.assign(graphNodeInfo, {
daoName,
safe,
safe: safeInfoWithGuard,
fractalModules,
});

Expand Down
1 change: 1 addition & 0 deletions src/types/safeGlobal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export declare type DataDecoded = {
};

export type SafeInfoResponseWithGuard = SafeInfoResponse & {
nonceWithPending: number;
guard?: string;
};

Expand Down

0 comments on commit 932fc1b

Please sign in to comment.