Skip to content

Commit

Permalink
fix(idea/frontend): read sails state (#1594)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitayutanov authored Jul 11, 2024
1 parent b2218d6 commit 4542ef7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function useService(sails: Sails, key: 'functions' | 'queries') {

const functions = services[select.value][key];
const functionSelect = useSelect(functions, { label: key === 'functions' ? 'Function' : 'Query' });
const { args, encodePayload, decodePayload } = functions[functionSelect.value];
const { args, encodePayload, decodeResult } = functions[functionSelect.value];

const defaultValues = useMemo(
() => getDefaultPayloadValue(sails, args),
Expand All @@ -31,7 +31,7 @@ function useService(sails: Sails, key: 'functions' | 'queries') {
[select.value, functionSelect.value],
);

return { select, functionSelect, defaultValues, schema, args, decodePayload };
return { select, functionSelect, defaultValues, schema, args, decodeResult };
}

export { useService };
6 changes: 3 additions & 3 deletions idea/frontend/src/pages/state/ui/sails/sails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const StateForm = ({ programId, sails }: { programId: HexString; sails: SailsTyp
const { account } = useAccount();
const alert = useAlert();
// would be better if useService could accept undefined sails?
const { select, functionSelect, args, decodePayload, ...query } = useService(sails, 'queries');
const { select, functionSelect, args, decodeResult, ...query } = useService(sails, 'queries');

const defaultValues = { ...INITIAL_VALUES, payload: query.defaultValues };
const schema = query.schema ? z.object({ payload: query.schema }) : undefined;
Expand All @@ -37,7 +37,7 @@ const StateForm = ({ programId, sails }: { programId: HexString; sails: SailsTyp

const readQuery = async (payload: PayloadValue | undefined): Promise<AnyJson> => {
if (!api) throw new Error('API is not initialized');
if (!decodePayload) throw new Error('Sails is not found');
if (!decodeResult) throw new Error('Sails is not found');

const result = await api.message.calculateReply({
destination: programId,
Expand All @@ -47,7 +47,7 @@ const StateForm = ({ programId, sails }: { programId: HexString; sails: SailsTyp
payload,
});

return decodePayload(result.payload.toHex());
return decodeResult(result.payload.toHex());
};

// decode numbers bigger than 64 bits (BigInt)?
Expand Down

0 comments on commit 4542ef7

Please sign in to comment.