diff --git a/pages/revoke.tsx b/pages/revoke.tsx new file mode 100644 index 0000000..0fd5301 --- /dev/null +++ b/pages/revoke.tsx @@ -0,0 +1,96 @@ +/* eslint-disable eslint-comments/disable-enable-pair */ +/* eslint-disable @typescript-eslint/no-unsafe-member-access */ +import { coins } from '@cosmjs/proto-signing' +import { ContractPageHeader } from 'components/ContractPageHeader' +import { TextInput } from 'components/forms/FormInput' +import { useInputState } from 'components/forms/FormInput.hooks' +import { useWallet } from 'contexts/wallet' +import type { NextPage } from 'next' +import { NextSeo } from 'next-seo' +import { useState } from 'react' +import toast from 'react-hot-toast' +import { withMetadata } from 'utils/layout' +import { links } from 'utils/links' + +const RevokeAuthorization: NextPage = () => { + const wallet = useWallet() + const client = wallet.getClient() + + const [transactionHash, setTransactionHash] = useState(undefined) + + const granteeAddressState = useInputState({ + id: 'grantee-address', + name: 'granteeAddress', + title: 'Grantee Address', + subtitle: 'Address to revoke message authorization', + placeholder: 'stars1234567890abcdefghijklmnopqrstuvwxyz...', + defaultValue: 'stars12vfpmlvmqrh9p0kcrtv6lw9ylkh7reuczdmmz5', + }) + + 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) => { + console.log('Wallet Address: ', wallet.address) + try { + await wallet.connect() + const result = await client.signAndBroadcast( + wallet.address, + [ + { + typeUrl: '/cosmos.authz.v1beta1.MsgRevoke', + value: { + granter: wallet.address, + grantee: granteeAddress, + msgTypeUrl: msg, + funds: coins('100000', 'ustars'), + }, + }, + ], + 'auto', + ) + setTransactionHash(result.transactionHash) + } catch (e: any) { + console.log(e) + toast.error(e.message, { style: { maxWidth: 'none' } }) + } + } + + return ( +
+ + + +
Message Types
+ + + + {transactionHash && ( +
{`Transaction Hash: ${transactionHash}`}
+ )} +
+ ) +} +export default withMetadata(RevokeAuthorization, { center: false })