Skip to content
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

Bug/multisig nonce selection #1516

Merged
merged 18 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions src/hooks/DAO/loaders/useFractalNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { NodeAction } from '../../../providers/App/node/action';
import { useNetworkConfig } from '../../../providers/NetworkConfig/NetworkConfigProvider';
import { Node } from '../../../types';
import { mapChildNodes } from '../../../utils/hierarchy';
import { useAsyncRetry } from '../../utils/useAsyncRetry';
import { useLazyDAOName } from '../useDAOName';
import { useFractalModules } from './useFractalModules';

Expand All @@ -33,7 +32,6 @@ export const useFractalNode = (
const { getDaoName } = useLazyDAOName();

const lookupModules = useFractalModules();
const { requestWithRetries } = useAsyncRetry();

const formatDAOQuery = useCallback((result: { data?: DAOQueryQuery }, _daoAddress: string) => {
if (!result.data) {
Expand Down Expand Up @@ -98,21 +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 requestWithRetries(
() => safeAPI.getSafeInfo(utils.getAddress(_daoAddress)),
5,
);
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;
}
DarksightKellar marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -121,15 +120,15 @@ 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, requestWithRetries, reset, safeAPI],
[action, lookupModules, reset, safeAPI],
);

useEffect(() => {
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
2 changes: 1 addition & 1 deletion src/pages/daos/[daoAddress]/proposals/new/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default function ProposalCreatePage() {
return (
<Formik<CreateProposalForm>
validationSchema={createProposalValidation}
initialValues={{ ...DEFAULT_PROPOSAL, nonce: safe.nonce }}
initialValues={{ ...DEFAULT_PROPOSAL, nonce: safe.nonceWithPending }}
onSubmit={async values => {
const { nonce } = values;
const proposalData = await prepareProposal(values);
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