Skip to content

Commit

Permalink
chore: Multisig user verification update (#1225)
Browse files Browse the repository at this point in the history
* chore: add cosmos address for verification

* chore: fix lint issues

* chore: remove dependency on cosmos network

* chore: fix lint issue

---------

Co-authored-by: chary <[email protected]>
  • Loading branch information
Hemanthghs and charymalloju authored Apr 25, 2024
1 parent 200c0f4 commit 7ac76d6
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 48 deletions.
9 changes: 3 additions & 6 deletions frontend/src/app/(routes)/multisig/components/AccountInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { getTimeDifferenceToFutureDate } from '@/utils/dataTime';
import CommonCopy from '@/components/CommonCopy';
import { getAuthToken } from '@/utils/localStorage';
import useVerifyAccount from '@/custom-hooks/useVerifyAccount';
import { COSMOS_CHAIN_ID } from '@/utils/constants';

interface AccountInfoProps {
chainID: string;
Expand Down Expand Up @@ -101,7 +102,6 @@ const AccountInfo: React.FC<AccountInfoProps> = (props) => {
coinMinimalDenom,
coinDecimals,
})}
chainID={chainID}
isAdmin={isAdmin}
walletAddress={walletAddress}
/>
Expand All @@ -117,7 +117,6 @@ const AccountDetails = ({
balance,
stakedBalance,
chainName,
chainID,
isAdmin,
walletAddress,
}: {
Expand All @@ -126,7 +125,6 @@ const AccountDetails = ({
balance: string;
stakedBalance: string;
chainName: string;
chainID: string;
isAdmin: boolean;
walletAddress: string;
}) => {
Expand All @@ -138,7 +136,6 @@ const AccountDetails = ({
(state: RootState) => state.multisig.deleteMultisigRes
);
const { isAccountVerified } = useVerifyAccount({
chainID,
address: walletAddress,
});

Expand All @@ -159,15 +156,15 @@ const AccountDetails = ({
}
}, [deleteMultisigRes?.status]);

const authToken = getAuthToken(chainID);
const authToken = getAuthToken(COSMOS_CHAIN_ID);

const handleDelete = () => {
if (isAdmin) {
dispatch(
deleteMultisig({
data: { address: multisigAccount?.account?.address },
queryParams: {
address: authToken?.address || '',
address: walletAddress || '',
signature: authToken?.signature || '',
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const AllMultisigs: React.FC<AllMultisigsProps> = (props) => {
const { pubkey } = accountInfo;
const { getChainInfo } = useGetChainInfo();
const { prefix, restURLs } = getChainInfo(chainID);
const { isAccountVerified } = useVerifyAccount({ chainID, address });
const { isAccountVerified } = useVerifyAccount({ address });

useEffect(() => {
if (address) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { MultisigTxStatus } from '@/types/enums';
import { FAILED_TO_BROADCAST_ERROR } from '@/utils/errors';
import { CircularProgress } from '@mui/material';
import useVerifyAccount from '@/custom-hooks/useVerifyAccount';
import { COSMOS_CHAIN_ID } from '@/utils/constants';

interface BroadCastTxnProps {
txn: Txn;
Expand All @@ -36,7 +37,6 @@ const BroadCastTxn: React.FC<BroadCastTxnProps> = (props) => {
const { getChainInfo } = useGetChainInfo();
const { rpc, address: walletAddress } = getChainInfo(chainID);
const { isAccountVerified } = useVerifyAccount({
chainID,
address: walletAddress,
});

Expand Down Expand Up @@ -67,7 +67,7 @@ const BroadCastTxn: React.FC<BroadCastTxnProps> = (props) => {
return;
}
setLoad(true);
const authToken = getAuthToken(chainID);
const authToken = getAuthToken(COSMOS_CHAIN_ID);
const queryParams = {
address: walletAddress,
signature: authToken?.signature || '',
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/(routes)/multisig/components/DeleteTxn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Image from 'next/image';
import React, { useState } from 'react';
import DialogDeleteTxn from './DialogDeleteTxn';
import useVerifyAccount from '@/custom-hooks/useVerifyAccount';
import { COSMOS_CHAIN_ID } from '@/utils/constants';

interface DeleteTxnProps {
txId: number;
Expand All @@ -23,9 +24,8 @@ const DeleteTxn: React.FC<DeleteTxnProps> = (props) => {
const [deleteDialogOpen, setDeleteDialogOpen] = useState<boolean>(false);
const { getChainInfo } = useGetChainInfo();
const { address: walletAddress } = getChainInfo(chainID);
const authToken = getAuthToken(chainID);
const authToken = getAuthToken(COSMOS_CHAIN_ID);
const { isAccountVerified } = useVerifyAccount({
chainID,
address: walletAddress,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { TxStatus } from '@/types/enums';
import { fromBech32 } from '@cosmjs/encoding';
import { DialogCreateMultisigProps, PubKeyFields } from '@/types/multisig';
import MultisigMemberTextField from './MultisigMemberTextField';
import { MULTISIG_PUBKEY_OBJECT } from '@/utils/constants';
import { COSMOS_CHAIN_ID, MULTISIG_PUBKEY_OBJECT } from '@/utils/constants';
import useGetPubkey from '@/custom-hooks/useGetPubkey';

const MAX_PUB_KEYS = 7;
Expand Down Expand Up @@ -253,7 +253,7 @@ const DialogCreateMultisig: React.FC<DialogCreateMultisigProps> = (props) => {
Number(threshold),
addressPrefix
);
const authToken = getAuthToken(chainID);
const authToken = getAuthToken(COSMOS_CHAIN_ID);
const queryParams = {
address: address,
signature: authToken?.signature || '',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
CLOSE_ICON_PATH,
COSMOS_CHAIN_ID,
DELEGATE_TYPE_URL,
MULTISIG_DELEGATE_TEMPLATE,
MULTISIG_REDELEGATE_TEMPLATE,
Expand Down Expand Up @@ -418,7 +419,7 @@ const DialogCreateTxn: React.FC<DialogCreateTxnProps> = (props) => {
data.fees.toString(),
data.gas
);
const authToken = getAuthToken(chainID);
const authToken = getAuthToken(COSMOS_CHAIN_ID);
dispatch(
createTxn({
data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ import { setVerifyDialogOpen } from '@/store/features/multisig/multisigSlice';
import Image from 'next/image';
import { CLOSE_ICON_PATH } from '@/utils/constants';

const DialogVerifyAccount = ({
address,
chainID,
}: {
chainID: string;
address: string;
}) => {
const DialogVerifyAccount = ({ address }: { address: string }) => {
const dispatch = useAppDispatch();
const open = useAppSelector((state) => state.multisig.verifyDialogOpen);
const handleClose = () => {
Expand Down Expand Up @@ -43,7 +37,7 @@ const DialogVerifyAccount = ({
</div>
</div>
<div className="mb-10 flex gap-6 px-10 items-center">
<VerifyAccount chainID={chainID} walletAddress={address} />
<VerifyAccount walletAddress={address} />
</div>
</div>
</DialogContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const MultisigSidebar: React.FC<MultisigSidebarProps> = (props) => {
(state: RootState) => state.multisig.deleteTxnRes
);
const { isAccountVerified } = useVerifyAccount({
chainID,
address: walletAddress,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const PageMultisig = ({ chainName }: { chainName: string }) => {
walletAddress={address}
accountSpecific={false}
/>
<DialogVerifyAccount address={address} chainID={chainID} />
<DialogVerifyAccount address={address} />
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const PageMultisigInfo: React.FC<PageMultisigInfoProps> = (props) => {
address={address}
walletAddress={walletAddress}
/>
<DialogVerifyAccount address={walletAddress} chainID={chainID} />
<DialogVerifyAccount address={walletAddress} />
</div>
);
};
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/(routes)/multisig/components/SignTxn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import React, { useState } from 'react';
import { CircularProgress } from '@mui/material';
import { ERR_UNKNOWN } from '@/utils/errors';
import useVerifyAccount from '@/custom-hooks/useVerifyAccount';
import { COSMOS_CHAIN_ID } from '@/utils/constants';

interface SignTxnProps {
address: string;
Expand All @@ -32,7 +33,6 @@ const SignTxn: React.FC<SignTxnProps> = (props) => {
const { getChainInfo } = useGetChainInfo();
const { rpc, address: walletAddress } = getChainInfo(chainID);
const { isAccountVerified } = useVerifyAccount({
chainID,
address: walletAddress,
});

Expand Down Expand Up @@ -91,7 +91,7 @@ const SignTxn: React.FC<SignTxnProps> = (props) => {
signature: toBase64(signatures[0]),
};

const authToken = getAuthToken(chainID);
const authToken = getAuthToken(COSMOS_CHAIN_ID);
dispatch(
signTx({
data: payload,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ import Image from 'next/image';
import React from 'react';

interface VerifyAccountProps {
chainID: string;
walletAddress: string;
}

const VerifyAccount: React.FC<VerifyAccountProps> = (props) => {
const { chainID, walletAddress } = props;
const { walletAddress } = props;
const { verifyOwnership } = useVerifyAccount({
chainID,
address: walletAddress,
});
const handleVerifyAccountEvent = () => {
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/custom-hooks/useGetChainInfo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useCallback } from 'react';
import { RootState } from '@/store/store';
import { useAppSelector } from './StateHooks';
import { COSMOS_CHAIN_ID } from '@/utils/constants';
import { getAddressByPrefix } from '@/utils/address';

export interface DenomInfo {
Expand Down Expand Up @@ -61,7 +60,7 @@ const useGetChainInfo = () => {
const chainName = config.chainName.toLowerCase();

const aminoCfg = network?.aminoConfig;
const cosmosAddress = networks[COSMOS_CHAIN_ID].walletInfo.bech32Address;
const cosmosAddress = getCosmosAddress();
const prefix = config?.bech32Config.bech32PrefixAccAddr;
const valPrefix = config?.bech32Config.bech32PrefixValAddr;
const feeAmount = config?.feeCurrencies[0].gasPriceStep?.average || 0;
Expand Down
24 changes: 13 additions & 11 deletions frontend/src/custom-hooks/useVerifyAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,20 @@ import {
import { setAuthToken } from '@/utils/localStorage';
import { setError } from '@/store/features/common/commonSlice';
import { isVerified } from '@/utils/util';
import { COSMOS_CHAIN_ID } from '@/utils/constants';
import { getAddressByPrefix } from '@/utils/address';

const useVerifyAccount = ({
address,
chainID,
}: {
chainID: string;
address: string;
}) => {
const useVerifyAccount = ({ address }: { address: string }) => {
const dispatch = useAppDispatch();
const verifyAccountRes = useAppSelector(
(state) => state.multisig.verifyAccountRes
);
const cosmosAddresss = getAddressByPrefix(address, 'cosmos');
useEffect(() => {
if (verifyAccountRes.status === 'idle') {
setAuthToken({
chainID: chainID,
address: address,
chainID: COSMOS_CHAIN_ID,
address: cosmosAddresss,
signature: verifyAccountRes.token,
});
dispatch(setVerifyDialogOpen(false));
Expand All @@ -46,11 +43,16 @@ const useVerifyAccount = ({
}, [verifyAccountRes]);

const verifyOwnership = () => {
dispatch(verifyAccount({ chainID, address }));
dispatch(
verifyAccount({ chainID: COSMOS_CHAIN_ID, address: cosmosAddresss })
);
};

const isAccountVerified = () => {
const verified = isVerified({ chainID, address });
const verified = isVerified({
chainID: COSMOS_CHAIN_ID,
address: cosmosAddresss,
});
return verified;
};
return { verifyOwnership, isAccountVerified };
Expand Down
10 changes: 6 additions & 4 deletions frontend/src/store/features/multisig/multisigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
VerifyUserPayload,
} from '@/types/multisig';
import { API_URL } from '@/utils/constants';
import { getAddressByPrefix } from '@/utils/address';

const BASE_URL: string = cleanURL(API_URL);

Expand All @@ -19,6 +20,8 @@ const GET_ACCOUNTS_URL = '/multisig/accounts';
const SIGNATURE_PARAMS_STRING = (queryParams: QueryParams): string =>
`?address=${encodeURIComponent(
queryParams.address
)}&cosmos_address=${encodeURIComponent(
getAddressByPrefix(queryParams.address, 'cosmos')
)}&signature=${encodeURIComponent(queryParams.signature)}`;

const CREATE_ACCOUNT = (queryParams: QueryParams): string =>
Expand Down Expand Up @@ -78,7 +81,7 @@ const updateTx = (
): Promise<AxiosResponse> =>
Axios.post(
`${BASE_URL}/multisig/${address}/tx/${txId}` +
SIGNATURE_PARAMS_STRING(queryParams),
SIGNATURE_PARAMS_STRING(queryParams),
payload
);

Expand All @@ -105,16 +108,15 @@ export const deleteTx = (
): Promise<AxiosResponse> =>
Axios.delete(
`${BASE_URL}/multisig/${address}/tx/${txId}` +
SIGNATURE_PARAMS_STRING(queryParams)
SIGNATURE_PARAMS_STRING(queryParams)
);

export const deleteMultisig = (
queryParams: QueryParams,
address: string
): Promise<AxiosResponse> =>
Axios.delete(
`${BASE_URL}/multisig/${address}` +
SIGNATURE_PARAMS_STRING(queryParams)
`${BASE_URL}/multisig/${address}` + SIGNATURE_PARAMS_STRING(queryParams)
);

export default {
Expand Down
2 changes: 1 addition & 1 deletion server/middleware/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func (h *Handler) AuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
signature := c.QueryParams().Get("signature")
address := c.QueryParams().Get("address")
address := c.QueryParams().Get("cosmos_address")

if address == "" {
return c.JSON(http.StatusNotAcceptable, model.ErrorResponse{
Expand Down

0 comments on commit 7ac76d6

Please sign in to comment.