Multisig-signer: Ensuring we await the data from useLazyQuery properly (#1832)

* Feat/1512: Ensuring we await the data from useLazyQuery properly

* Feat/1512: Removed redundant await
This commit is contained in:
Sam Keen 2022-10-21 15:20:11 +01:00 committed by GitHub
parent bbb6cfe780
commit 33be5bc069
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 22 deletions

View File

@ -10,7 +10,6 @@ import {
InputError, InputError,
Loader, Loader,
} from '@vegaprotocol/ui-toolkit'; } from '@vegaprotocol/ui-toolkit';
import { prepend0x } from '@vegaprotocol/smart-contracts';
import { useContracts } from '../../config/contracts/contracts-context'; import { useContracts } from '../../config/contracts/contracts-context';
import type { FormEvent } from 'react'; import type { FormEvent } from 'react';
import type { import type {
@ -37,7 +36,7 @@ export const AddSignerForm = () => {
const { multisig } = useContracts(); const { multisig } = useContracts();
const [address, setAddress] = useState(''); const [address, setAddress] = useState('');
const [bundleNotFound, setBundleNotFound] = useState(false); const [bundleNotFound, setBundleNotFound] = useState(false);
const [runQuery, { data, error, loading }] = useLazyQuery< const [runQuery, { error, loading }] = useLazyQuery<
AddSignerBundle, AddSignerBundle,
AddSignerBundleVariables AddSignerBundleVariables
>(ADD_SIGNER_QUERY); >(ADD_SIGNER_QUERY);
@ -52,10 +51,12 @@ export const AddSignerForm = () => {
if (address === '') { if (address === '') {
return; return;
} }
await runQuery({ const result = await runQuery({
variables: { nodeId: address }, variables: { nodeId: address },
}); });
const bundle = data?.erc20MultiSigSignerAddedBundles?.edges?.[0]?.node;
const bundle =
result.data?.erc20MultiSigSignerAddedBundles?.edges?.[0]?.node;
if (!bundle) { if (!bundle) {
if (!error) { if (!error) {
@ -64,13 +65,7 @@ export const AddSignerForm = () => {
return; return;
} }
await perform( await perform(bundle.newSigner, bundle.nonce, bundle.signatures);
bundle.newSigner,
bundle.nonce.startsWith('0x') ? bundle.nonce : prepend0x(bundle.nonce),
bundle.signatures.startsWith('0x')
? bundle.signatures
: prepend0x(bundle.signatures)
);
} catch (err: unknown) { } catch (err: unknown) {
captureException(err); captureException(err);
} }

View File

@ -10,7 +10,6 @@ import {
InputError, InputError,
Loader, Loader,
} from '@vegaprotocol/ui-toolkit'; } from '@vegaprotocol/ui-toolkit';
import { prepend0x } from '@vegaprotocol/smart-contracts';
import { useContracts } from '../../config/contracts/contracts-context'; import { useContracts } from '../../config/contracts/contracts-context';
import type { FormEvent } from 'react'; import type { FormEvent } from 'react';
import type { import type {
@ -37,7 +36,7 @@ export const RemoveSignerForm = () => {
const { multisig } = useContracts(); const { multisig } = useContracts();
const [address, setAddress] = useState(''); const [address, setAddress] = useState('');
const [bundleNotFound, setBundleNotFound] = useState(false); const [bundleNotFound, setBundleNotFound] = useState(false);
const [runQuery, { data, error, loading }] = useLazyQuery< const [runQuery, { error, loading }] = useLazyQuery<
RemoveSignerBundle, RemoveSignerBundle,
RemoveSignerBundleVariables RemoveSignerBundleVariables
>(REMOVE_SIGNER_QUERY); >(REMOVE_SIGNER_QUERY);
@ -52,10 +51,12 @@ export const RemoveSignerForm = () => {
if (address === '') { if (address === '') {
return; return;
} }
await runQuery({ const result = await runQuery({
variables: { nodeId: address }, variables: { nodeId: address },
}); });
const bundle = data?.erc20MultiSigSignerRemovedBundles?.edges?.[0]?.node;
const bundle =
result.data?.erc20MultiSigSignerRemovedBundles?.edges?.[0]?.node;
if (!bundle) { if (!bundle) {
if (!error) { if (!error) {
@ -64,13 +65,7 @@ export const RemoveSignerForm = () => {
return; return;
} }
await perform( await perform(bundle.oldSigner, bundle.nonce, bundle.signatures);
bundle.oldSigner,
bundle.nonce.startsWith('0x') ? bundle.nonce : prepend0x(bundle.nonce),
bundle.signatures.startsWith('0x')
? bundle.signatures
: prepend0x(bundle.signatures)
);
} catch (err: unknown) { } catch (err: unknown) {
captureException(err); captureException(err);
} }