/* eslint-disable eslint-comments/disable-enable-pair */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ import { GasPrice, SigningStargateClient } from '@cosmjs/stargate' import { Alert } from 'components/Alert' import { Button } from 'components/Button' import { ContractPageHeader } from 'components/ContractPageHeader' import { TextInput } from 'components/forms/FormInput' import { useInputState } from 'components/forms/FormInput.hooks' import { LinkTabs } from 'components/LinkTabs' import { authzLinkTabs } from 'components/LinkTabs.data' import { getConfig } from 'config' import type { NextPage } from 'next' import { NextSeo } from 'next-seo' import { useState } from 'react' import toast from 'react-hot-toast' import { NETWORK } from 'utils/constants' import { withMetadata } from 'utils/layout' import { useWallet } from 'utils/wallet' const RevokeAuthorization: NextPage = () => { const wallet = useWallet() const [transactionHash, setTransactionHash] = useState(undefined) const [isLoading, setIsLoading] = useState(false) const granteeAddressState = useInputState({ id: 'grantee-address', name: 'granteeAddress', title: 'Grantee Address', subtitle: 'Address to revoke message authorization', placeholder: 'stars1...', }) const messageState = useInputState({ id: 'message', name: 'message', title: 'Message', subtitle: 'Message to revoke authorization for', placeholder: '/cosmos.bank.v1beta1.MsgSend', defaultValue: '/cosmos.bank.v1beta1.MsgSend', }) const revokeAuthorization = async (granteeAddress: string, msg: string) => { try { if (!wallet.isWalletConnected) throw new Error('Wallet not connected.') setTransactionHash(undefined) setIsLoading(true) const offlineSigner = wallet.getOfflineSignerDirect() const stargateClient = await SigningStargateClient.connectWithSigner(getConfig(NETWORK).rpcUrl, offlineSigner, { gasPrice: GasPrice.fromString('0.25ustars'), }) const response = await stargateClient.signAndBroadcast( wallet.address || '', [ { typeUrl: '/cosmos.authz.v1beta1.MsgRevoke', value: { granter: wallet.address, grantee: granteeAddress, msgTypeUrl: msg, }, }, ], { amount: [{ amount: '500000', denom: 'ustars' }], gas: '200000', }, ) setTransactionHash(response.transactionHash) if (response.rawLog?.includes('failed')) toast.error(response.rawLog, { style: { maxWidth: 'none' } }) else toast.success(`Revoke authorization success.`, { style: { maxWidth: 'none' } }) setIsLoading(false) } catch (e: any) { console.log(e) setIsLoading(false) setTransactionHash(undefined) toast.error(e.message, { style: { maxWidth: 'none' } }) } } return (
Authorization Type
{/* */} {transactionHash && ( {`Transaction Hash: ${transactionHash}`} )}
) } export default withMetadata(RevokeAuthorization, { center: false })