diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ea6a0d6f..cab5a22bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Improvements +- [#709](https://github.com/alleslabs/celatone-frontend/pull/709) refactor all address types + ### Bug fixes ## v1.4.1 diff --git a/src/lib/amplitude/track-event/trackInteraction.ts b/src/lib/amplitude/track-event/trackInteraction.ts index d74d166ef..8c60a76a3 100644 --- a/src/lib/amplitude/track-event/trackInteraction.ts +++ b/src/lib/amplitude/track-event/trackInteraction.ts @@ -3,7 +3,7 @@ import big from "big.js"; import { amp } from "../Amplitude"; import { AmpEvent } from "../types"; import type { SearchResultType } from "lib/services/searchService"; -import type { MoveAccountAddr, Option, Token } from "lib/types"; +import type { Addr, Option, Token } from "lib/types"; import { isHexModuleAddress, isHexWalletAddress } from "lib/utils"; export const trackUseMainSearch = ( @@ -197,7 +197,7 @@ export const trackUseToggle = (name: string, isActive: boolean) => amp.track(AmpEvent.USE_TOGGLE, { name, isActive }); export const trackUseModuleSelectionInputFill = ( - address: MoveAccountAddr, + address: Addr, manualModuleName: boolean, manualFunctionName: boolean ) => diff --git a/src/lib/app-fns/tx/clearAdmin.tsx b/src/lib/app-fns/tx/clearAdmin.tsx index 27fd04919..ff90aa114 100644 --- a/src/lib/app-fns/tx/clearAdmin.tsx +++ b/src/lib/app-fns/tx/clearAdmin.tsx @@ -10,7 +10,7 @@ import { EstimatedFeeRender } from "lib/components/EstimatedFeeRender"; import { ExplorerLink } from "lib/components/ExplorerLink"; import { CustomIcon } from "lib/components/icon"; import { TxStreamPhase } from "lib/types"; -import type { TxResultRendering, ContractAddr, HumanAddr } from "lib/types"; +import type { BechAddr20, BechAddr32, TxResultRendering } from "lib/types"; import { feeFromStr } from "lib/utils"; import { catchTxError } from "./common"; @@ -18,8 +18,8 @@ import { postTx } from "./common/post"; import { sendingTx } from "./common/sending"; interface ClearAdminTxParams { - address: HumanAddr; - contractAddress: ContractAddr; + address: BechAddr20; + contractAddress: BechAddr32; fee: StdFee; memo?: string; client: SigningCosmWasmClient; diff --git a/src/lib/app-fns/tx/execute.tsx b/src/lib/app-fns/tx/execute.tsx index e2ff15067..d81dc07a4 100644 --- a/src/lib/app-fns/tx/execute.tsx +++ b/src/lib/app-fns/tx/execute.tsx @@ -10,15 +10,15 @@ import { EstimatedFeeRender } from "lib/components/EstimatedFeeRender"; import { ExplorerLink } from "lib/components/ExplorerLink"; import { CustomIcon } from "lib/components/icon"; import type { Activity } from "lib/stores/contract"; -import type { ContractAddr, HumanAddr, TxResultRendering } from "lib/types"; +import type { BechAddr20, BechAddr32, TxResultRendering } from "lib/types"; import { TxStreamPhase } from "lib/types"; import { encode, feeFromStr, getCurrentDate } from "lib/utils"; import { catchTxError, postTx, sendingTx } from "./common"; interface ExecuteTxParams { - address: HumanAddr; - contractAddress: ContractAddr; + address: BechAddr20; + contractAddress: BechAddr32; fee: StdFee; msg: object; funds: Coin[]; diff --git a/src/lib/app-fns/tx/migrate.tsx b/src/lib/app-fns/tx/migrate.tsx index f23f833ae..c7525919c 100644 --- a/src/lib/app-fns/tx/migrate.tsx +++ b/src/lib/app-fns/tx/migrate.tsx @@ -9,7 +9,7 @@ import type { Observable } from "rxjs"; import { EstimatedFeeRender } from "lib/components/EstimatedFeeRender"; import { ExplorerLink } from "lib/components/ExplorerLink"; import { CustomIcon } from "lib/components/icon"; -import type { ContractAddr, HumanAddr, TxResultRendering } from "lib/types"; +import type { BechAddr20, BechAddr32, TxResultRendering } from "lib/types"; import { TxStreamPhase } from "lib/types"; import { feeFromStr } from "lib/utils"; @@ -18,8 +18,8 @@ import { postTx } from "./common/post"; import { sendingTx } from "./common/sending"; interface MigrateTxParams { - sender: HumanAddr; - contractAddress: ContractAddr; + sender: BechAddr20; + contractAddress: BechAddr32; codeId: number; migrateMsg: object; fee: StdFee; diff --git a/src/lib/app-fns/tx/move/executeModule.tsx b/src/lib/app-fns/tx/move/executeModule.tsx index 9ca17f8e1..9b4c129bd 100644 --- a/src/lib/app-fns/tx/move/executeModule.tsx +++ b/src/lib/app-fns/tx/move/executeModule.tsx @@ -11,11 +11,11 @@ import { EstimatedFeeRender } from "lib/components/EstimatedFeeRender"; import { ExplorerLink } from "lib/components/ExplorerLink"; import { CustomIcon } from "lib/components/icon"; import { TxStreamPhase } from "lib/types"; -import type { HumanAddr, TxResultRendering } from "lib/types"; +import type { BechAddr20, TxResultRendering } from "lib/types"; import { feeFromStr } from "lib/utils"; interface ExecuteModuleTxParams { - address: HumanAddr; + address: BechAddr20; messages: EncodeObject[]; fee: StdFee; client: SigningCosmWasmClient; diff --git a/src/lib/app-fns/tx/publish.tsx b/src/lib/app-fns/tx/publish.tsx index 7c5281d64..aa43e6d7f 100644 --- a/src/lib/app-fns/tx/publish.tsx +++ b/src/lib/app-fns/tx/publish.tsx @@ -4,13 +4,21 @@ import type { StdFee } from "@cosmjs/stargate"; import { pipe } from "@rx-stream/pipe"; import type { Observable } from "rxjs"; -import type { PublishSucceedCallback } from "lib/app-provider/tx/publish"; -import type { HumanAddr, TxResultRendering } from "lib/types"; +import type { BechAddr20, Option, TxResultRendering } from "lib/types"; import { catchTxError, postTx, sendingTx } from "./common"; +export interface PublishTxInternalResult { + txHash: string; + txFee: Option; +} + +export type PublishSucceedCallback = ( + txResult: PublishTxInternalResult +) => void; + interface PublishModuleTxParams { - address: HumanAddr; + address: BechAddr20; client: SigningCosmWasmClient; onTxSucceed?: PublishSucceedCallback; onTxFailed?: () => void; diff --git a/src/lib/app-fns/tx/resend.tsx b/src/lib/app-fns/tx/resend.tsx index 21f5c7f40..c09eef18d 100644 --- a/src/lib/app-fns/tx/resend.tsx +++ b/src/lib/app-fns/tx/resend.tsx @@ -8,14 +8,14 @@ import type { Observable } from "rxjs"; import { EstimatedFeeRender } from "lib/components/EstimatedFeeRender"; import { ExplorerLink } from "lib/components/ExplorerLink"; import { CustomIcon } from "lib/components/icon"; -import type { HumanAddr, TxResultRendering } from "lib/types"; +import type { BechAddr20, TxResultRendering } from "lib/types"; import { TxStreamPhase } from "lib/types"; import { feeFromStr } from "lib/utils"; import { catchTxError, postTx, sendingTx } from "./common"; interface ResendTxParams { - address: HumanAddr; + address: BechAddr20; client: SigningCosmWasmClient; fee: StdFee; messages: EncodeObject[]; diff --git a/src/lib/app-fns/tx/script.tsx b/src/lib/app-fns/tx/script.tsx index 07eb5dd3a..552da8d1c 100644 --- a/src/lib/app-fns/tx/script.tsx +++ b/src/lib/app-fns/tx/script.tsx @@ -7,14 +7,14 @@ import type { Observable } from "rxjs"; import { EstimatedFeeRender } from "lib/components/EstimatedFeeRender"; import { ExplorerLink } from "lib/components/ExplorerLink"; import { CustomIcon } from "lib/components/icon"; -import type { HumanAddr, TxResultRendering } from "lib/types"; +import type { BechAddr20, TxResultRendering } from "lib/types"; import { TxStreamPhase } from "lib/types"; import { feeFromStr } from "lib/utils"; import { catchTxError, postTx, sendingTx } from "./common"; interface DeployScriptTxParams { - address: HumanAddr; + address: BechAddr20; client: SigningCosmWasmClient; onTxSucceed?: () => void; onTxFailed?: () => void; diff --git a/src/lib/app-fns/tx/upload.tsx b/src/lib/app-fns/tx/storeCode.tsx similarity index 86% rename from src/lib/app-fns/tx/upload.tsx rename to src/lib/app-fns/tx/storeCode.tsx index 4a471e8cd..c6fabb0a7 100644 --- a/src/lib/app-fns/tx/upload.tsx +++ b/src/lib/app-fns/tx/storeCode.tsx @@ -3,20 +3,36 @@ import type { DeliverTxResponse, logs, StdFee } from "@cosmjs/stargate"; import { pipe } from "@rx-stream/pipe"; import type { Observable } from "rxjs"; -import type { UploadSucceedCallback } from "lib/app-provider"; import { EstimatedFeeRender } from "lib/components/EstimatedFeeRender"; import { ExplorerLink } from "lib/components/ExplorerLink"; import { CustomIcon } from "lib/components/icon"; import { TxStreamPhase } from "lib/types"; -import type { HumanAddr, TxResultRendering, ComposedMsg } from "lib/types"; +import type { + BechAddr, + ComposedMsg, + Option, + TxResultRendering, +} from "lib/types"; import { feeFromStr, findAttr } from "lib/utils"; import { catchTxError } from "./common"; import { postTx } from "./common/post"; import { sendingTx } from "./common/sending"; -interface UploadTxParams { - address: HumanAddr; +export interface StoreCodeTxInternalResult { + codeDisplayName: string; + codeId: string; + codeHash: string; + txHash: string; + txFee: Option; +} + +export type StoreCodeSucceedCallback = ( + txResult: StoreCodeTxInternalResult +) => void; + +interface StoreCodeTxParams { + address: BechAddr; codeName: string; messages: ComposedMsg[]; wasmFileName: string; @@ -24,10 +40,10 @@ interface UploadTxParams { memo?: string; client: SigningCosmWasmClient; isMigrate: boolean; - onTxSucceed: UploadSucceedCallback; + onTxSucceed: StoreCodeSucceedCallback; } -export const uploadContractTx = ({ +export const storeCodeTx = ({ address, codeName, messages, @@ -37,7 +53,7 @@ export const uploadContractTx = ({ client, isMigrate, onTxSucceed, -}: UploadTxParams): Observable => { +}: StoreCodeTxParams): Observable => { return pipe( sendingTx(fee), postTx({ diff --git a/src/lib/app-fns/tx/submitProposal.tsx b/src/lib/app-fns/tx/submitProposal.tsx index 5eff7edf3..7bf32ae62 100644 --- a/src/lib/app-fns/tx/submitProposal.tsx +++ b/src/lib/app-fns/tx/submitProposal.tsx @@ -8,14 +8,14 @@ import type { Observable } from "rxjs"; import { EstimatedFeeRender } from "lib/components/EstimatedFeeRender"; import { ExplorerLink } from "lib/components/ExplorerLink"; import { CustomIcon } from "lib/components/icon"; -import type { HumanAddr, Nullable, TxResultRendering } from "lib/types"; +import type { BechAddr20, Nullable, TxResultRendering } from "lib/types"; import { TxStreamPhase } from "lib/types"; import { feeFromStr, findAttr } from "lib/utils"; import { catchTxError, postTx, sendingTx } from "./common"; interface SubmitWhitelistProposalTxParams { - address: HumanAddr; + address: BechAddr20; client: SigningCosmWasmClient; fee: StdFee; messages: EncodeObject[]; @@ -106,7 +106,7 @@ export const submitWhitelistProposalTx = ({ }; interface SubmitStoreCodeProposalTxParams { - address: HumanAddr; + address: BechAddr20; client: SigningCosmWasmClient; fee: StdFee; chainName: string; diff --git a/src/lib/app-fns/tx/updateAdmin.tsx b/src/lib/app-fns/tx/updateAdmin.tsx index cc85c0065..a68f6beef 100644 --- a/src/lib/app-fns/tx/updateAdmin.tsx +++ b/src/lib/app-fns/tx/updateAdmin.tsx @@ -10,9 +10,9 @@ import { EstimatedFeeRender } from "lib/components/EstimatedFeeRender"; import { ExplorerLink } from "lib/components/ExplorerLink"; import { CustomIcon } from "lib/components/icon"; import type { - Addr, - ContractAddr, - HumanAddr, + BechAddr, + BechAddr20, + BechAddr32, TxResultRendering, } from "lib/types"; import { TxStreamPhase } from "lib/types"; @@ -21,9 +21,9 @@ import { feeFromStr } from "lib/utils"; import { catchTxError, postTx, sendingTx } from "./common"; interface UpdateAdminTxParams { - address: HumanAddr; - contractAddress: ContractAddr; - newAdmin: Addr; + address: BechAddr20; + contractAddress: BechAddr32; + newAdmin: BechAddr; fee: StdFee; client: SigningCosmWasmClient; onTxSucceed?: () => void; diff --git a/src/lib/app-provider/hooks/useCurrentChain.ts b/src/lib/app-provider/hooks/useCurrentChain.ts index 68c233780..09e02bf60 100644 --- a/src/lib/app-provider/hooks/useCurrentChain.ts +++ b/src/lib/app-provider/hooks/useCurrentChain.ts @@ -1,11 +1,21 @@ +import type { ChainContext as CosmosChainContext } from "@cosmos-kit/core"; import { useChain } from "@cosmos-kit/react"; import { useCelatoneApp } from "../contexts"; +import type { BechAddr20, Option } from "lib/types"; -export const useCurrentChain = () => { +interface ChainContext extends Omit { + address: Option; +} + +export const useCurrentChain = (): ChainContext => { const { chainConfig: { registryChainName }, } = useCelatoneApp(); - return useChain(registryChainName); + const { address, ...res } = useChain(registryChainName); + return { + address: address as Option, + ...res, + }; }; diff --git a/src/lib/app-provider/hooks/useDummyWallet.ts b/src/lib/app-provider/hooks/useDummyWallet.ts index 8d6c824f9..0b0996664 100644 --- a/src/lib/app-provider/hooks/useDummyWallet.ts +++ b/src/lib/app-provider/hooks/useDummyWallet.ts @@ -2,14 +2,14 @@ import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"; import { useEffect, useState } from "react"; import { DUMMY_MNEMONIC } from "env"; -import type { HumanAddr } from "lib/types"; +import type { BechAddr20 } from "lib/types"; import { useCurrentChain } from "./useCurrentChain"; export const useDummyWallet = () => { const { chain } = useCurrentChain(); const [dummyWallet, setDummyWallet] = useState(); - const [dummyAddress, setDummyAddress] = useState(); + const [dummyAddress, setDummyAddress] = useState(); useEffect(() => { (async () => { if (DUMMY_MNEMONIC) { @@ -23,7 +23,7 @@ export const useDummyWallet = () => { setDummyWallet(wallet); const { address } = (await wallet.getAccounts())[0]; - setDummyAddress(address as HumanAddr); + setDummyAddress(address as BechAddr20); } })(); }, [chain.bech32_prefix]); diff --git a/src/lib/app-provider/hooks/useExampleAddresses.ts b/src/lib/app-provider/hooks/useExampleAddresses.ts index 6080346d0..a83b3a25b 100644 --- a/src/lib/app-provider/hooks/useExampleAddresses.ts +++ b/src/lib/app-provider/hooks/useExampleAddresses.ts @@ -1,7 +1,7 @@ import { toBech32 } from "@cosmjs/encoding"; import { useMemo } from "react"; -import type { ContractAddr, HumanAddr } from "lib/types"; +import type { BechAddr20, BechAddr32 } from "lib/types"; import { addrToValoper } from "lib/utils"; import { useCurrentChain } from "./useCurrentChain"; @@ -16,13 +16,13 @@ export const useExampleAddresses = () => { const user = toBech32( prefix, new Uint8Array(bytes.slice(0, 20)) - ) as HumanAddr; + ) as BechAddr20; // reverse the bytes so the initial characters are different from the user address const contract = toBech32( prefix, new Uint8Array(bytes.reverse()) - ) as ContractAddr; + ) as BechAddr32; const validator = addrToValoper(user); diff --git a/src/lib/app-provider/queries/simulateFee.ts b/src/lib/app-provider/queries/simulateFee.ts index 36fbae427..3ee821b19 100644 --- a/src/lib/app-provider/queries/simulateFee.ts +++ b/src/lib/app-provider/queries/simulateFee.ts @@ -11,14 +11,7 @@ import { useGetSigningClient, useRPCEndpoint, } from "../hooks"; -import type { - AccessType, - Addr, - ComposedMsg, - Gas, - HumanAddr, - Option, -} from "lib/types"; +import type { AccessType, BechAddr, ComposedMsg, Gas, Option } from "lib/types"; import { composeStoreCodeMsg, composeStoreCodeProposalMsg } from "lib/utils"; interface SimulateQueryParams { @@ -87,7 +80,7 @@ interface SimulateQueryParamsForStoreCode { enabled: boolean; wasmFile: Option; permission: AccessType; - addresses?: Addr[]; + addresses?: BechAddr[]; onSuccess?: (gas: Gas | undefined) => void; onError?: (err: Error) => void; } @@ -110,7 +103,7 @@ export const useSimulateFeeForStoreCode = ({ const submitStoreCodeMsg = async () => { return composeStoreCodeMsg({ - sender: address as HumanAddr, + sender: address, wasmByteCode: await gzip(new Uint8Array(await wasmFile.arrayBuffer())), permission, addresses, @@ -141,7 +134,7 @@ interface SimulateQueryParamsForProposalStoreCode { enabled: boolean; title: string; description: string; - runAs: Addr; + runAs: BechAddr; initialDeposit: Coin; unpinCode: boolean; builder: string; @@ -149,7 +142,7 @@ interface SimulateQueryParamsForProposalStoreCode { codeHash: string; wasmFile: Option; permission: AccessType; - addresses: Addr[]; + addresses: BechAddr[]; precision: Option; onSuccess?: (gas: Gas | undefined) => void; onError?: (err: Error) => void; @@ -182,10 +175,10 @@ export const useSimulateFeeForProposalStoreCode = ({ const submitStoreCodeProposalMsg = async () => { return composeStoreCodeProposalMsg({ - proposer: address as HumanAddr, + proposer: address, title, description, - runAs: runAs as Addr, + runAs, wasmByteCode: await gzip(new Uint8Array(await wasmFile.arrayBuffer())), permission, addresses, diff --git a/src/lib/app-provider/tx/clearAdmin.ts b/src/lib/app-provider/tx/clearAdmin.ts index 78119ec3d..f8555da6b 100644 --- a/src/lib/app-provider/tx/clearAdmin.ts +++ b/src/lib/app-provider/tx/clearAdmin.ts @@ -10,13 +10,13 @@ import { } from "../hooks"; import { trackTxSucceed } from "lib/amplitude"; import { clearAdminTx } from "lib/app-fns/tx/clearAdmin"; -import type { ContractAddr, HumanAddr } from "lib/types"; +import type { BechAddr32 } from "lib/types"; export interface ClearAdminStreamParams { onTxSucceed?: () => void; } -export const useClearAdminTx = (contractAddress: ContractAddr) => { +export const useClearAdminTx = (contractAddress: BechAddr32) => { const { address } = useCurrentChain(); const getSigningClient = useGetSigningClient(); const queryClient = useQueryClient(); @@ -37,7 +37,7 @@ export const useClearAdminTx = (contractAddress: ContractAddr) => { const clearAdminFee = fabricateFee(wasm.clearAdminGas); return clearAdminTx({ - address: address as HumanAddr, + address, contractAddress, fee: clearAdminFee, client, diff --git a/src/lib/app-provider/tx/execute.ts b/src/lib/app-provider/tx/execute.ts index 1216852ac..40da87d37 100644 --- a/src/lib/app-provider/tx/execute.ts +++ b/src/lib/app-provider/tx/execute.ts @@ -5,13 +5,13 @@ import { useCurrentChain, useGetSigningClient } from "../hooks"; import { trackTxSucceed } from "lib/amplitude"; import { executeContractTx } from "lib/app-fns/tx/execute"; import type { Activity } from "lib/stores/contract"; -import type { ContractAddr, HumanAddr } from "lib/types"; +import type { BechAddr32 } from "lib/types"; export interface ExecuteStreamParams { onTxSucceed?: (activity: Activity) => void; onTxFailed?: () => void; estimatedFee: StdFee | undefined; - contractAddress: ContractAddr; + contractAddress: BechAddr32; msg: object; funds: Coin[]; } @@ -35,7 +35,7 @@ export const useExecuteContractTx = () => { if (!estimatedFee) return null; return executeContractTx({ - address: address as HumanAddr, + address, contractAddress, fee: estimatedFee, msg, diff --git a/src/lib/app-provider/tx/index.ts b/src/lib/app-provider/tx/index.ts index bddeeba69..802167a9d 100644 --- a/src/lib/app-provider/tx/index.ts +++ b/src/lib/app-provider/tx/index.ts @@ -1,5 +1,5 @@ export * from "./move"; -export * from "./upload"; +export * from "./storeCode"; export * from "./execute"; export * from "./instantiate"; export * from "./resend"; diff --git a/src/lib/app-provider/tx/migrate.ts b/src/lib/app-provider/tx/migrate.ts index 195dfc010..d64e53a6f 100644 --- a/src/lib/app-provider/tx/migrate.ts +++ b/src/lib/app-provider/tx/migrate.ts @@ -4,10 +4,10 @@ import { useCallback } from "react"; import { useCurrentChain, useGetSigningClient } from "../hooks"; import { trackTxSucceed } from "lib/amplitude"; import { migrateContractTx } from "lib/app-fns/tx/migrate"; -import type { ContractAddr, HumanAddr, Option } from "lib/types"; +import type { BechAddr32, Option } from "lib/types"; export interface MigrateStreamParams { - contractAddress: ContractAddr; + contractAddress: BechAddr32; codeId: number; migrateMsg: object; estimatedFee: Option; @@ -34,7 +34,7 @@ export const useMigrateTx = () => { if (!estimatedFee) return null; return migrateContractTx({ - sender: address as HumanAddr, + sender: address, contractAddress, codeId, migrateMsg, diff --git a/src/lib/app-provider/tx/move/executeModule.ts b/src/lib/app-provider/tx/move/executeModule.ts index 67ad79f03..e6041c035 100644 --- a/src/lib/app-provider/tx/move/executeModule.ts +++ b/src/lib/app-provider/tx/move/executeModule.ts @@ -5,7 +5,7 @@ import { useCallback } from "react"; import { trackTxSucceed } from "lib/amplitude"; import { executeModuleTx } from "lib/app-fns/tx/move/executeModule"; import { useCurrentChain, useGetSigningClient } from "lib/app-provider/hooks"; -import type { HexAddr, HumanAddr } from "lib/types"; +import type { HexAddr } from "lib/types"; import { toEncodeObject } from "lib/utils"; export interface ExecuteModuleStreamParams { @@ -51,7 +51,7 @@ export const useExecuteModuleTx = () => { if (!estimatedFee) return null; return executeModuleTx({ - address: address as HumanAddr, + address, messages, fee: estimatedFee, client, diff --git a/src/lib/app-provider/tx/publish.tsx b/src/lib/app-provider/tx/publish.tsx index 2c751b37e..2aa899321 100644 --- a/src/lib/app-provider/tx/publish.tsx +++ b/src/lib/app-provider/tx/publish.tsx @@ -4,17 +4,8 @@ import { useCallback } from "react"; import { useCurrentChain, useGetSigningClient } from "../hooks"; import { trackTxSucceed } from "lib/amplitude"; +import type { PublishSucceedCallback } from "lib/app-fns/tx/publish"; import { publishModuleTx } from "lib/app-fns/tx/publish"; -import type { HumanAddr, Option } from "lib/types"; - -export interface PublishTxInternalResult { - txHash: string; - txFee: Option; -} - -export type PublishSucceedCallback = ( - txResult: PublishTxInternalResult -) => void; export interface PublishModuleStreamParams { onTxSucceed?: PublishSucceedCallback; @@ -39,7 +30,7 @@ export const usePublishModuleTx = () => { throw new Error("Please check your wallet connection."); if (!estimatedFee) return null; return publishModuleTx({ - address: address as HumanAddr, + address, client, onTxSucceed: (txResult) => { trackTxSucceed(); diff --git a/src/lib/app-provider/tx/resend.ts b/src/lib/app-provider/tx/resend.ts index 623491aac..912d72a60 100644 --- a/src/lib/app-provider/tx/resend.ts +++ b/src/lib/app-provider/tx/resend.ts @@ -5,7 +5,6 @@ import { useCallback } from "react"; import { useCurrentChain, useGetSigningClient } from "../hooks"; import { trackTxSucceed } from "lib/amplitude"; import { resendTx } from "lib/app-fns/tx/resend"; -import type { HumanAddr } from "lib/types"; export interface ResendStreamParams { onTxSucceed?: (txHash: string) => void; @@ -30,7 +29,7 @@ export const useResendTx = () => { throw new Error("Please check your wallet connection."); if (!estimatedFee) return null; return resendTx({ - address: address as HumanAddr, + address, client, fee: estimatedFee, messages, diff --git a/src/lib/app-provider/tx/script.tsx b/src/lib/app-provider/tx/script.tsx index e7a24c41e..352de597f 100644 --- a/src/lib/app-provider/tx/script.tsx +++ b/src/lib/app-provider/tx/script.tsx @@ -5,7 +5,6 @@ import { useCallback } from "react"; import { useCurrentChain, useGetSigningClient } from "../hooks"; import { trackTxSucceed } from "lib/amplitude"; import { deployScriptTx } from "lib/app-fns/tx/script"; -import type { HumanAddr } from "lib/types"; export interface DeployScriptStreamParams { onTxSucceed?: () => void; @@ -30,7 +29,7 @@ export const useDeployScriptTx = () => { throw new Error("Please check your wallet connection."); if (!estimatedFee) return null; return deployScriptTx({ - address: address as HumanAddr, + address, client, onTxSucceed: () => { trackTxSucceed(); diff --git a/src/lib/app-provider/tx/upload.ts b/src/lib/app-provider/tx/storeCode.ts similarity index 67% rename from src/lib/app-provider/tx/upload.ts rename to src/lib/app-provider/tx/storeCode.ts index a97706869..f7298d1f1 100644 --- a/src/lib/app-provider/tx/upload.ts +++ b/src/lib/app-provider/tx/storeCode.ts @@ -4,31 +4,22 @@ import { useCallback } from "react"; import { useCurrentChain, useGetSigningClient } from "../hooks"; import { trackTxSucceed } from "lib/amplitude"; -import { uploadContractTx } from "lib/app-fns/tx/upload"; -import type { AccessType, Addr, HumanAddr, Option } from "lib/types"; +import type { StoreCodeSucceedCallback } from "lib/app-fns/tx/storeCode"; +import { storeCodeTx } from "lib/app-fns/tx/storeCode"; +import type { AccessType, BechAddr, Option } from "lib/types"; import { composeStoreCodeMsg } from "lib/utils"; -export interface UploadTxInternalResult { - codeDisplayName: string; - codeId: string; - codeHash: string; - txHash: string; - txFee: Option; -} - -export type UploadSucceedCallback = (txResult: UploadTxInternalResult) => void; - -export interface UploadStreamParams { +export interface StoreCodeStreamParams { wasmFileName: Option; wasmCode: Option>; - addresses?: Addr[]; + addresses?: BechAddr[]; permission: AccessType; codeName: string; estimatedFee: Option; - onTxSucceed: UploadSucceedCallback; + onTxSucceed: StoreCodeSucceedCallback; } -export const useUploadContractTx = (isMigrate: boolean) => { +export const useStoreCodeTx = (isMigrate: boolean) => { const { address } = useCurrentChain(); const getSigningClient = useGetSigningClient(); @@ -41,21 +32,21 @@ export const useUploadContractTx = (isMigrate: boolean) => { codeName, estimatedFee, onTxSucceed, - }: UploadStreamParams) => { + }: StoreCodeStreamParams) => { const client = await getSigningClient(); if (!address || !client) throw new Error("Please check your wallet connection."); if (!wasmFileName || !wasmCode || !estimatedFee) return null; const message = composeStoreCodeMsg({ - sender: address as Addr, + sender: address, wasmByteCode: await gzip(new Uint8Array(await wasmCode)), permission, addresses, }); - return uploadContractTx({ - address: address as HumanAddr, + return storeCodeTx({ + address, messages: [message], codeName, wasmFileName, diff --git a/src/lib/app-provider/tx/submitProposal.ts b/src/lib/app-provider/tx/submitProposal.ts index 7fa78a883..62580b3d0 100644 --- a/src/lib/app-provider/tx/submitProposal.ts +++ b/src/lib/app-provider/tx/submitProposal.ts @@ -8,7 +8,7 @@ import { submitStoreCodeProposalTx, submitWhitelistProposalTx, } from "lib/app-fns/tx/submitProposal"; -import type { HumanAddr, Nullable } from "lib/types"; +import type { Nullable } from "lib/types"; export interface SubmitWhitelistProposalStreamParams { estimatedFee?: StdFee; @@ -37,7 +37,7 @@ export const useSubmitWhitelistProposalTx = () => { throw new Error("Please check your wallet connection."); if (!estimatedFee) return null; return submitWhitelistProposalTx({ - address: address as HumanAddr, + address, client, fee: estimatedFee, messages, @@ -80,7 +80,7 @@ export const useSubmitStoreCodeProposalTx = () => { throw new Error("Please check your wallet connection."); if (!estimatedFee) return null; return submitStoreCodeProposalTx({ - address: address as HumanAddr, + address, chainName: chain.chain_name, client, fee: estimatedFee, diff --git a/src/lib/app-provider/tx/updateAdmin.ts b/src/lib/app-provider/tx/updateAdmin.ts index 7bbfe6203..8737b4a83 100644 --- a/src/lib/app-provider/tx/updateAdmin.ts +++ b/src/lib/app-provider/tx/updateAdmin.ts @@ -4,11 +4,11 @@ import { useCallback } from "react"; import { useCurrentChain, useGetSigningClient } from "../hooks"; import { trackTxSucceed } from "lib/amplitude"; import { updateAdminTx } from "lib/app-fns/tx/updateAdmin"; -import type { Addr, ContractAddr, HumanAddr, Option } from "lib/types"; +import type { BechAddr, BechAddr32, Option } from "lib/types"; export interface UpdateAdminStreamParams { - contractAddress: ContractAddr; - newAdmin: Addr; + contractAddress: BechAddr32; + newAdmin: BechAddr; estimatedFee: Option; onTxSucceed?: () => void; onTxFailed?: () => void; @@ -32,7 +32,7 @@ export const useUpdateAdminTx = () => { if (!estimatedFee) return null; return updateAdminTx({ - address: address as HumanAddr, + address, contractAddress, newAdmin, fee: estimatedFee, diff --git a/src/lib/components/ContractSelectSection.tsx b/src/lib/components/ContractSelectSection.tsx index bcde0c295..288c7971f 100644 --- a/src/lib/components/ContractSelectSection.tsx +++ b/src/lib/components/ContractSelectSection.tsx @@ -8,7 +8,7 @@ import { useContractStore } from "lib/providers/store"; import type { ContractDetail } from "lib/services/contractService"; import { useContractDetailByContractAddress } from "lib/services/contractService"; import type { ContractLocalInfo } from "lib/stores/contract"; -import type { Addr, ContractAddr, Option } from "lib/types"; +import type { BechAddr, BechAddr32, Option } from "lib/types"; import { ExplorerLink } from "./ExplorerLink"; import { CustomIcon } from "./icon"; @@ -27,16 +27,16 @@ interface DisplayNameProps { } interface ContractDetailsButtonProps { - contractAddress: ContractAddr; + contractAddress: BechAddr32; contractLocalInfo: Option; - instantiator: Addr; + instantiator: BechAddr; label: string; } interface ContractSelectSectionProps { mode: "all-lists" | "only-admin"; - contractAddress: ContractAddr; - onContractSelect: (contract: ContractAddr) => void; + contractAddress: BechAddr32; + onContractSelect: (contract: BechAddr32) => void; successCallback?: (data: ContractDetail) => void; } @@ -244,7 +244,7 @@ export const ContractSelectSection = observer( )} diff --git a/src/lib/components/PermissionChip.tsx b/src/lib/components/PermissionChip.tsx index c41748d76..ace62643c 100644 --- a/src/lib/components/PermissionChip.tsx +++ b/src/lib/components/PermissionChip.tsx @@ -1,11 +1,7 @@ import { Flex, Tag } from "@chakra-ui/react"; import { useCurrentChain } from "lib/app-provider"; -import type { - HumanAddr, - PermissionAddresses, - AccessConfigPermission, -} from "lib/types"; +import type { PermissionAddresses, AccessConfigPermission } from "lib/types"; import { getPermissionHelper, resolvePermission } from "lib/utils"; import { Tooltip } from "./Tooltip"; @@ -24,13 +20,13 @@ export const PermissionChip = ({ const { address } = useCurrentChain(); const isAllowed = resolvePermission( - address as HumanAddr, + address, instantiatePermission, permissionAddresses ); const { message } = getPermissionHelper( - address as HumanAddr, + address, instantiatePermission, permissionAddresses ); diff --git a/src/lib/components/abi/args-form/field/ArgFieldWidget.tsx b/src/lib/components/abi/args-form/field/ArgFieldWidget.tsx index c4dd7bff7..c86a4cd60 100644 --- a/src/lib/components/abi/args-form/field/ArgFieldWidget.tsx +++ b/src/lib/components/abi/args-form/field/ArgFieldWidget.tsx @@ -3,7 +3,7 @@ import { Select } from "chakra-react-select"; import type { ControllerRenderProps } from "react-hook-form"; import { useCurrentChain, useExampleAddresses } from "lib/app-provider"; -import type { HumanAddr, Nullable } from "lib/types"; +import type { BechAddr20, Nullable } from "lib/types"; import { UINT_TYPES, @@ -27,14 +27,14 @@ const getInputPlaceholder = ( const getVectorPlaceholder = ( type: string, isNull: boolean, - sampleAddresses: HumanAddr + sampleAddress: BechAddr20 ) => { if (isNull) return " "; const [, elementType] = type.split(/<(.*)>/); if (UINT_TYPES.includes(elementType)) return "[1, 2, 3]"; if (elementType === "address" || elementType.startsWith(OBJECT_TYPE)) - return `[0x1, ${sampleAddresses}]`; + return `[0x1, ${sampleAddress}]`; if (elementType === STRING_TYPE) return "[some first string, some second string]"; if (elementType === "bool") return "[true, false]"; diff --git a/src/lib/components/button/AdminButton.tsx b/src/lib/components/button/AdminButton.tsx index 1f60e2ce9..850f8ca0d 100644 --- a/src/lib/components/button/AdminButton.tsx +++ b/src/lib/components/button/AdminButton.tsx @@ -4,11 +4,11 @@ import { CustomIcon } from "../icon"; import { ClearAdminModal } from "../modal/contract/ClearAdmin"; import { Tooltip } from "../Tooltip"; import { useCurrentChain, useInternalNavigate } from "lib/app-provider"; -import type { Addr, ContractAddr, Nullable } from "lib/types"; +import type { BechAddr, BechAddr32, Nullable } from "lib/types"; interface AdminButtonProps { - contractAddress: ContractAddr; - admin: Nullable; + contractAddress: BechAddr32; + admin: Nullable; } export const AdminButton = ({ contractAddress, admin }: AdminButtonProps) => { diff --git a/src/lib/components/button/InstantiateButton.tsx b/src/lib/components/button/InstantiateButton.tsx index 87a080524..bcba9ccbf 100644 --- a/src/lib/components/button/InstantiateButton.tsx +++ b/src/lib/components/button/InstantiateButton.tsx @@ -4,7 +4,7 @@ import { Button } from "@chakra-ui/react"; import { CustomIcon } from "../icon"; import { Tooltip } from "../Tooltip"; import { useCurrentChain, useInternalNavigate } from "lib/app-provider"; -import type { HumanAddr, PermissionAddresses } from "lib/types"; +import type { PermissionAddresses } from "lib/types"; import { AccessConfigPermission } from "lib/types"; import { resolvePermission } from "lib/utils"; @@ -65,7 +65,7 @@ export const InstantiateButton = ({ navigate({ pathname: "/instantiate", query: { "code-id": codeId } }); const isAllowed = resolvePermission( - address as HumanAddr, + address, instantiatePermission, permissionAddresses ); diff --git a/src/lib/components/modal/MoveCodeSnippet.tsx b/src/lib/components/modal/MoveCodeSnippet.tsx index ed96dc362..64a59fca0 100644 --- a/src/lib/components/modal/MoveCodeSnippet.tsx +++ b/src/lib/components/modal/MoveCodeSnippet.tsx @@ -29,7 +29,7 @@ import { useRPCEndpoint, } from "lib/app-provider"; import { CustomTab } from "lib/components/CustomTab"; -import type { AbiFormData, ExposedFunction, MoveAccountAddr } from "lib/types"; +import type { AbiFormData, ExposedFunction, HexAddr } from "lib/types"; import { getArgType, serializeAbiData } from "lib/utils"; import "ace-builds/src-noconflict/ace"; @@ -41,7 +41,7 @@ import "ace-builds/src-noconflict/theme-one_dark"; import "ace-builds/src-noconflict/theme-pastel_on_dark"; interface MoveCodeSnippetProps { - moduleAddress: MoveAccountAddr; + moduleAddress: HexAddr; moduleName: string; fn: ExposedFunction; abiData: AbiFormData; diff --git a/src/lib/components/modal/UnsupportedTokensModal.tsx b/src/lib/components/modal/UnsupportedTokensModal.tsx index d03d1ce65..5456c4c0f 100644 --- a/src/lib/components/modal/UnsupportedTokensModal.tsx +++ b/src/lib/components/modal/UnsupportedTokensModal.tsx @@ -21,7 +21,7 @@ import { trackUseUnsupportedToken } from "lib/amplitude"; import { useGetAddressType, useMobile } from "lib/app-provider"; import type { AddressReturnType } from "lib/app-provider"; import { Copier } from "lib/components/copy"; -import type { Addr, TokenWithValue } from "lib/types"; +import type { BechAddr, TokenWithValue } from "lib/types"; import { getTokenType, getTokenLabel, @@ -30,7 +30,7 @@ import { interface UnsupportedTokensModalProps { unsupportedAssets: TokenWithValue[]; - address?: Addr; + address?: BechAddr; addressType?: AddressReturnType; buttonProps?: ButtonProps; amptrackSection?: string; diff --git a/src/lib/components/modal/WasmCodeSnippet.tsx b/src/lib/components/modal/WasmCodeSnippet.tsx index 7e8c3cc9c..2fbb4865e 100644 --- a/src/lib/components/modal/WasmCodeSnippet.tsx +++ b/src/lib/components/modal/WasmCodeSnippet.tsx @@ -29,7 +29,7 @@ import { useRPCEndpoint, } from "lib/app-provider"; import { CustomTab } from "lib/components/CustomTab"; -import type { ContractAddr } from "lib/types"; +import type { BechAddr32 } from "lib/types"; import { coinsToStr, jsonPrettify } from "lib/utils"; import "ace-builds/src-noconflict/ace"; @@ -41,7 +41,7 @@ import "ace-builds/src-noconflict/theme-one_dark"; import "ace-builds/src-noconflict/theme-pastel_on_dark"; interface WasmCodeSnippetProps { - contractAddress: ContractAddr; + contractAddress: BechAddr32; message: string; type: "query" | "execute"; ml?: ButtonProps["ml"]; diff --git a/src/lib/components/modal/account/SaveNewAccount.tsx b/src/lib/components/modal/account/SaveNewAccount.tsx index 99ae16f6c..bbba983a0 100644 --- a/src/lib/components/modal/account/SaveNewAccount.tsx +++ b/src/lib/components/modal/account/SaveNewAccount.tsx @@ -18,12 +18,13 @@ import { useGetMaxLengthError, useHandleAccountSave } from "lib/hooks"; import { useFormatAddresses } from "lib/hooks/useFormatAddresses"; import { useAccountStore } from "lib/providers/store"; import { useAccountType } from "lib/services/accountService"; -import { AccountType, type Addr } from "lib/types"; +import type { BechAddr } from "lib/types"; +import { AccountType } from "lib/types"; import { ToContractButton } from "./ToContractButton"; export interface SaveAccountDetail { - address: Addr; + address: BechAddr; name: string; description: string; } @@ -35,7 +36,7 @@ const statusSuccess: FormStatus = { interface SaveNewAccountModalProps { buttonProps: ButtonProps; - accountAddress?: Addr; + accountAddress?: BechAddr; publicName?: string; publicDescription?: string; } @@ -56,7 +57,7 @@ export function SaveNewAccountModal({ const getMaxLengthError = useGetMaxLengthError(); const { isAccountSaved } = useAccountStore(); - const defaultAddress = accountAddress ?? ("" as Addr); + const defaultAddress = accountAddress ?? ("" as BechAddr); const defaultValues: SaveAccountDetail = useMemo(() => { return { address: defaultAddress, diff --git a/src/lib/components/modal/account/SavedAccountModalHeader.tsx b/src/lib/components/modal/account/SavedAccountModalHeader.tsx index 721b473a6..380cee0c0 100644 --- a/src/lib/components/modal/account/SavedAccountModalHeader.tsx +++ b/src/lib/components/modal/account/SavedAccountModalHeader.tsx @@ -2,11 +2,11 @@ import { Flex, Text } from "@chakra-ui/react"; import { useMoveConfig } from "lib/app-provider"; import { ExplorerLink } from "lib/components/ExplorerLink"; -import type { Addr, HumanAddr } from "lib/types"; +import type { BechAddr } from "lib/types"; import { bech32AddressToHex, unpadHexAddress } from "lib/utils"; interface SavedAccountModalHeaderProps { - address: Addr; + address: BechAddr; } export const SavedAccountModalHeader = ({ @@ -27,7 +27,7 @@ export const SavedAccountModalHeader = ({ Hex Address diff --git a/src/lib/components/modal/code/CodeDetailsTemplate.tsx b/src/lib/components/modal/code/CodeDetailsTemplate.tsx index 82b41be2a..4d75ef304 100644 --- a/src/lib/components/modal/code/CodeDetailsTemplate.tsx +++ b/src/lib/components/modal/code/CodeDetailsTemplate.tsx @@ -10,7 +10,7 @@ import type { IconKeys } from "lib/components/icon"; import { CustomIcon } from "lib/components/icon"; import { PermissionChip } from "lib/components/PermissionChip"; import { useCodeStore } from "lib/providers/store"; -import type { Addr, CodeInfo } from "lib/types"; +import type { CodeInfo } from "lib/types"; interface CodeDetailsTemplateModalProps { title: string; @@ -48,7 +48,7 @@ export const CodeDetailsTemplateModal = ({ track(AmpEvent.CODE_EDIT); } - updateCodeInfo(codeInfo.id, codeInfo.uploader as Addr, name); + updateCodeInfo(codeInfo.id, codeInfo.uploader, name); // TODO: abstract toast to template later toast({ diff --git a/src/lib/components/modal/code/SaveNewCode.tsx b/src/lib/components/modal/code/SaveNewCode.tsx index 38719f842..14b4de0f7 100644 --- a/src/lib/components/modal/code/SaveNewCode.tsx +++ b/src/lib/components/modal/code/SaveNewCode.tsx @@ -11,7 +11,7 @@ import { CustomIcon } from "lib/components/icon"; import { useGetMaxLengthError } from "lib/hooks"; import { useCodeStore } from "lib/providers/store"; import { useLCDCodeInfo } from "lib/services/codeService"; -import type { Addr, HumanAddr } from "lib/types"; +import type { BechAddr } from "lib/types"; import { getNameAndDescriptionDefault, getPermissionHelper } from "lib/utils"; interface SaveNewCodeModalProps { @@ -61,7 +61,7 @@ export function SaveNewCodeModal({ buttonProps }: SaveNewCodeModalProps) { cacheTime: 0, onSuccess(data) { const { message, messageColor } = getPermissionHelper( - address as HumanAddr, + address, data.code_info.instantiate_permission.permission, data.code_info.instantiate_permission.address ? [data.code_info.instantiate_permission.address] @@ -96,7 +96,7 @@ export function SaveNewCodeModal({ buttonProps }: SaveNewCodeModalProps) { const id = Number(codeId); saveNewCode(id); - updateCodeInfo(id, uploader as Addr, name); + updateCodeInfo(id, uploader as BechAddr, name); // TODO: abstract toast to template later toast({ diff --git a/src/lib/components/modal/contract/ClearAdmin.tsx b/src/lib/components/modal/contract/ClearAdmin.tsx index 68ac5afab..c2eb4307e 100644 --- a/src/lib/components/modal/contract/ClearAdmin.tsx +++ b/src/lib/components/modal/contract/ClearAdmin.tsx @@ -5,10 +5,10 @@ import { ActionModal } from "../ActionModal"; import { AmpEvent, track } from "lib/amplitude"; import { useClearAdminTx } from "lib/app-provider"; import { useTxBroadcast } from "lib/providers/tx-broadcast"; -import type { ContractAddr } from "lib/types"; +import type { BechAddr32 } from "lib/types"; interface ClearAdminModalProps { - contractAddress: ContractAddr; + contractAddress: BechAddr32; triggerElement: JSX.Element; } diff --git a/src/lib/components/modal/contract/SaveNewContract.tsx b/src/lib/components/modal/contract/SaveNewContract.tsx index 82fef803d..a07c94a41 100644 --- a/src/lib/components/modal/contract/SaveNewContract.tsx +++ b/src/lib/components/modal/contract/SaveNewContract.tsx @@ -14,7 +14,7 @@ import { INSTANTIATED_LIST_NAME } from "lib/data"; import { useHandleContractSave } from "lib/hooks"; import { useContractStore } from "lib/providers/store"; import { useContractDetailByContractAddress } from "lib/services/contractService"; -import type { Addr, ContractAddr, LVPair } from "lib/types"; +import type { BechAddr, BechAddr32, LVPair } from "lib/types"; import { formatSlugName, getNameAndDescriptionDefault, @@ -89,7 +89,7 @@ export function SaveNewContractModal({ }; const { refetch } = useContractDetailByContractAddress( - contractAddressState as ContractAddr, + contractAddressState as BechAddr32, (data) => { const contractLocalInfo = getContractLocalInfo(contractAddressState); reset({ @@ -149,8 +149,8 @@ export function SaveNewContractModal({ title: `Saved ${ offchainState.name.trim().length ? offchainState.name : labelState }`, - contractAddress: contractAddressState as ContractAddr, - instantiator: instantiatorState as Addr, + contractAddress: contractAddressState as BechAddr32, + instantiator: instantiatorState as BechAddr, label: labelState, name: offchainState.name, description: offchainState.description, diff --git a/src/lib/components/module/ModuleCard.tsx b/src/lib/components/module/ModuleCard.tsx index d296fb81d..55d86419a 100644 --- a/src/lib/components/module/ModuleCard.tsx +++ b/src/lib/components/module/ModuleCard.tsx @@ -7,12 +7,12 @@ import { CustomIcon } from "../icon"; import { AmpEvent, track } from "lib/amplitude"; import type { IndexedModule } from "lib/services/move/moduleService"; import { useVerifyModule } from "lib/services/move/moduleService"; -import type { MoveAccountAddr, Option } from "lib/types"; +import type { BechAddr, Option } from "lib/types"; import { CountBadge } from "./CountBadge"; interface ModuleCardProps { - selectedAddress: MoveAccountAddr; + selectedAddress: BechAddr; module: IndexedModule; selectedModule: Option; setSelectedModule?: (module: IndexedModule) => void; diff --git a/src/lib/components/select-contract/ContractListDetail.tsx b/src/lib/components/select-contract/ContractListDetail.tsx index 120e0aeac..49cba2502 100644 --- a/src/lib/components/select-contract/ContractListDetail.tsx +++ b/src/lib/components/select-contract/ContractListDetail.tsx @@ -10,13 +10,13 @@ import { TagSelection } from "lib/components/TagSelection"; import { INSTANTIATED_LIST_NAME } from "lib/data"; import { useAdminByContractAddresses } from "lib/services/contractService"; import type { ContractListInfo } from "lib/stores/contract"; -import type { ContractAddr, ContractInfo } from "lib/types"; +import type { BechAddr32, ContractInfo } from "lib/types"; import { formatSlugName } from "lib/utils"; interface ContractListContentProps { contractListInfo: ContractListInfo; filteredContracts: ContractInfo[]; - onContractSelect: (addr: ContractAddr) => void; + onContractSelect: (addr: BechAddr32) => void; isLoading: boolean; isReadOnly: boolean; } @@ -78,7 +78,7 @@ interface ContractListDetailProps { contractListInfo: ContractListInfo; isLoading: boolean; isReadOnly?: boolean; - onContractSelect: (addr: ContractAddr) => void; + onContractSelect: (addr: BechAddr32) => void; } export const ContractListDetail = ({ diff --git a/src/lib/components/select-contract/SelectContractAdmin.tsx b/src/lib/components/select-contract/SelectContractAdmin.tsx index 0cc8da772..5a42312d7 100644 --- a/src/lib/components/select-contract/SelectContractAdmin.tsx +++ b/src/lib/components/select-contract/SelectContractAdmin.tsx @@ -17,14 +17,14 @@ import { ADMIN_SPECIAL_SLUG } from "lib/data"; import { useContractStore } from "lib/providers/store"; import { useContractListByAdmin } from "lib/services/contractService"; import type { ContractListInfo, ContractLocalInfo } from "lib/stores/contract"; -import type { ContractAddr, HumanAddr } from "lib/types"; +import type { BechAddr32 } from "lib/types"; import { getCurrentDate } from "lib/utils"; import { ContractListDetail } from "./ContractListDetail"; interface SelectContractAdminProps { notSelected: boolean; - onContractSelect: (contract: ContractAddr) => void; + onContractSelect: (contract: BechAddr32) => void; } export const SelectContractAdmin = ({ @@ -35,9 +35,7 @@ export const SelectContractAdmin = ({ const { address } = useCurrentChain(); const { getContractLocalInfo } = useContractStore(); - const { data: contracts = [], isLoading } = useContractListByAdmin( - address as HumanAddr - ); + const { data: contracts = [], isLoading } = useContractListByAdmin(address); const contractList: ContractListInfo = { name: ADMIN_SPECIAL_SLUG, slug: ADMIN_SPECIAL_SLUG, @@ -50,7 +48,7 @@ export const SelectContractAdmin = ({ isContractRemovable: false, }; - const onSelectThenClose = (contract: ContractAddr) => { + const onSelectThenClose = (contract: BechAddr32) => { onContractSelect(contract); onClose(); }; diff --git a/src/lib/components/select-contract/SelectContractInstantiator.tsx b/src/lib/components/select-contract/SelectContractInstantiator.tsx index 728ca4e49..b1ab7186f 100644 --- a/src/lib/components/select-contract/SelectContractInstantiator.tsx +++ b/src/lib/components/select-contract/SelectContractInstantiator.tsx @@ -31,14 +31,14 @@ import { DEFAULT_RPC_ERROR } from "lib/data"; import { useInstantiatedByMe } from "lib/model/contract"; import { useContractStore } from "lib/providers/store"; import { queryContract } from "lib/services/contract"; -import type { ContractAddr, RpcQueryError } from "lib/types"; +import type { BechAddr32, RpcQueryError } from "lib/types"; import { AllContractLists } from "./AllContractLists"; import { ContractListDetail } from "./ContractListDetail"; interface SelectContractInstantiatorProps { notSelected: boolean; - onContractSelect: (contract: ContractAddr) => void; + onContractSelect: (contract: BechAddr32) => void; } export const SelectContractInstantiator = ({ @@ -50,8 +50,8 @@ export const SelectContractInstantiator = ({ const [listSlug, setListSlug] = useState(""); const { validateContractAddress } = useValidateAddress(); - const [searchContract, setSearchContract] = useState( - "" as ContractAddr + const [searchContract, setSearchContract] = useState( + "" as BechAddr32 ); const [invalid, setInvalid] = useState(""); @@ -68,12 +68,12 @@ export const SelectContractInstantiator = ({ const resetOnClose = () => { setListSlug(""); - setSearchContract("" as ContractAddr); + setSearchContract("" as BechAddr32); setInvalid(""); onClose(); }; - const onSelectThenClose = (contract: ContractAddr) => { + const onSelectThenClose = (contract: BechAddr32) => { track(AmpEvent.USE_CONTRACT_MODAL_LISTS); onContractSelect(contract); resetOnClose(); @@ -82,7 +82,7 @@ export const SelectContractInstantiator = ({ // TODO: Abstract query const { refetch, isFetching, isRefetching } = useQuery( [CELATONE_QUERY_KEYS.CONTRACT_INFO, lcdEndpoint, searchContract], - async () => queryContract(lcdEndpoint, searchContract as ContractAddr), + async () => queryContract(lcdEndpoint, searchContract), { enabled: false, retry: false, @@ -164,7 +164,7 @@ export const SelectContractInstantiator = ({ value={searchContract} onChange={(e) => { const inputValue = e.target.value; - setSearchContract(inputValue as ContractAddr); + setSearchContract(inputValue as BechAddr32); }} placeholder={`ex. ${exampleContractAddress}`} size="lg" diff --git a/src/lib/components/table/accounts/SavedAccountsTableRow.tsx b/src/lib/components/table/accounts/SavedAccountsTableRow.tsx index a261a787f..881bc05da 100644 --- a/src/lib/components/table/accounts/SavedAccountsTableRow.tsx +++ b/src/lib/components/table/accounts/SavedAccountsTableRow.tsx @@ -9,7 +9,7 @@ import { RemoveSavedAccountModal, } from "lib/components/modal"; import type { AccountLocalInfo } from "lib/stores/account"; -import type { Addr, HumanAddr } from "lib/types"; +import type { BechAddr } from "lib/types"; import { bech32AddressToHex, unpadHexAddress } from "lib/utils"; import { AccountNameCell } from "./AccountNameCell"; @@ -25,7 +25,7 @@ export const SavedAccountsTableRow = ({ }: SavedAccountsTableRowProps) => { const move = useMoveConfig({ shouldRedirect: false }); const navigate = useInternalNavigate(); - const onRowSelect = (address: Addr) => + const onRowSelect = (address: BechAddr) => navigate({ pathname: "/accounts/[accountAddress]", query: { accountAddress: address }, @@ -51,9 +51,7 @@ export const SavedAccountsTableRow = ({ diff --git a/src/lib/components/table/contracts/ContractsTable.tsx b/src/lib/components/table/contracts/ContractsTable.tsx index ce0b6e492..7379b20fc 100644 --- a/src/lib/components/table/contracts/ContractsTable.tsx +++ b/src/lib/components/table/contracts/ContractsTable.tsx @@ -1,7 +1,7 @@ import { MobileTableContainer, TableContainer } from "../tableComponents"; import { useMobile } from "lib/app-provider"; import { Loading } from "lib/components/Loading"; -import type { ContractAddr, ContractInfo, Option } from "lib/types"; +import type { BechAddr32, ContractInfo, Option } from "lib/types"; import { ContractsTableHeader } from "./ContractsTableHeader"; import { ContractsTableMobileCard } from "./ContractsTableMobileCard"; @@ -12,7 +12,7 @@ interface ContractsTableProps { contracts: Option; isLoading: boolean; emptyState: JSX.Element; - onRowSelect: (contract: ContractAddr) => void; + onRowSelect: (contract: BechAddr32) => void; isReadOnly?: boolean; withCTA?: CTAInfo; withoutTag?: boolean; diff --git a/src/lib/components/table/contracts/ContractsTableMobileCard.tsx b/src/lib/components/table/contracts/ContractsTableMobileCard.tsx index 70924e763..e52218bcf 100644 --- a/src/lib/components/table/contracts/ContractsTableMobileCard.tsx +++ b/src/lib/components/table/contracts/ContractsTableMobileCard.tsx @@ -4,7 +4,7 @@ import { MobileCardTemplate } from "../MobileCardTemplate"; import { MobileLabel } from "../MobileLabel"; import { ExplorerLink } from "lib/components/ExplorerLink"; import type { - ContractAddr, + BechAddr32, ContractHistoryRemark, ContractInfo, Option, @@ -16,7 +16,7 @@ import { ContractInstantiatorCell } from "./ContractInstantiatorCell"; interface ContractsTableMobileCardProps { contractInfo: ContractInfo; - onRowSelect: (contract: ContractAddr) => void; + onRowSelect: (contract: BechAddr32) => void; } const InstantiatorRemark = ({ diff --git a/src/lib/components/table/contracts/ContractsTableRow.tsx b/src/lib/components/table/contracts/ContractsTableRow.tsx index c4a51b1b1..234bfd070 100644 --- a/src/lib/components/table/contracts/ContractsTableRow.tsx +++ b/src/lib/components/table/contracts/ContractsTableRow.tsx @@ -2,7 +2,7 @@ import { Grid } from "@chakra-ui/react"; import { TableRow } from "../tableComponents"; import { ExplorerLink } from "lib/components/ExplorerLink"; -import type { ContractAddr, ContractInfo } from "lib/types"; +import type { BechAddr32, ContractInfo } from "lib/types"; import { ContractInstantiatorCell } from "./ContractInstantiatorCell"; import { ContractNameCell } from "./ContractNameCell"; @@ -13,7 +13,7 @@ import { TagsCell } from "./TagsCell"; interface ContractsTableRowProps { contractInfo: ContractInfo; templateColumns: string; - onRowSelect: (contract: ContractAddr) => void; + onRowSelect: (contract: BechAddr32) => void; isReadOnly: boolean; withCTA?: CTAInfo; withoutTag?: boolean; diff --git a/src/lib/components/table/proposals/Proposer.tsx b/src/lib/components/table/proposals/Proposer.tsx index 178f30ac5..8de75d115 100644 --- a/src/lib/components/table/proposals/Proposer.tsx +++ b/src/lib/components/table/proposals/Proposer.tsx @@ -2,13 +2,13 @@ import { Text } from "@chakra-ui/react"; import { useGetAddressType } from "lib/app-provider"; import { ExplorerLink } from "lib/components/ExplorerLink"; -import type { Addr, Option } from "lib/types"; +import type { BechAddr, Option } from "lib/types"; export const Proposer = ({ proposer, amptrackSection, }: { - proposer: Option; + proposer: Option; amptrackSection?: string; }) => { const getAddressType = useGetAddressType(); diff --git a/src/lib/components/upload/InstantiatePermissionRadio.tsx b/src/lib/components/upload/InstantiatePermissionRadio.tsx index bdec4a7a1..5d40b0886 100644 --- a/src/lib/components/upload/InstantiatePermissionRadio.tsx +++ b/src/lib/components/upload/InstantiatePermissionRadio.tsx @@ -8,7 +8,7 @@ import { AssignMe } from "../AssignMe"; import { AmpEvent, trackUseInstantiatePermission, track } from "lib/amplitude"; import { useCelatoneApp, useCurrentChain } from "lib/app-provider"; import { CustomIcon } from "lib/components/icon"; -import type { Addr, UploadSectionState } from "lib/types"; +import type { BechAddr, UploadSectionState } from "lib/types"; import { AccessType } from "lib/types"; interface InstantiatePermissionRadioProps { @@ -124,7 +124,7 @@ export const InstantiatePermissionRadio = ({ track(AmpEvent.USE_ASSIGN_ME); setValue( `addresses.${idx}.address`, - walletAddress as Addr + walletAddress ?? ("" as BechAddr) ); trigger(`addresses.${idx}.address`); }} @@ -157,9 +157,7 @@ export const InstantiatePermissionRadio = ({ variant="outline-primary" mt={3} mx="auto" - onClick={() => { - append({ address: "" as Addr }); - }} + onClick={() => append({ address: "" as BechAddr })} leftIcon={} > Add More Address diff --git a/src/lib/components/upload/UploadSection.tsx b/src/lib/components/upload/UploadSection.tsx index 55cbae2a3..aa151ec76 100644 --- a/src/lib/components/upload/UploadSection.tsx +++ b/src/lib/components/upload/UploadSection.tsx @@ -6,16 +6,13 @@ import { useForm } from "react-hook-form"; import { DropZone } from "../dropzone"; import { ControllerInput } from "../forms"; import { AmpEvent, track } from "lib/amplitude"; -import type { - UploadSucceedCallback, - UploadTxInternalResult, -} from "lib/app-provider"; +import type { StoreCodeSucceedCallback } from "lib/app-fns/tx/storeCode"; import { useCelatoneApp, useCurrentChain, useFabricateFee, useSimulateFeeForStoreCode, - useUploadContractTx, + useStoreCodeTx, useValidateAddress, } from "lib/app-provider"; import { EstimatedFeeRender } from "lib/components/EstimatedFeeRender"; @@ -23,12 +20,7 @@ import { CustomIcon } from "lib/components/icon"; import { useGetMaxLengthError } from "lib/hooks"; import { useCodeStore } from "lib/providers/store"; import { useTxBroadcast } from "lib/providers/tx-broadcast"; -import type { - Addr, - HumanAddr, - SimulateStatus, - UploadSectionState, -} from "lib/types"; +import type { BechAddr, SimulateStatus, UploadSectionState } from "lib/types"; import { AccessType } from "lib/types"; import { getCodeHash } from "lib/utils"; @@ -39,7 +31,7 @@ import { UploadCard } from "./UploadCard"; interface UploadSectionProps { handleBack: () => void; - onComplete?: UploadSucceedCallback; + onComplete?: StoreCodeSucceedCallback; isMigrate?: boolean; } @@ -59,7 +51,7 @@ export const UploadSection = ({ const { address } = useCurrentChain(); const { broadcast } = useTxBroadcast(); const { updateCodeInfo } = useCodeStore(); - const postUploadTx = useUploadContractTx(isMigrate); + const storeCodeTx = useStoreCodeTx(isMigrate); const { validateUserAddress, validateContractAddress } = useValidateAddress(); const [codeHash, setCodeHash] = useState(); @@ -80,7 +72,7 @@ export const UploadSection = ({ wasmFile: undefined, codeName: "", permission: AccessType.ACCESS_TYPE_EVERYBODY, - addresses: [{ address: "" as Addr }], + addresses: [{ address: "" as BechAddr }], }, mode: "all", }); @@ -149,7 +141,7 @@ export const UploadSection = ({ const proceed = useCallback(async () => { if (address) { track(AmpEvent.ACTION_UPLOAD); - const stream = await postUploadTx({ + const stream = await storeCodeTx({ wasmFileName: wasmFile?.name, wasmCode: wasmFile?.arrayBuffer(), // Remarks: disableAnyOfAddresses is only used for Cosmos SDK 0.26 @@ -159,11 +151,11 @@ export const UploadSection = ({ permission, codeName, estimatedFee, - onTxSucceed: (txResult: UploadTxInternalResult) => { + onTxSucceed: (txResult) => { onComplete?.(txResult); updateCodeInfo( Number(txResult.codeId), - address as HumanAddr, + address, codeName || `${wasmFile?.name}(${txResult.codeId})` ); }, @@ -173,7 +165,7 @@ export const UploadSection = ({ } }, [ address, - postUploadTx, + storeCodeTx, wasmFile, addresses, permission, @@ -199,7 +191,7 @@ export const UploadSection = ({ useEffect(() => { if (!wasmFile) { setDefaultBehavior(); - setValue("addresses", [{ address: "" as Addr }]); + setValue("addresses", [{ address: "" as BechAddr }]); } }, [setValue, wasmFile]); diff --git a/src/lib/hooks/useCodeFilter.ts b/src/lib/hooks/useCodeFilter.ts index f918573a9..a3ee069cb 100644 --- a/src/lib/hooks/useCodeFilter.ts +++ b/src/lib/hooks/useCodeFilter.ts @@ -1,7 +1,7 @@ import { useCallback } from "react"; import { useCurrentChain } from "lib/app-provider"; -import type { CodeInfo, HumanAddr } from "lib/types"; +import type { CodeInfo } from "lib/types"; import { resolvePermission } from "lib/utils"; export type PermissionFilterValue = @@ -14,7 +14,7 @@ export const useCodePermissionFilter = (filterValue: PermissionFilterValue) => { return useCallback( ({ instantiatePermission, permissionAddresses }: CodeInfo) => { const isAllowed = resolvePermission( - address as HumanAddr, + address, instantiatePermission, permissionAddresses ); diff --git a/src/lib/hooks/useExecuteCmds.ts b/src/lib/hooks/useExecuteCmds.ts index 9bb7df296..6c6a45d70 100644 --- a/src/lib/hooks/useExecuteCmds.ts +++ b/src/lib/hooks/useExecuteCmds.ts @@ -1,11 +1,11 @@ import { useEffect, useState } from "react"; import { useSimulateFeeQuery, useDummyWallet } from "lib/app-provider"; -import type { HumanAddr, ContractAddr } from "lib/types"; +import type { BechAddr32 } from "lib/types"; import { MsgType } from "lib/types"; import { composeMsg } from "lib/utils"; -export const useExecuteCmds = (contractAddress: ContractAddr) => { +export const useExecuteCmds = (contractAddress: BechAddr32) => { const [execCmds, setExecCmds] = useState<[string, string][]>([]); const { dummyAddress } = useDummyWallet(); @@ -16,14 +16,16 @@ export const useExecuteCmds = (contractAddress: ContractAddr) => { const { isFetching } = useSimulateFeeQuery({ isDummyUser: true, enabled: !!contractAddress && !!dummyAddress, - messages: [ - composeMsg(MsgType.EXECUTE, { - sender: dummyAddress as HumanAddr, - contract: contractAddress as ContractAddr, - msg: Buffer.from('{"": {}}'), - funds: [], - }), - ], + messages: dummyAddress + ? [ + composeMsg(MsgType.EXECUTE, { + sender: dummyAddress, + contract: contractAddress, + msg: Buffer.from('{"": {}}'), + funds: [], + }), + ] + : [], retry: false, onError: (e) => { const executeCmds: string[] = []; diff --git a/src/lib/hooks/useFormatAddresses.ts b/src/lib/hooks/useFormatAddresses.ts index 2336fe2c4..a223019d4 100644 --- a/src/lib/hooks/useFormatAddresses.ts +++ b/src/lib/hooks/useFormatAddresses.ts @@ -1,7 +1,7 @@ import { useCallback } from "react"; import { useConvertHexAddress } from "lib/app-provider"; -import type { HexAddr, HumanAddr } from "lib/types"; +import type { BechAddr, HexAddr } from "lib/types"; import { bech32AddressToHex, isHexModuleAddress, @@ -26,8 +26,8 @@ export const useFormatAddresses = () => { hex: unpadHexAddress(address as HexAddr), }; return { - address: address as HumanAddr, - hex: unpadHexAddress(bech32AddressToHex(address as HumanAddr)), + address: address as BechAddr, + hex: unpadHexAddress(bech32AddressToHex(address as BechAddr)), }; }, [convertHexModuleAddress, convertHexWalletAddress] diff --git a/src/lib/hooks/useHandleSave.tsx b/src/lib/hooks/useHandleSave.tsx index 83399bcba..c1732ff5d 100644 --- a/src/lib/hooks/useHandleSave.tsx +++ b/src/lib/hooks/useHandleSave.tsx @@ -2,15 +2,15 @@ import { useToast } from "@chakra-ui/react"; import { CustomIcon } from "lib/components/icon"; import { useAccountStore, useContractStore } from "lib/providers/store"; -import type { Addr, ContractAddr, LVPair, Option } from "lib/types"; +import type { BechAddr, BechAddr32, LVPair, Option } from "lib/types"; import { useFormatAddresses } from "./useFormatAddresses"; import { useUserKey } from "./useUserKey"; interface UseHandleContractSaveProps { title: string; - contractAddress: ContractAddr; - instantiator: Option; + contractAddress: BechAddr32; + instantiator: Option; label: string; name?: string; description?: string; @@ -21,7 +21,7 @@ interface UseHandleContractSaveProps { interface UseHandleAccountSaveProps { title: string; - address: Addr; + address: BechAddr; name: string; description?: string; actions?: () => void; diff --git a/src/lib/hooks/useSingleMessageProps.ts b/src/lib/hooks/useSingleMessageProps.ts index 77e82eabc..8687281f8 100644 --- a/src/lib/hooks/useSingleMessageProps.ts +++ b/src/lib/hooks/useSingleMessageProps.ts @@ -11,14 +11,14 @@ import type { DetailExecute, DetailInstantiate, DetailSend, + DetailStoreCode, DetailUpdateAdmin, - DetailUpload, Message, Option, DetailMigrate, DetailClearAdmin, - ContractAddr, AssetInfo, + BechAddr32, } from "lib/types"; import { getFirstQueryParam, getExecuteMsgTags } from "lib/utils"; @@ -44,7 +44,7 @@ const instantiateSingleMsgProps = ( isSuccess: boolean, messages: Message[], getContractLocalInfo: ( - contractAddress: ContractAddr + contractAddress: BechAddr32 ) => Option, isInstantiate2: boolean, getAddressTypeByLength: GetAddressTypeByLengthFn @@ -53,7 +53,7 @@ const instantiateSingleMsgProps = ( // TODO - revisit, instantiate detail response when query from contract transaction table doesn't contain contract addr const contractAddress = detail.contractAddress || - (getFirstQueryParam(router.query.contractAddress) as ContractAddr); + (getFirstQueryParam(router.query.contractAddress) as BechAddr32); const contractLocalInfo = getContractLocalInfo(contractAddress); const type = isInstantiate2 ? "Instantiate2" : "Instantiate"; @@ -124,7 +124,7 @@ const executeSingleMsgProps = ( messages: Message[], singleMsg: Option, getContractLocalInfo: ( - contractAddress: ContractAddr + contractAddress: BechAddr32 ) => Option, getAddressTypeByLength: GetAddressTypeByLengthFn ) => { @@ -224,13 +224,13 @@ const sendSingleMsgProps = ( messages: Message[], assetInfos: Option>, getContractLocalInfo: ( - contractAddress: ContractAddr + contractAddress: BechAddr32 ) => Option, getAddressTypeByLength: GetAddressTypeByLengthFn ) => { const detail = messages[0].detail as DetailSend; const contractLocalInfo = getContractLocalInfo( - detail.toAddress as ContractAddr + detail.toAddress as BechAddr32 ); const tokens = detail.amount.map((coin) => ({ @@ -324,7 +324,7 @@ const migrateSingleMsgProps = ( isSuccess: boolean, messages: Message[], getContractLocalInfo: ( - contractAddress: ContractAddr + contractAddress: BechAddr32 ) => Option, getAddressTypeByLength: GetAddressTypeByLengthFn ) => { @@ -390,13 +390,14 @@ const updateAdminSingleMsgProps = ( isSuccess: boolean, messages: Message[], getContractLocalInfo: ( - contractAddress: ContractAddr + contractAddress: BechAddr32 ) => Option, getAddressTypeByLength: GetAddressTypeByLengthFn ) => { const detail = messages[0].detail as DetailUpdateAdmin; const contractLocalInfo = getContractLocalInfo(detail.contract); - const adminLocalInfo = getContractLocalInfo(detail.newAdmin as ContractAddr); + // TODO: need to also handle getAccountLocalInfo + const adminLocalInfo = getContractLocalInfo(detail.newAdmin as BechAddr32); if (messages.length > 1) { return isSuccess @@ -463,7 +464,7 @@ const clearAdminSingleMsgProps = ( isSuccess: boolean, messages: Message[], getContractLocalInfo: ( - contractAddress: ContractAddr + contractAddress: BechAddr32 ) => Option, getAddressTypeByLength: GetAddressTypeByLengthFn ) => { @@ -522,7 +523,7 @@ const clearAdminSingleMsgProps = ( * */ const storeCodeSingleMsgProps = (isSuccess: boolean, messages: Message[]) => { - const detail = messages[0].detail as DetailUpload; + const detail = messages[0].detail as DetailStoreCode; if (messages.length > 1) { return isSuccess diff --git a/src/lib/layout/Searchbar.tsx b/src/lib/layout/Searchbar.tsx index dafc4c9a8..0a362dc80 100644 --- a/src/lib/layout/Searchbar.tsx +++ b/src/lib/layout/Searchbar.tsx @@ -33,7 +33,7 @@ import type { SearchResultType, } from "lib/services/searchService"; import { useSearchHandler } from "lib/services/searchService"; -import type { MoveAccountAddr, Nullable, Option } from "lib/types"; +import type { Addr, Nullable, Option } from "lib/types"; import { splitModule } from "lib/utils"; const NOT_FOUND_MSG = @@ -273,7 +273,7 @@ const Searchbar = () => { if (routeOptions) { const queryValues = type === "Module Path" - ? (splitModule(keyword) as [MoveAccountAddr, string]) + ? (splitModule(keyword) as [Addr, string]) : metadata.icns.address || keyword; navigate({ pathname: routeOptions.pathname, diff --git a/src/lib/model/code.ts b/src/lib/model/code.ts index a3fddde46..680005a6a 100644 --- a/src/lib/model/code.ts +++ b/src/lib/model/code.ts @@ -20,11 +20,10 @@ import { } from "lib/services/publicProjectService"; import type { CodeData, - PublicDetail, - Option, - HumanAddr, CodeInfo, + Option, PublicCode, + PublicDetail, } from "lib/types"; import { AccessConfigPermission } from "lib/types"; @@ -77,9 +76,8 @@ const useStoredCodes = () => { const { address } = useCurrentChain(); const { getCodeLocalInfo, isCodeIdSaved, isHydrated } = useCodeStore(); - const { data: rawStoredCodes, isLoading } = useCodeListByWalletAddress( - address as HumanAddr - ); + const { data: rawStoredCodes, isLoading } = + useCodeListByWalletAddress(address); const storedCodes = rawStoredCodes?.map((code) => ({ diff --git a/src/lib/model/contract.ts b/src/lib/model/contract.ts index c5aa7b8b3..29e5228e7 100644 --- a/src/lib/model/contract.ts +++ b/src/lib/model/contract.ts @@ -8,13 +8,7 @@ import { useInstantiatedListByUserQuery, } from "lib/services/contractService"; import type { ContractListInfo } from "lib/stores/contract"; -import type { - Addr, - ContractAddr, - HumanAddr, - ContractInfo, - Option, -} from "lib/types"; +import type { BechAddr, BechAddr32, ContractInfo, Option } from "lib/types"; import { formatSlugName, getCurrentDate, getDefaultDate } from "lib/utils"; interface InstantiatedByMeState { @@ -25,7 +19,7 @@ interface InstantiatedByMeState { export const useInstantiatedByMe = (enable: boolean): InstantiatedByMeState => { const { address } = useCurrentChain(); const { data: contracts = [], isLoading } = useInstantiatedListByUserQuery( - enable ? (address as HumanAddr) : undefined + enable ? address : undefined ); const { getContractLocalInfo } = useContractStore(); @@ -48,12 +42,12 @@ export const useInstantiatedByMe = (enable: boolean): InstantiatedByMeState => { export const useInstantiatedMockInfoByMe = (): ContractListInfo => { const { address } = useCurrentChain(); - const { data: count } = useInstantiatedCountByUserQuery(address as HumanAddr); + const { data: count } = useInstantiatedCountByUserQuery(address); return { contracts: Array.from({ length: count ?? 0 }, () => ({ - contractAddress: "" as ContractAddr, - instantiator: "" as Addr, + contractAddress: "" as BechAddr32, + instantiator: "" as BechAddr, label: "", created: getDefaultDate(), })), diff --git a/src/lib/pages/account-details/components/AccountHeader.tsx b/src/lib/pages/account-details/components/AccountHeader.tsx index 3183969d2..a56ed9bd4 100644 --- a/src/lib/pages/account-details/components/AccountHeader.tsx +++ b/src/lib/pages/account-details/components/AccountHeader.tsx @@ -12,13 +12,13 @@ import { import { PrimaryNameMark } from "lib/components/PrimaryNameMark"; import { useAccountStore } from "lib/providers/store"; import type { AccountData } from "lib/services/account"; -import type { HexAddr, HumanAddr, Option } from "lib/types"; +import type { HexAddr, BechAddr, Option } from "lib/types"; import { TotalAccountValue } from "./TotalAccountValue"; interface AccounHeaderProps { accountData: Option; - accountAddress: HumanAddr; + accountAddress: BechAddr; hexAddress: HexAddr; } diff --git a/src/lib/pages/account-details/components/TotalAccountValue.tsx b/src/lib/pages/account-details/components/TotalAccountValue.tsx index bfc3b51bf..c207032f4 100644 --- a/src/lib/pages/account-details/components/TotalAccountValue.tsx +++ b/src/lib/pages/account-details/components/TotalAccountValue.tsx @@ -1,11 +1,11 @@ import { Flex, Heading, Skeleton, Text } from "@chakra-ui/react"; import { useAccountTotalValue } from "../data"; -import type { HumanAddr } from "lib/types"; +import type { BechAddr } from "lib/types"; import { formatPrice } from "lib/utils"; interface TotalAccountValueProps { - accountAddress: HumanAddr; + accountAddress: BechAddr; } export const TotalAccountValue = ({ accountAddress, diff --git a/src/lib/pages/account-details/components/UserAccountDesc.tsx b/src/lib/pages/account-details/components/UserAccountDesc.tsx index d5d0dbd02..15e5a2526 100644 --- a/src/lib/pages/account-details/components/UserAccountDesc.tsx +++ b/src/lib/pages/account-details/components/UserAccountDesc.tsx @@ -8,10 +8,10 @@ import { ShowMoreButton } from "lib/components/button"; import { CustomIcon } from "lib/components/icon"; import { EditSavedAccountModal } from "lib/components/modal"; import { useAccountStore } from "lib/providers/store"; -import type { Addr } from "lib/types"; +import type { BechAddr } from "lib/types"; interface UserAccountDescProps { - address: Addr; + address: BechAddr; publicAccount?: boolean; } diff --git a/src/lib/pages/account-details/components/asset/AssetCta.tsx b/src/lib/pages/account-details/components/asset/AssetCta.tsx index 547453ead..6a55f6b9b 100644 --- a/src/lib/pages/account-details/components/asset/AssetCta.tsx +++ b/src/lib/pages/account-details/components/asset/AssetCta.tsx @@ -4,12 +4,12 @@ import { trackUseViewJSON } from "lib/amplitude"; import { CustomIcon } from "lib/components/icon"; import { UnsupportedTokensModal } from "lib/components/modal"; import { useOpenAssetTab } from "lib/hooks"; -import type { Addr, TokenWithValue } from "lib/types"; +import type { BechAddr, TokenWithValue } from "lib/types"; interface AssetCtaProps { unsupportedAssets: TokenWithValue[]; totalAsset: number; - address: Addr; + address: BechAddr; } export const AssetCta = ({ diff --git a/src/lib/pages/account-details/components/asset/index.tsx b/src/lib/pages/account-details/components/asset/index.tsx index 48a3d0dc6..ef90bd5e8 100644 --- a/src/lib/pages/account-details/components/asset/index.tsx +++ b/src/lib/pages/account-details/components/asset/index.tsx @@ -5,7 +5,7 @@ import { CustomIcon } from "lib/components/icon"; import { Loading } from "lib/components/Loading"; import { TableTitle, ViewMore } from "lib/components/table"; import { useBalanceInfos } from "lib/services/balanceService"; -import type { Addr } from "lib/types"; +import type { BechAddr } from "lib/types"; import { AssetCta } from "./AssetCta"; import { AssetSectionContent } from "./AssetSectionContent"; @@ -14,7 +14,7 @@ import { UserAssetInfoCard } from "./UserAssetInfoCard"; const MAX_ASSETS_SHOW = 8; interface AssetsSectionProps { - address: Addr; + address: BechAddr; onViewMore?: () => void; } diff --git a/src/lib/pages/account-details/components/delegations/index.tsx b/src/lib/pages/account-details/components/delegations/index.tsx index 50ef60b20..f3cb51b1f 100644 --- a/src/lib/pages/account-details/components/delegations/index.tsx +++ b/src/lib/pages/account-details/components/delegations/index.tsx @@ -6,7 +6,7 @@ import { AmpEvent, track } from "lib/amplitude"; import { Loading } from "lib/components/Loading"; import { ErrorFetching } from "lib/components/state"; import { useUserDelegationInfos } from "lib/pages/account-details/data"; -import type { HumanAddr } from "lib/types"; +import type { BechAddr } from "lib/types"; import { getTokenLabel } from "lib/utils"; import { DelegationInfo } from "./DelegationInfo"; @@ -15,16 +15,16 @@ import { RedelegationsSection } from "./RedelegationsSection"; import { TotalCard } from "./total-card"; interface DelegationsSectionProps { - walletAddress: HumanAddr; + address: BechAddr; onViewMore?: () => void; } export const DelegationsSection = ({ - walletAddress, + address, onViewMore, }: DelegationsSectionProps) => { - const { isOpen, onToggle, onClose } = useDisclosure(); const router = useRouter(); + const { isOpen, onToggle, onClose } = useDisclosure(); const { isLoading, stakingParams, @@ -38,7 +38,7 @@ export const DelegationsSection = ({ rewards, redelegations, totalCommission, - } = useUserDelegationInfos(walletAddress); + } = useUserDelegationInfos(address); useEffect(() => { onClose(); @@ -77,7 +77,7 @@ export const DelegationsSection = ({ ) : "tokens" }, including those delegated through vesting`} - address={walletAddress} + address={address} bondDenoms={stakingParams.bondDenoms} tokens={totalBonded} isLoading={isLoading} @@ -96,7 +96,7 @@ export const DelegationsSection = ({ ) : "tokens" } across all validators`} - address={walletAddress} + address={address} bondDenoms={stakingParams.bondDenoms} tokens={totalRewards} isLoading={isLoading} @@ -106,7 +106,7 @@ export const DelegationsSection = ({ >; } diff --git a/src/lib/pages/account-details/components/delegations/total-card/TotalCardModal.tsx b/src/lib/pages/account-details/components/delegations/total-card/TotalCardModal.tsx index eeafca660..c698cec20 100644 --- a/src/lib/pages/account-details/components/delegations/total-card/TotalCardModal.tsx +++ b/src/lib/pages/account-details/components/delegations/total-card/TotalCardModal.tsx @@ -17,7 +17,7 @@ import big from "big.js"; import { CopyLink } from "lib/components/CopyLink"; import { CustomIcon } from "lib/components/icon"; import { TokenImageRender, TokenComposition } from "lib/components/token"; -import type { Addr, TokenWithValue, USD } from "lib/types"; +import type { BechAddr, TokenWithValue, USD } from "lib/types"; import { compareTokenWithValues, formatPrice, @@ -30,7 +30,7 @@ import { TotalCardTop } from "./TotalCardTop"; interface TotalCardModel { title: string; message: string; - address: Addr; + address: BechAddr; tokens: Record; isOpen: boolean; onClose: () => void; diff --git a/src/lib/pages/account-details/components/delegations/total-card/index.tsx b/src/lib/pages/account-details/components/delegations/total-card/index.tsx index 0bde51656..770bb4ae4 100644 --- a/src/lib/pages/account-details/components/delegations/total-card/index.tsx +++ b/src/lib/pages/account-details/components/delegations/total-card/index.tsx @@ -1,6 +1,6 @@ import { Box, Spinner } from "@chakra-ui/react"; -import type { Addr, Option, TokenWithValue } from "lib/types"; +import type { BechAddr, Option, TokenWithValue } from "lib/types"; import { MultiBondsCard } from "./MultiBondsCard"; import { OverviewCard } from "./OverviewCard"; @@ -9,7 +9,7 @@ import { SingleBondCard } from "./single-bond-card"; export interface TotalCardProps { title: string; message: string; - address: Addr; + address: BechAddr; bondDenoms: TokenWithValue[]; tokens: Option>; isLoading: boolean; diff --git a/src/lib/pages/account-details/components/delegations/total-card/single-bond-card/SingleBondCardBody.tsx b/src/lib/pages/account-details/components/delegations/total-card/single-bond-card/SingleBondCardBody.tsx index dced70c8b..858be932f 100644 --- a/src/lib/pages/account-details/components/delegations/total-card/single-bond-card/SingleBondCardBody.tsx +++ b/src/lib/pages/account-details/components/delegations/total-card/single-bond-card/SingleBondCardBody.tsx @@ -1,4 +1,4 @@ -import type { Addr, TokenWithValue } from "lib/types"; +import type { BechAddr, TokenWithValue } from "lib/types"; import { SingleBondCardBodyMulti } from "./SingleBondCardBodyMulti"; import { SingleBondCardBodySingle } from "./SingleBondCardBodySingle"; @@ -6,7 +6,7 @@ import { SingleBondCardBodySingle } from "./SingleBondCardBodySingle"; interface SingleBondCardBodyProps { title: string; message: string; - address: Addr; + address: BechAddr; bondDenom: TokenWithValue; tokens: Record; } diff --git a/src/lib/pages/account-details/components/delegations/total-card/single-bond-card/SingleBondCardBodyMulti.tsx b/src/lib/pages/account-details/components/delegations/total-card/single-bond-card/SingleBondCardBodyMulti.tsx index 2815afde9..5570650d7 100644 --- a/src/lib/pages/account-details/components/delegations/total-card/single-bond-card/SingleBondCardBodyMulti.tsx +++ b/src/lib/pages/account-details/components/delegations/total-card/single-bond-card/SingleBondCardBodyMulti.tsx @@ -3,13 +3,13 @@ import big, { type Big } from "big.js"; import { TotalCardModal } from "../TotalCardModal"; import { CustomIcon } from "lib/components/icon"; -import type { Addr, TokenWithValue, USD } from "lib/types"; +import type { BechAddr, TokenWithValue, USD } from "lib/types"; import { formatPrice, totalValueTokenWithValue } from "lib/utils"; interface SingleBondCardBodyMultiProps { title: string; message: string; - address: Addr; + address: BechAddr; tokens: Record; } diff --git a/src/lib/pages/account-details/components/delegations/total-card/single-bond-card/index.tsx b/src/lib/pages/account-details/components/delegations/total-card/single-bond-card/index.tsx index 087f9467d..3a2b6b40f 100644 --- a/src/lib/pages/account-details/components/delegations/total-card/single-bond-card/index.tsx +++ b/src/lib/pages/account-details/components/delegations/total-card/single-bond-card/index.tsx @@ -1,14 +1,14 @@ import { Flex, Heading } from "@chakra-ui/react"; import { TotalCardTop } from "../TotalCardTop"; -import type { Addr, Option, TokenWithValue } from "lib/types"; +import type { BechAddr, Option, TokenWithValue } from "lib/types"; import { SingleBondCardBody } from "./SingleBondCardBody"; interface SingleBondCardProps { title: string; message: string; - address: Addr; + address: BechAddr; bondDenom: TokenWithValue; tokens: Option>; } diff --git a/src/lib/pages/account-details/components/modules/ModuleLists.tsx b/src/lib/pages/account-details/components/modules/ModuleLists.tsx index 85234b1b1..cc1880bf2 100644 --- a/src/lib/pages/account-details/components/modules/ModuleLists.tsx +++ b/src/lib/pages/account-details/components/modules/ModuleLists.tsx @@ -5,21 +5,21 @@ import { useMobile } from "lib/app-provider"; import InputWithIcon from "lib/components/InputWithIcon"; import { MobileTitle, TableTitle, ViewMore } from "lib/components/table"; import { type IndexedModule } from "lib/services/move/moduleService"; -import type { MoveAccountAddr, Option } from "lib/types"; +import type { BechAddr, Option } from "lib/types"; import { ModuleListsBody } from "./ModuleListsBody"; interface ModuleListsProps { + address: BechAddr; totalCount: Option; - selectedAddress: MoveAccountAddr; modules: Option; isLoading: boolean; onViewMore?: () => void; } export const ModuleLists = ({ + address, totalCount, - selectedAddress, modules, isLoading, onViewMore, @@ -53,7 +53,7 @@ export const ModuleLists = ({ /> )} ; isLoading: boolean; @@ -16,7 +16,7 @@ interface ModuleListsBodyProps { } export const ModuleListsBody = ({ - selectedAddress, + address, keyword, modules, isLoading, @@ -51,7 +51,7 @@ export const ModuleListsBody = ({ (item) => ( diff --git a/src/lib/pages/account-details/components/resources/ResourceLeftPanel.tsx b/src/lib/pages/account-details/components/resources/ResourceLeftPanel.tsx index 64113b41c..f25204154 100644 --- a/src/lib/pages/account-details/components/resources/ResourceLeftPanel.tsx +++ b/src/lib/pages/account-details/components/resources/ResourceLeftPanel.tsx @@ -15,14 +15,14 @@ import { useInternalNavigate } from "lib/app-provider"; import InputWithIcon from "lib/components/InputWithIcon"; import { ResourceCard } from "lib/components/resource"; import type { - HumanAddr, + BechAddr, ResourceGroup, ResourceGroupByAccount, } from "lib/types"; import { getFirstQueryParam, truncate } from "lib/utils"; interface ResourceSectionBodyProps { - address: HumanAddr; + address: BechAddr; resourcesByOwner: ResourceGroupByAccount[]; } diff --git a/src/lib/pages/account-details/components/resources/ResourceOverview.tsx b/src/lib/pages/account-details/components/resources/ResourceOverview.tsx index 11eb9d18a..94ebebf9f 100644 --- a/src/lib/pages/account-details/components/resources/ResourceOverview.tsx +++ b/src/lib/pages/account-details/components/resources/ResourceOverview.tsx @@ -2,12 +2,12 @@ import { Box } from "@chakra-ui/react"; import { useMobile } from "lib/app-provider"; import { MobileTitle, TableTitle } from "lib/components/table"; -import type { MoveAccountAddr, Option, ResourceGroup } from "lib/types"; +import type { BechAddr, Option, ResourceGroup } from "lib/types"; import { ResourceOverviewBody } from "./ResourceOverviewBody"; interface ResourceOverviewProps { - address: MoveAccountAddr; + address: BechAddr; totalCount: Option; resourcesByName: Option; isLoading: boolean; diff --git a/src/lib/pages/account-details/components/resources/ResourceOverviewBody.tsx b/src/lib/pages/account-details/components/resources/ResourceOverviewBody.tsx index a1f5a10c8..20599254e 100644 --- a/src/lib/pages/account-details/components/resources/ResourceOverviewBody.tsx +++ b/src/lib/pages/account-details/components/resources/ResourceOverviewBody.tsx @@ -6,11 +6,11 @@ import { Loading } from "lib/components/Loading"; import { ResourceCard } from "lib/components/resource"; import { ErrorFetching, EmptyState } from "lib/components/state"; import { ViewMore } from "lib/components/table"; -import type { MoveAccountAddr, Option, ResourceGroup } from "lib/types"; +import type { BechAddr, Option, ResourceGroup } from "lib/types"; import { scrollToTop } from "lib/utils"; interface ResourceOverviewBodyProps { - address: MoveAccountAddr; + address: BechAddr; resourcesByName: Option; isLoading: boolean; onViewMore: () => void; diff --git a/src/lib/pages/account-details/components/resources/ResourceSection.tsx b/src/lib/pages/account-details/components/resources/ResourceSection.tsx index 31e52d928..b1d7b96ed 100644 --- a/src/lib/pages/account-details/components/resources/ResourceSection.tsx +++ b/src/lib/pages/account-details/components/resources/ResourceSection.tsx @@ -1,12 +1,12 @@ import { Flex } from "@chakra-ui/react"; import { TableTitle } from "lib/components/table"; -import type { HumanAddr, ResourceGroupByAccount, Option } from "lib/types"; +import type { BechAddr, ResourceGroupByAccount, Option } from "lib/types"; import { ResourceSectionBody } from "./ResourceSectionBody"; interface ResourceSectionProps { - address: HumanAddr; + address: BechAddr; totalCount: Option; resourcesByOwner: Option; isLoading: boolean; diff --git a/src/lib/pages/account-details/components/resources/ResourceSectionBody.tsx b/src/lib/pages/account-details/components/resources/ResourceSectionBody.tsx index ddb448a88..9c2ae31c7 100644 --- a/src/lib/pages/account-details/components/resources/ResourceSectionBody.tsx +++ b/src/lib/pages/account-details/components/resources/ResourceSectionBody.tsx @@ -9,13 +9,13 @@ import { CustomIcon } from "lib/components/icon"; import { Loading } from "lib/components/Loading"; import { ResourceDetailCard } from "lib/components/resource"; import { ErrorFetching, EmptyState } from "lib/components/state"; -import type { HumanAddr, Option, ResourceGroupByAccount } from "lib/types"; +import type { BechAddr, Option, ResourceGroupByAccount } from "lib/types"; import { getFirstQueryParam } from "lib/utils"; import { ResourceLeftPanel } from "./ResourceLeftPanel"; interface ResourceSectionBodyProps { - address: HumanAddr; + address: BechAddr; resourcesByOwner: Option; isLoading: boolean; } diff --git a/src/lib/pages/account-details/components/tables/AdminContractsTable.tsx b/src/lib/pages/account-details/components/tables/AdminContractsTable.tsx index 558204866..8ce26f568 100644 --- a/src/lib/pages/account-details/components/tables/AdminContractsTable.tsx +++ b/src/lib/pages/account-details/components/tables/AdminContractsTable.tsx @@ -13,10 +13,10 @@ import { ViewMore, } from "lib/components/table"; import { useAccountAdminContracts } from "lib/pages/account-details/data"; -import type { ContractAddr, HumanAddr, Option } from "lib/types"; +import type { BechAddr, BechAddr32, Option } from "lib/types"; interface AdminContractsTableProps { - walletAddress: HumanAddr; + address: BechAddr; scrollComponentId: string; totalData: Option; refetchCount: () => void; @@ -25,7 +25,7 @@ interface AdminContractsTableProps { export const AdminContractsTable = observer( ({ - walletAddress, + address, scrollComponentId, totalData, refetchCount, @@ -33,7 +33,7 @@ export const AdminContractsTable = observer( }: AdminContractsTableProps) => { const isMobile = useMobile(); const navigate = useInternalNavigate(); - const onRowSelect = (contract: ContractAddr) => + const onRowSelect = (contract: BechAddr32) => navigate({ pathname: "/contracts/[contract]", query: { contract }, @@ -55,7 +55,7 @@ export const AdminContractsTable = observer( }, }); const { contracts, isLoading } = useAccountAdminContracts( - walletAddress, + address, offset, onViewMore ? 5 : pageSize ); diff --git a/src/lib/pages/account-details/components/tables/InstantiatedContractsTable.tsx b/src/lib/pages/account-details/components/tables/InstantiatedContractsTable.tsx index ba6c25cd8..74c2018b9 100644 --- a/src/lib/pages/account-details/components/tables/InstantiatedContractsTable.tsx +++ b/src/lib/pages/account-details/components/tables/InstantiatedContractsTable.tsx @@ -13,10 +13,10 @@ import { ViewMore, } from "lib/components/table"; import { useAccountContracts } from "lib/pages/account-details/data"; -import type { ContractAddr, HumanAddr, Option } from "lib/types"; +import type { BechAddr, BechAddr32, Option } from "lib/types"; interface InstantiatedContractsTableProps { - walletAddress: HumanAddr; + address: BechAddr; scrollComponentId: string; totalData: Option; refetchCount: () => void; @@ -25,7 +25,7 @@ interface InstantiatedContractsTableProps { export const InstantiatedContractsTable = observer( ({ - walletAddress, + address, scrollComponentId, totalData, refetchCount, @@ -33,7 +33,7 @@ export const InstantiatedContractsTable = observer( }: InstantiatedContractsTableProps) => { const isMobile = useMobile(); const navigate = useInternalNavigate(); - const onRowSelect = (contract: ContractAddr) => + const onRowSelect = (contract: BechAddr32) => navigate({ pathname: "/contracts/[contract]", query: { contract }, @@ -55,7 +55,7 @@ export const InstantiatedContractsTable = observer( }, }); const { contracts, isLoading } = useAccountContracts( - walletAddress, + address, offset, onViewMore ? 5 : pageSize ); diff --git a/src/lib/pages/account-details/components/tables/OpenedProposalsTable.tsx b/src/lib/pages/account-details/components/tables/OpenedProposalsTable.tsx index a9161aee6..db66b6757 100644 --- a/src/lib/pages/account-details/components/tables/OpenedProposalsTable.tsx +++ b/src/lib/pages/account-details/components/tables/OpenedProposalsTable.tsx @@ -12,10 +12,10 @@ import { ViewMore, } from "lib/components/table"; import { useProposalsByAddress } from "lib/services/proposalService"; -import type { HumanAddr, Option } from "lib/types"; +import type { BechAddr, Option } from "lib/types"; interface OpenedProposalsTableProps { - walletAddress: HumanAddr; + address: BechAddr; scrollComponentId: string; totalData: Option; refetchCount: () => void; @@ -23,7 +23,7 @@ interface OpenedProposalsTableProps { } export const OpenedProposalsTable = ({ - walletAddress, + address, scrollComponentId, totalData, refetchCount, @@ -48,7 +48,7 @@ export const OpenedProposalsTable = ({ }); const { data: proposals, isLoading } = useProposalsByAddress( - walletAddress, + address, offset, onViewMore ? 5 : pageSize ); diff --git a/src/lib/pages/account-details/components/tables/StoredCodesTable.tsx b/src/lib/pages/account-details/components/tables/StoredCodesTable.tsx index 0f528bcac..88b747552 100644 --- a/src/lib/pages/account-details/components/tables/StoredCodesTable.tsx +++ b/src/lib/pages/account-details/components/tables/StoredCodesTable.tsx @@ -13,10 +13,10 @@ import { ViewMore, } from "lib/components/table"; import { useAccountCodes } from "lib/pages/account-details/data"; -import type { HumanAddr, Option } from "lib/types"; +import type { BechAddr, Option } from "lib/types"; interface StoredCodesTableProps { - walletAddress: HumanAddr; + address: BechAddr; scrollComponentId: string; totalData: Option; refetchCount: () => void; @@ -25,7 +25,7 @@ interface StoredCodesTableProps { export const StoredCodesTable = observer( ({ - walletAddress, + address, scrollComponentId, totalData, refetchCount, @@ -55,7 +55,7 @@ export const StoredCodesTable = observer( }, }); const { codes, isLoading } = useAccountCodes( - walletAddress, + address, offset, onViewMore ? 5 : pageSize ); diff --git a/src/lib/pages/account-details/components/tables/txs/index.tsx b/src/lib/pages/account-details/components/tables/txs/index.tsx index cc119adfe..f1b693b23 100644 --- a/src/lib/pages/account-details/components/tables/txs/index.tsx +++ b/src/lib/pages/account-details/components/tables/txs/index.tsx @@ -11,13 +11,13 @@ import { TxFilterSelection } from "lib/components/TxFilterSelection"; import { TxRelationSelection } from "lib/components/TxRelationSelection"; import { DEFAULT_TX_FILTERS } from "lib/data"; import { useTxsCountByAddress, useTxsByAddress } from "lib/services/txService"; -import type { Addr, Option, TxFilters } from "lib/types"; +import type { BechAddr, Option, TxFilters } from "lib/types"; import { TxsAlert } from "./TxsAlert"; import { TxsTop } from "./TxsTop"; interface TxsTableProps { - address: Addr; + address: BechAddr; scrollComponentId: string; refetchCount: () => void; onViewMore?: () => void; diff --git a/src/lib/pages/account-details/data.ts b/src/lib/pages/account-details/data.ts index f47d28511..8ccffc675 100644 --- a/src/lib/pages/account-details/data.ts +++ b/src/lib/pages/account-details/data.ts @@ -14,10 +14,9 @@ import { import { useDelegationsByAddress } from "lib/services/delegationService"; import { useMovePoolInfos } from "lib/services/move"; import type { - Addr, + BechAddr, CodeInfo, ContractInfo, - HumanAddr, Nullish, Option, TokenWithValue, @@ -55,7 +54,7 @@ interface AccountDetailsTableCounts { } export const useAccountDetailsTableCounts = ( - address: HumanAddr + address: BechAddr ): AccountDetailsTableCounts => { const { data, @@ -88,12 +87,12 @@ interface AccountContracts { } export const useAccountContracts = ( - walletAddress: HumanAddr, + address: BechAddr, offset: number, limit: number ): AccountContracts => { const { data: contracts, isLoading } = useInstantiatedContractsByAddress( - walletAddress, + address, limit, offset ); @@ -116,12 +115,12 @@ export const useAccountContracts = ( }; export const useAccountAdminContracts = ( - walletAddress: HumanAddr, + address: BechAddr, offset: number, pageSize: number ): AccountContracts => { const { data: contractsAdmin, isLoading } = useAdminContractsByAddress( - walletAddress as HumanAddr, + address, pageSize, offset ); @@ -155,15 +154,11 @@ interface AccountCodes { } export const useAccountCodes = ( - walletAddress: HumanAddr, + address: BechAddr, offset: number, limit: number ): AccountCodes => { - const { data: codes, isLoading } = useCodesByAddress( - walletAddress as HumanAddr, - limit, - offset - ); + const { data: codes, isLoading } = useCodesByAddress(address, limit, offset); const { getCodeLocalInfo, isCodeIdSaved } = useCodeStore(); @@ -216,7 +211,7 @@ const calBonded = ( ); }; -export const useUserDelegationInfos = (address: Addr) => { +export const useUserDelegationInfos = (address: BechAddr) => { const { data: assetInfos, isLoading: isLoadingAssetInfos } = useAssetInfos({ withPrices: true, }); @@ -362,7 +357,7 @@ export const useUserDelegationInfos = (address: Addr) => { return data; }; -export const useAccountTotalValue = (address: Addr) => { +export const useAccountTotalValue = (address: BechAddr) => { const defaultValue = big(0) as USD; const { diff --git a/src/lib/pages/account-details/index.tsx b/src/lib/pages/account-details/index.tsx index 6f1038ee1..86ff76710 100644 --- a/src/lib/pages/account-details/index.tsx +++ b/src/lib/pages/account-details/index.tsx @@ -28,7 +28,7 @@ import { useFormatAddresses } from "lib/hooks/useFormatAddresses"; import { useAccountData } from "lib/services/accountService"; import { useModulesByAddress } from "lib/services/move/moduleService"; import { useResourcesByAddress } from "lib/services/move/resourceService"; -import type { Addr, HexAddr, HumanAddr, Option } from "lib/types"; +import type { Addr, BechAddr, HexAddr, Option } from "lib/types"; import { truncate } from "lib/utils"; import { AccountHeader } from "./components/AccountHeader"; @@ -54,7 +54,7 @@ export interface AccountDetailsBodyProps { tabParam: TabIndex; } -const getAddressOnPath = (hexAddress: HexAddr, accountAddress: HumanAddr) => +const getAddressOnPath = (hexAddress: HexAddr, accountAddress: BechAddr) => hexAddress === "0x1" ? hexAddress : accountAddress; const InvalidAccount = () => ; @@ -290,7 +290,7 @@ const AccountDetailsBody = ({ borderBottomColor={{ base: "transparent", md: "gray.700" }} > @@ -307,7 +307,7 @@ const AccountDetailsBody = ({ {wasm.enabled && ( <> - + { const contractAddressParam = getFirstQueryParam( router.query.contract - ) as ContractAddr; + ) as BechAddr32; const onContractPathChange = useCallback( - (contract?: ContractAddr) => { + (contract?: BechAddr32) => { navigate({ pathname: "/admin", query: { ...(contract && { contract }) }, @@ -65,13 +65,15 @@ const UpdateAdmin = () => { !!address && !!contractAddressParam && adminFormStatus.state === "success", - messages: [ - composeMsg(MsgType.UPDATE_ADMIN, { - sender: address as HumanAddr, - newAdmin: adminAddress as Addr, - contract: contractAddressParam, - }), - ], + messages: address + ? [ + composeMsg(MsgType.UPDATE_ADMIN, { + sender: address, + newAdmin: adminAddress as BechAddr, + contract: contractAddressParam, + }), + ] + : [], onSuccess: (fee) => { if (fee) { setSimulateError(undefined); @@ -88,7 +90,7 @@ const UpdateAdmin = () => { track(AmpEvent.ACTION_ADMIN_UPDATE); const stream = await updateAdminTx({ contractAddress: contractAddressParam, - newAdmin: adminAddress as Addr, + newAdmin: adminAddress as BechAddr, estimatedFee, }); @@ -105,7 +107,7 @@ const UpdateAdmin = () => { * @remarks Contract admin validation */ useContractDetailByContractAddress( - contractAddressParam as ContractAddr, + contractAddressParam, (contractDetail) => { if (contractDetail.admin !== address) onContractPathChange(); }, diff --git a/src/lib/pages/code-details/components/code-info/table/CodeContractsTable.tsx b/src/lib/pages/code-details/components/code-info/table/CodeContractsTable.tsx index 49177303d..383c8c7f8 100644 --- a/src/lib/pages/code-details/components/code-info/table/CodeContractsTable.tsx +++ b/src/lib/pages/code-details/components/code-info/table/CodeContractsTable.tsx @@ -8,7 +8,7 @@ import { usePaginator } from "lib/components/pagination/usePaginator"; import { ContractsTable, TableTitle } from "lib/components/table"; import { useContractsByCodeId } from "lib/model/contract"; import { useContractListCountByCodeId } from "lib/services/contractService"; -import type { ContractAddr } from "lib/types"; +import type { BechAddr32 } from "lib/types"; import { NoContracts } from "./NoContracts"; @@ -19,7 +19,7 @@ interface CodeContractsTableProps { export const CodeContractsTable = observer( ({ codeId }: CodeContractsTableProps) => { const navigate = useInternalNavigate(); - const onRowSelect = (contract: ContractAddr) => + const onRowSelect = (contract: BechAddr32) => navigate({ pathname: "/contracts/[contract]", query: { contract }, diff --git a/src/lib/pages/contract-details/components/CommandSection.tsx b/src/lib/pages/contract-details/components/CommandSection.tsx index 5c9e9c0de..df6c1491f 100644 --- a/src/lib/pages/contract-details/components/CommandSection.tsx +++ b/src/lib/pages/contract-details/components/CommandSection.tsx @@ -22,18 +22,18 @@ import { Tooltip } from "lib/components/Tooltip"; import { useExecuteCmds } from "lib/hooks"; import { useSchemaStore } from "lib/providers/store"; import { useContractQueryMsgs } from "lib/services/contractService"; -import type { ContractAddr } from "lib/types"; +import type { BechAddr32 } from "lib/types"; import { encode, jsonPrettify } from "lib/utils"; interface RenderCmdsProps { isFetching: boolean; cmds: [string, string][]; - contractAddress: ContractAddr; + contractAddress: BechAddr32; type: string; } interface CommandSectionProps { - contractAddress: ContractAddr; + contractAddress: BechAddr32; codeHash: string; codeId: number; } diff --git a/src/lib/pages/contract-details/components/ContractTop.tsx b/src/lib/pages/contract-details/components/ContractTop.tsx index 6ac4e09a1..18512d618 100644 --- a/src/lib/pages/contract-details/components/ContractTop.tsx +++ b/src/lib/pages/contract-details/components/ContractTop.tsx @@ -21,7 +21,7 @@ import { import type { Contract } from "lib/services/contract"; import type { ContractLocalInfo } from "lib/stores/contract"; import type { - ContractAddr, + BechAddr32, Nullable, Option, ProjectInfo, @@ -30,7 +30,7 @@ import type { import { truncate } from "lib/utils"; interface ContractTopProps { - contractAddress: ContractAddr; + contractAddress: BechAddr32; projectInfo: Nullable; publicInfo: Nullable; @@ -91,7 +91,7 @@ export const ContractTop = ({ return ( {!isMobile && ( )} diff --git a/src/lib/pages/contract-details/components/contract-balances/index.tsx b/src/lib/pages/contract-details/components/contract-balances/index.tsx index dbe28c1fb..13747e5bf 100644 --- a/src/lib/pages/contract-details/components/contract-balances/index.tsx +++ b/src/lib/pages/contract-details/components/contract-balances/index.tsx @@ -3,12 +3,12 @@ import { Flex, Heading } from "@chakra-ui/react"; import { UnsupportedTokensModal } from "lib/components/modal"; import { ErrorFetching } from "lib/components/state/ErrorFetching"; import { useBalanceInfos } from "lib/services/balanceService"; -import type { ContractAddr } from "lib/types"; +import type { BechAddr32 } from "lib/types"; import { SupportedTokensSection } from "./SupportedTokensSection"; interface ContractBalancesProps { - contractAddress: ContractAddr; + contractAddress: BechAddr32; amptrackPage?: string; onViewMore?: () => void; } diff --git a/src/lib/pages/contract-details/components/contract-states/index.tsx b/src/lib/pages/contract-details/components/contract-states/index.tsx index a9098ffb4..c9d1f2664 100644 --- a/src/lib/pages/contract-details/components/contract-states/index.tsx +++ b/src/lib/pages/contract-details/components/contract-states/index.tsx @@ -12,7 +12,7 @@ import { useMemo, useState } from "react"; import { AmpEvent, track, trackContractStatesLoad } from "lib/amplitude"; import InputWithIcon from "lib/components/InputWithIcon"; import { useContractStates } from "lib/services/contractStateService"; -import type { ContractAddr } from "lib/types"; +import type { BechAddr32 } from "lib/types"; import { groupContractStatesByFirstIndex } from "lib/utils"; import { StateList } from "./StateList"; @@ -26,7 +26,7 @@ const getDisplayName = (namespace: string) => { }; interface ContractStatesProps { - contractAddress: ContractAddr; + contractAddress: BechAddr32; } const NUM_STATES_TO_LOAD = 100; diff --git a/src/lib/pages/contract-details/components/tables/RelatedProposalsTable.tsx b/src/lib/pages/contract-details/components/tables/RelatedProposalsTable.tsx index 2541ed62e..3c4895d25 100644 --- a/src/lib/pages/contract-details/components/tables/RelatedProposalsTable.tsx +++ b/src/lib/pages/contract-details/components/tables/RelatedProposalsTable.tsx @@ -5,10 +5,10 @@ import { usePaginator } from "lib/components/pagination/usePaginator"; import { EmptyState, ErrorFetching } from "lib/components/state"; import { ProposalsTable } from "lib/components/table"; import { useRelatedProposalsByContractAddress } from "lib/services/proposalService"; -import type { ContractAddr, Option } from "lib/types"; +import type { BechAddr32, Option } from "lib/types"; interface RelatedProposalsTableProps { - contractAddress: ContractAddr; + contractAddress: BechAddr32; scrollComponentId: string; totalData: Option; refetchCount: () => void; diff --git a/src/lib/pages/contract-details/components/tables/TxsTable.tsx b/src/lib/pages/contract-details/components/tables/TxsTable.tsx index f46c16297..d7dc16340 100644 --- a/src/lib/pages/contract-details/components/tables/TxsTable.tsx +++ b/src/lib/pages/contract-details/components/tables/TxsTable.tsx @@ -4,10 +4,10 @@ import { EmptyState, ErrorFetching } from "lib/components/state"; import { TransactionsTable } from "lib/components/table"; import { DEFAULT_TX_FILTERS } from "lib/data"; import { useTxsByAddress } from "lib/services/txService"; -import type { ContractAddr, Option } from "lib/types"; +import type { BechAddr32, Option } from "lib/types"; interface TxsTableProps { - contractAddress: ContractAddr; + contractAddress: BechAddr32; scrollComponentId: string; totalData: Option; refetchCount: () => void; diff --git a/src/lib/pages/contract-details/components/tables/index.tsx b/src/lib/pages/contract-details/components/tables/index.tsx index d9c8302f0..a7d4be7a7 100644 --- a/src/lib/pages/contract-details/components/tables/index.tsx +++ b/src/lib/pages/contract-details/components/tables/index.tsx @@ -10,14 +10,14 @@ import { import { useGovConfig } from "lib/app-provider"; import { CustomTab } from "lib/components/CustomTab"; import { useContractTableCounts } from "lib/services/contractService"; -import type { ContractAddr } from "lib/types"; +import type { BechAddr32 } from "lib/types"; import { MigrationTable } from "./migration"; import { RelatedProposalsTable } from "./RelatedProposalsTable"; import { TxsTable } from "./TxsTable"; interface ContractTablesProps { - contractAddress: ContractAddr; + contractAddress: BechAddr32; } export const ContractTables = ({ contractAddress }: ContractTablesProps) => { diff --git a/src/lib/pages/contract-details/components/tables/migration/index.tsx b/src/lib/pages/contract-details/components/tables/migration/index.tsx index 1f9d946bd..149b20b5d 100644 --- a/src/lib/pages/contract-details/components/tables/migration/index.tsx +++ b/src/lib/pages/contract-details/components/tables/migration/index.tsx @@ -5,14 +5,14 @@ import { usePaginator } from "lib/components/pagination/usePaginator"; import { EmptyState, ErrorFetching } from "lib/components/state"; import { MobileTableContainer, TableContainer } from "lib/components/table"; import { useMigrationHistories } from "lib/pages/contract-details/data"; -import type { ContractAddr, Option } from "lib/types"; +import type { BechAddr32, Option } from "lib/types"; import { MigrationHeader } from "./MigrationHeader"; import { MigrationMobileCard } from "./MigrationMobileCard"; import { MigrationRow } from "./MigrationRow"; interface MigrationTableProps { - contractAddress: ContractAddr; + contractAddress: BechAddr32; scrollComponentId: string; totalData: Option; refetchCount: () => void; diff --git a/src/lib/pages/contract-details/data.ts b/src/lib/pages/contract-details/data.ts index 2ef987b2d..f7c2965c9 100644 --- a/src/lib/pages/contract-details/data.ts +++ b/src/lib/pages/contract-details/data.ts @@ -3,9 +3,9 @@ import { useContractDataByContractAddress, useMigrationHistoriesByContractAddress, } from "lib/services/contractService"; -import type { ContractAddr, ContractMigrationHistory } from "lib/types"; +import type { BechAddr32, ContractMigrationHistory } from "lib/types"; -export const useContractData = (contractAddress: ContractAddr) => { +export const useContractData = (contractAddress: BechAddr32) => { const { getCodeLocalInfo } = useCodeStore(); const { getContractLocalInfo } = useContractStore(); @@ -24,7 +24,7 @@ export const useContractData = (contractAddress: ContractAddr) => { }; export const useMigrationHistories = ( - contractAddress: ContractAddr, + contractAddress: BechAddr32, offset: number, pageSize: number ) => { diff --git a/src/lib/pages/contract-details/index.tsx b/src/lib/pages/contract-details/index.tsx index a3f817b7e..89ee194c7 100644 --- a/src/lib/pages/contract-details/index.tsx +++ b/src/lib/pages/contract-details/index.tsx @@ -23,7 +23,7 @@ import { CustomIcon } from "lib/components/icon"; import { Loading } from "lib/components/Loading"; import PageContainer from "lib/components/PageContainer"; import { ErrorFetching, InvalidState } from "lib/components/state"; -import type { ContractAddr } from "lib/types"; +import type { BechAddr32 } from "lib/types"; import { jsonPrettify } from "lib/utils"; import { CommandSection } from "./components/CommandSection"; @@ -40,7 +40,7 @@ import { TabIndex, zContractDetailsQueryParams } from "./types"; const InvalidContract = () => ; interface ContractDetailsBodyProps { - contractAddress: ContractAddr; + contractAddress: BechAddr32; tab: TabIndex; } diff --git a/src/lib/pages/contract-details/types.ts b/src/lib/pages/contract-details/types.ts index 5b0be494e..c16229969 100644 --- a/src/lib/pages/contract-details/types.ts +++ b/src/lib/pages/contract-details/types.ts @@ -1,6 +1,6 @@ import { z } from "zod"; -import { zContractAddr } from "lib/types"; +import { zBechAddr32 } from "lib/types"; export enum TabIndex { Overview = "overview", @@ -10,7 +10,7 @@ export enum TabIndex { } export const zContractDetailsQueryParams = z.object({ - contractAddress: zContractAddr, + contractAddress: zBechAddr32, tab: z.union([ z.nativeEnum(TabIndex), z diff --git a/src/lib/pages/contract-list/slug.tsx b/src/lib/pages/contract-list/slug.tsx index 22613a40a..1e05526f7 100644 --- a/src/lib/pages/contract-list/slug.tsx +++ b/src/lib/pages/contract-list/slug.tsx @@ -24,7 +24,7 @@ import { ContractListDetail } from "lib/components/select-contract"; import { INSTANTIATED_LIST_NAME, SAVED_LIST_NAME } from "lib/data"; import { useInstantiatedByMe } from "lib/model/contract"; import { useContractStore } from "lib/providers/store"; -import type { ContractAddr } from "lib/types"; +import type { BechAddr32 } from "lib/types"; import { formatSlugName, getFirstQueryParam } from "lib/utils"; // TODO: revisit again @@ -46,7 +46,7 @@ const ContractsByList = observer(() => { ? instantiatedListInfo : getContractLists().find((item) => item.slug === listSlug); - const onContractSelect = (contract: ContractAddr) => + const onContractSelect = (contract: BechAddr32) => navigate({ pathname: "/contracts/[contract]", query: { contract }, diff --git a/src/lib/pages/contracts/index.tsx b/src/lib/pages/contracts/index.tsx index 3aedf9edb..afb6d7fc7 100644 --- a/src/lib/pages/contracts/index.tsx +++ b/src/lib/pages/contracts/index.tsx @@ -8,7 +8,7 @@ import { useInternalNavigate, useWasmConfig } from "lib/app-provider"; import PageContainer from "lib/components/PageContainer"; import { EmptyState } from "lib/components/state"; import { ContractsTable } from "lib/components/table"; -import type { ContractAddr } from "lib/types"; +import type { BechAddr32 } from "lib/types"; import { useRecentContractsData } from "./data"; @@ -16,7 +16,7 @@ const RecentContracts = observer(() => { useWasmConfig({ shouldRedirect: true }); const router = useRouter(); const navigate = useInternalNavigate(); - const onRowSelect = (contract: ContractAddr) => + const onRowSelect = (contract: BechAddr32) => navigate({ pathname: "/contracts/[contract]", query: { contract }, diff --git a/src/lib/pages/deploy-script/index.tsx b/src/lib/pages/deploy-script/index.tsx index 25cd532ae..8b1c55f94 100644 --- a/src/lib/pages/deploy-script/index.tsx +++ b/src/lib/pages/deploy-script/index.tsx @@ -15,12 +15,7 @@ import { ErrorMessageRender } from "lib/components/ErrorMessageRender"; import { EstimatedFeeRender } from "lib/components/EstimatedFeeRender"; import WasmPageContainer from "lib/components/WasmPageContainer"; import { useTxBroadcast } from "lib/providers/tx-broadcast"; -import type { - ExposedFunction, - HumanAddr, - Option, - AbiFormData, -} from "lib/types"; +import type { AbiFormData, ExposedFunction, Option } from "lib/types"; import { composeScriptMsg, getAbiInitialData } from "lib/utils"; import { Footer } from "./components/Footer"; @@ -90,7 +85,7 @@ export const DeployScript = () => { const { isFetching: isSimulating } = useSimulateFeeQuery({ enabled: enableDeploy, messages: composeScriptMsg( - address as HumanAddr, + address, fileState.base64File, fileState.decodeRes, inputData @@ -113,7 +108,7 @@ export const DeployScript = () => { onTxFailed: () => setProcessing(false), estimatedFee, messages: composeScriptMsg( - address as HumanAddr, + address, fileState.base64File, fileState.decodeRes, inputData diff --git a/src/lib/pages/deploy/index.tsx b/src/lib/pages/deploy/index.tsx index 142ec24e8..2d7de2db2 100644 --- a/src/lib/pages/deploy/index.tsx +++ b/src/lib/pages/deploy/index.tsx @@ -24,7 +24,6 @@ import { Loading } from "lib/components/Loading"; import { Stepper } from "lib/components/stepper"; import WasmPageContainer from "lib/components/WasmPageContainer"; import { useUploadAccessParams } from "lib/services/proposalService"; -import type { HumanAddr } from "lib/types"; import { AccessConfigPermission } from "lib/types"; const getAlertContent = ( @@ -73,7 +72,7 @@ const Deploy = () => { const enableUpload = !isPermissionedNetwork || - Boolean(data?.addresses?.includes(address as HumanAddr)); + Boolean(address && data?.addresses?.includes(address)); useWasmConfig({ shouldRedirect: true }); diff --git a/src/lib/pages/execute/components/ExecuteArea.tsx b/src/lib/pages/execute/components/ExecuteArea.tsx index 4f5066ecd..71330952f 100644 --- a/src/lib/pages/execute/components/ExecuteArea.tsx +++ b/src/lib/pages/execute/components/ExecuteArea.tsx @@ -13,13 +13,13 @@ import { } from "lib/components/json-schema"; import { Tooltip } from "lib/components/Tooltip"; import { useSchemaStore } from "lib/providers/store"; -import type { ContractAddr, Option } from "lib/types"; +import type { BechAddr32, Option } from "lib/types"; import { JsonExecute } from "./JsonExecute"; import { SchemaExecute } from "./schema-execute"; interface ExecuteAreaProps { - contractAddress: ContractAddr; + contractAddress: BechAddr32; initialMsg: string; initialFunds: Coin[]; codeId: Option; diff --git a/src/lib/pages/execute/components/JsonExecute.tsx b/src/lib/pages/execute/components/JsonExecute.tsx index 631286195..800eb7cd1 100644 --- a/src/lib/pages/execute/components/JsonExecute.tsx +++ b/src/lib/pages/execute/components/JsonExecute.tsx @@ -31,14 +31,14 @@ import { useExecuteCmds } from "lib/hooks"; import { useContractStore } from "lib/providers/store"; import { useTxBroadcast } from "lib/providers/tx-broadcast"; import type { Activity } from "lib/stores/contract"; -import type { ComposedMsg, ContractAddr, HumanAddr } from "lib/types"; +import type { BechAddr32, ComposedMsg } from "lib/types"; import { MsgType } from "lib/types"; import { composeMsg, jsonPrettify, jsonValidate } from "lib/utils"; import { MsgSuggestion } from "./MsgSuggestion"; interface JsonExecuteProps { - contractAddress: ContractAddr; + contractAddress: BechAddr32; initialMsg: string; initialFunds: Coin[]; } @@ -132,9 +132,8 @@ export const JsonExecute = ({ // ------------------------------------------// // -----------------REACT QUERY--------------// // ------------------------------------------// - const { isFetching: cmdsFetching, execCmds } = useExecuteCmds( - contractAddress as ContractAddr - ); + const { isFetching: cmdsFetching, execCmds } = + useExecuteCmds(contractAddress); const { isFetching } = useSimulateFeeQuery({ enabled: composedTxMsg.length > 0, messages: composedTxMsg, @@ -210,15 +209,19 @@ export const JsonExecute = ({ useEffect(() => { if (enableExecute) { - const composedMsg = composeMsg(MsgType.EXECUTE, { - sender: address as HumanAddr, - contract: contractAddress as ContractAddr, - msg: Buffer.from(msg), - funds, - }); + const composedMsg = address + ? [ + composeMsg(MsgType.EXECUTE, { + sender: address, + contract: contractAddress, + msg: Buffer.from(msg), + funds, + }), + ] + : []; const timeoutId = setTimeout(() => { - setComposedTxMsg([composedMsg]); + setComposedTxMsg(composedMsg); }, 1000); return () => clearTimeout(timeoutId); } diff --git a/src/lib/pages/execute/components/MsgSuggestion.tsx b/src/lib/pages/execute/components/MsgSuggestion.tsx index feedc98de..dfc7a71f7 100644 --- a/src/lib/pages/execute/components/MsgSuggestion.tsx +++ b/src/lib/pages/execute/components/MsgSuggestion.tsx @@ -2,11 +2,11 @@ import { Box, Text, ButtonGroup } from "@chakra-ui/react"; import { AmpEvent, track } from "lib/amplitude"; import { ContractCmdButton } from "lib/components/ContractCmdButton"; -import type { ContractAddr } from "lib/types"; +import type { BechAddr32 } from "lib/types"; import { jsonPrettify } from "lib/utils"; interface MsgSuggestionProps { - contractAddress: ContractAddr; + contractAddress: BechAddr32; cmds: [string, string][]; setMsg: (msg: string) => void; } diff --git a/src/lib/pages/execute/components/schema-execute/ExecuteBox.tsx b/src/lib/pages/execute/components/schema-execute/ExecuteBox.tsx index 55032f842..0d2943db3 100644 --- a/src/lib/pages/execute/components/schema-execute/ExecuteBox.tsx +++ b/src/lib/pages/execute/components/schema-execute/ExecuteBox.tsx @@ -43,12 +43,7 @@ import { useContractStore } from "lib/providers/store"; import { useTxBroadcast } from "lib/providers/tx-broadcast"; import type { Activity } from "lib/stores/contract"; import type { SchemaInfo } from "lib/stores/schema"; -import type { - ComposedMsg, - ContractAddr, - HumanAddr, - JsonDataType, -} from "lib/types"; +import type { BechAddr32, ComposedMsg, JsonDataType } from "lib/types"; import { MsgType } from "lib/types"; import { composeMsg, @@ -67,7 +62,7 @@ const WasmCodeSnippet = dynamic( interface ExecuteBoxProps { msgSchema: SchemaInfo; - contractAddress: ContractAddr; + contractAddress: BechAddr32; initialMsg: JsonDataType; initialFunds: Coin[]; opened: boolean; @@ -255,15 +250,19 @@ export const ExecuteBox = ({ useEffect(() => { if (enableExecute) { - const composedMsg = composeMsg(MsgType.EXECUTE, { - sender: address as HumanAddr, - contract: contractAddress as ContractAddr, - msg: Buffer.from(msg), - funds, - }); + const composedMsg = address + ? [ + composeMsg(MsgType.EXECUTE, { + sender: address, + contract: contractAddress, + msg: Buffer.from(msg), + funds, + }), + ] + : []; const timeoutId = setTimeout(() => { - setComposedTxMsg([composedMsg]); + setComposedTxMsg(composedMsg); }, 1000); return () => clearTimeout(timeoutId); } diff --git a/src/lib/pages/execute/components/schema-execute/index.tsx b/src/lib/pages/execute/components/schema-execute/index.tsx index 64edf3665..4d51731cd 100644 --- a/src/lib/pages/execute/components/schema-execute/index.tsx +++ b/src/lib/pages/execute/components/schema-execute/index.tsx @@ -9,14 +9,14 @@ import { UploadSchema } from "lib/components/json-schema"; import { EmptyState, StateImage } from "lib/components/state"; import { useSchemaStore } from "lib/providers/store"; import type { ExecuteSchema } from "lib/stores/schema"; -import type { ContractAddr, Option } from "lib/types"; +import type { BechAddr32, Option } from "lib/types"; import { getDefaultMsg, resolveInitialMsg } from "lib/utils"; import { ExecuteBox } from "./ExecuteBox"; interface SchemaExecuteProps { schema: Option; - contractAddress: ContractAddr; + contractAddress: BechAddr32; initialMsg: string; initialFunds: Coin[]; codeId: number; diff --git a/src/lib/pages/execute/index.tsx b/src/lib/pages/execute/index.tsx index d34c1e45c..2b7b5cb16 100644 --- a/src/lib/pages/execute/index.tsx +++ b/src/lib/pages/execute/index.tsx @@ -10,7 +10,7 @@ import { ContractSelectSection } from "lib/components/ContractSelectSection"; import { CustomIcon } from "lib/components/icon"; import PageContainer from "lib/components/PageContainer"; import type { ContractDetail } from "lib/services/contractService"; -import type { ContractAddr } from "lib/types"; +import type { BechAddr32 } from "lib/types"; import { getFirstQueryParam, jsonPrettify, @@ -33,7 +33,7 @@ const Execute = () => { // ------------------STATES------------------// // ------------------------------------------// const [initialMsg, setInitialMsg] = useState(""); - const [contractAddress, setContractAddress] = useState("" as ContractAddr); + const [contractAddress, setContractAddress] = useState("" as BechAddr32); const [initialFunds, setInitialFunds] = useState([]); const [codeHash, setCodeHash] = useState(""); const [codeId, setCodeId] = useState(); @@ -51,7 +51,7 @@ const Execute = () => { }; const onContractSelect = useCallback( - (contract: ContractAddr) => { + (contract: BechAddr32) => { navigate({ pathname: "/execute", query: { ...(contract && { contract }) }, @@ -68,7 +68,7 @@ const Execute = () => { if (router.isReady) { const contractAddressParam = getFirstQueryParam( router.query.contract - ) as ContractAddr; + ) as BechAddr32; const msgParam = getFirstQueryParam(router.query.msg); if (!msgParam.length) { setInitialMsg(""); diff --git a/src/lib/pages/instantiate/completed.tsx b/src/lib/pages/instantiate/completed.tsx index af40e9189..6b656f63e 100644 --- a/src/lib/pages/instantiate/completed.tsx +++ b/src/lib/pages/instantiate/completed.tsx @@ -6,7 +6,7 @@ import { ExplorerLink } from "lib/components/ExplorerLink"; import { CustomIcon } from "lib/components/icon"; import { TxReceiptRender } from "lib/components/tx"; import WasmPageContainer from "lib/components/WasmPageContainer"; -import type { ContractAddr } from "lib/types"; +import type { BechAddr32 } from "lib/types"; import { feeFromStr } from "lib/utils"; import type { InstantiateTxInfo } from "."; @@ -100,8 +100,9 @@ const Completed = ({ txInfo }: CompletedProps) => { ); diff --git a/src/lib/pages/instantiate/component/InstantiateOffchainForm.tsx b/src/lib/pages/instantiate/component/InstantiateOffchainForm.tsx index 07aaea5f9..174b00376 100644 --- a/src/lib/pages/instantiate/component/InstantiateOffchainForm.tsx +++ b/src/lib/pages/instantiate/component/InstantiateOffchainForm.tsx @@ -3,21 +3,22 @@ import { observer } from "mobx-react-lite"; import { useForm } from "react-hook-form"; import { AmpEvent, track } from "lib/amplitude"; -import { useCurrentChain, useInternalNavigate } from "lib/app-provider"; +import { useInternalNavigate } from "lib/app-provider"; import { OffChainForm } from "lib/components/OffChainForm"; import type { OffchainDetail } from "lib/components/OffChainForm"; import { INSTANTIATED_LIST_NAME } from "lib/data"; import { useUserKey } from "lib/hooks"; import { useContractStore } from "lib/providers/store"; -import type { ContractAddr, HumanAddr, LVPair } from "lib/types"; +import type { BechAddr20, BechAddr32, LVPair } from "lib/types"; import { formatSlugName } from "lib/utils"; interface InstantiateOffChainFormProps { title?: string; subtitle?: string; cta?: boolean; - contractAddress: ContractAddr; + contractAddress: BechAddr32; contractLabel: string; + instantiator: BechAddr20; } export const InstantiateOffChainForm = observer( @@ -27,8 +28,8 @@ export const InstantiateOffChainForm = observer( cta = true, contractAddress, contractLabel, + instantiator, }: InstantiateOffChainFormProps) => { - const { address = "" } = useCurrentChain(); const navigate = useInternalNavigate(); const { updateContractLocalInfo } = useContractStore(); const userKey = useUserKey(); @@ -69,7 +70,7 @@ export const InstantiateOffChainForm = observer( updateContractLocalInfo( userKey, contractAddress, - address as HumanAddr, + instantiator, contractLabel, data.name, data.description, diff --git a/src/lib/pages/instantiate/index.tsx b/src/lib/pages/instantiate/index.tsx index 749b7a6cf..138b0918e 100644 --- a/src/lib/pages/instantiate/index.tsx +++ b/src/lib/pages/instantiate/index.tsx @@ -2,6 +2,7 @@ import type { InstantiateResult } from "@cosmjs/cosmwasm-stargate"; import { useEffect, useState } from "react"; import { useWasmConfig } from "lib/app-provider"; +import type { BechAddr20 } from "lib/types"; import { scrollToTop } from "lib/utils"; import CompletedPage from "./completed"; @@ -9,6 +10,7 @@ import InstantiatePage from "./instantiate"; export interface InstantiateTxInfo extends InstantiateResult { contractLabel: string; + instantiator: BechAddr20; } const Index = () => { @@ -23,6 +25,7 @@ const Index = () => { gasWanted: 0, gasUsed: 0, contractLabel: "", + instantiator: "" as BechAddr20, }); useEffect(() => { @@ -33,8 +36,12 @@ const Index = () => { ) : ( { - setTxInfo({ ...txResult, contractLabel }); + onComplete={( + txResult: InstantiateResult, + contractLabel: string, + instantiator: BechAddr20 + ) => { + setTxInfo({ ...txResult, contractLabel, instantiator }); setCompleted(true); }} /> diff --git a/src/lib/pages/instantiate/instantiate.tsx b/src/lib/pages/instantiate/instantiate.tsx index d0e85ef48..b95be4d34 100644 --- a/src/lib/pages/instantiate/instantiate.tsx +++ b/src/lib/pages/instantiate/instantiate.tsx @@ -48,7 +48,7 @@ import { useSchemaStore } from "lib/providers/store"; import { useTxBroadcast } from "lib/providers/tx-broadcast"; import type { CodeIdInfoResponse } from "lib/services/code"; import { useLCDCodeInfo } from "lib/services/codeService"; -import type { ComposedMsg, HumanAddr } from "lib/types"; +import type { BechAddr, BechAddr20, ComposedMsg } from "lib/types"; import { MsgType } from "lib/types"; import { composeMsg, @@ -74,7 +74,11 @@ interface InstantiatePageState { simulateError: string; } interface InstantiatePageProps { - onComplete: (txResult: InstantiateResult, contractLabel: string) => void; + onComplete: ( + txResult: InstantiateResult, + contractLabel: string, + instantiator: BechAddr20 + ) => void; } const Instantiate = ({ onComplete }: InstantiatePageProps) => { @@ -85,7 +89,7 @@ const Instantiate = ({ onComplete }: InstantiatePageProps) => { const msgQuery = (router.query.msg as string) ?? ""; const codeIdQuery = (router.query["code-id"] as string) ?? ""; const { user: exampleUserAddress } = useExampleAddresses(); - const { address = "" } = useCurrentChain(); + const { address } = useCurrentChain(); const postInstantiateTx = useInstantiateTx(); const fabricateFee = useFabricateFee(); const { broadcast } = useTxBroadcast(); @@ -197,7 +201,7 @@ const Instantiate = ({ onComplete }: InstantiatePageProps) => { setValue("codeHash", data.code_info.data_hash.toLowerCase()); if ( resolvePermission( - address as HumanAddr, + address, permission.permission, permission.addresses, permission.address @@ -257,7 +261,7 @@ const Instantiate = ({ onComplete }: InstantiatePageProps) => { estimatedFee, onTxSucceed: (txResult, contractLabel) => { setProcessing(false); - onComplete(txResult, contractLabel); + onComplete(txResult, contractLabel, address ?? ("" as BechAddr20)); }, onTxFailed: () => setProcessing(false), }); @@ -267,17 +271,18 @@ const Instantiate = ({ onComplete }: InstantiatePageProps) => { broadcast(stream); } }, [ - funds, - tab, + address, + adminAddress, attachFundsOption, - postInstantiateTx, + broadcast, codeId, currentInput, - label, - adminAddress, estimatedFee, + funds, + label, onComplete, - broadcast, + postInstantiateTx, + tab, ]); // ------------------------------------------// @@ -334,16 +339,20 @@ const Instantiate = ({ onComplete }: InstantiatePageProps) => { useEffect(() => { if (enableInstantiate) { setSimulateError(""); - const composedMsg = composeMsg(MsgType.INSTANTIATE, { - sender: address as HumanAddr, - admin: adminAddress as HumanAddr, - codeId: Long.fromString(codeId), - label, - msg: Buffer.from(currentInput), - funds, - }); + const composedMsg = address + ? [ + composeMsg(MsgType.INSTANTIATE, { + sender: address, + admin: adminAddress as BechAddr, + codeId: Long.fromString(codeId), + label, + msg: Buffer.from(currentInput), + funds, + }), + ] + : []; const timeoutId = setTimeout(() => { - setComposedTxMsg([composedMsg]); + setComposedTxMsg(composedMsg); }, 1000); return () => clearTimeout(timeoutId); } @@ -434,7 +443,7 @@ const Instantiate = ({ onComplete }: InstantiatePageProps) => { { track(AmpEvent.USE_ASSIGN_ME); - setValue("adminAddress", address); + setValue("adminAddress", address ?? ""); }} isDisable={adminAddress === address} /> diff --git a/src/lib/pages/interact/component/FunctionSelectBody.tsx b/src/lib/pages/interact/component/FunctionSelectBody.tsx index c0e07e8b8..07ab99d05 100644 --- a/src/lib/pages/interact/component/FunctionSelectBody.tsx +++ b/src/lib/pages/interact/component/FunctionSelectBody.tsx @@ -3,7 +3,7 @@ import { Button, Flex } from "@chakra-ui/react"; import { CustomIcon } from "lib/components/icon"; import { EmptyState } from "lib/components/state"; import type { IndexedModule } from "lib/services/move/moduleService"; -import type { ExposedFunction, HexAddr, Option } from "lib/types"; +import type { ExposedFunction, Option } from "lib/types"; import { ModuleContainer } from "./common"; import { ExecuteArea, ViewArea } from "./form"; @@ -30,13 +30,13 @@ export const FunctionSelectBody = ({ {selectedFn.is_view ? ( ) : ( diff --git a/src/lib/pages/interact/component/drawer/ModuleSelectDrawer.tsx b/src/lib/pages/interact/component/drawer/ModuleSelectDrawer.tsx index a0a0b43ac..a960492d6 100644 --- a/src/lib/pages/interact/component/drawer/ModuleSelectDrawer.tsx +++ b/src/lib/pages/interact/component/drawer/ModuleSelectDrawer.tsx @@ -17,7 +17,7 @@ import { useAccountModules, type IndexedModule, } from "lib/services/move/moduleService"; -import type { HexAddr, HumanAddr, MoveAccountAddr, Option } from "lib/types"; +import type { BechAddr, HexAddr, Option } from "lib/types"; import { isHexWalletAddress } from "lib/utils"; import { ModuleSelectMainBody } from "./body"; @@ -46,13 +46,13 @@ export const ModuleSelectDrawer = ({ const [mode, setMode] = useState("input"); const [selectedAddress, setSelectedAddress] = useState({ - address: "" as HumanAddr, + address: "" as BechAddr, hex: "" as HexAddr, }); const [modules, setModules] = useState(); const { refetch } = useAccountModules({ - address: selectedAddress.hex as MoveAccountAddr, + address: selectedAddress.hex, moduleName: undefined, functionName: undefined, options: { @@ -77,7 +77,7 @@ export const ModuleSelectDrawer = ({ } else { setMode("input"); setSelectedAddress({ - address: "" as HumanAddr, + address: "" as BechAddr, hex: "" as HexAddr, }); setModules(undefined); diff --git a/src/lib/pages/interact/component/drawer/selector/ModuleSelectorInput.tsx b/src/lib/pages/interact/component/drawer/selector/ModuleSelectorInput.tsx index 6d062a7a0..071815791 100644 --- a/src/lib/pages/interact/component/drawer/selector/ModuleSelectorInput.tsx +++ b/src/lib/pages/interact/component/drawer/selector/ModuleSelectorInput.tsx @@ -14,7 +14,7 @@ import { useFormatAddresses } from "lib/hooks/useFormatAddresses"; import { useValidateModuleInput } from "lib/pages/interact/hooks/useValidateModuleInput"; import type { IndexedModule } from "lib/services/move/moduleService"; import { useAccountModules } from "lib/services/move/moduleService"; -import type { MoveAccountAddr, Option } from "lib/types"; +import type { Option } from "lib/types"; import { splitModule } from "lib/utils"; export interface ModuleSelectorInputProps { @@ -45,7 +45,7 @@ export const ModuleSelectorInput = ({ const validateModuleInput = useValidateModuleInput(); const { user } = useExampleAddresses(); const { refetch, isFetching } = useAccountModules({ - address: addr as MoveAccountAddr, + address: addr, moduleName, functionName, options: { diff --git a/src/lib/pages/interact/component/drawer/selector/index.tsx b/src/lib/pages/interact/component/drawer/selector/index.tsx index 5a3184ea2..9eec40fb2 100644 --- a/src/lib/pages/interact/component/drawer/selector/index.tsx +++ b/src/lib/pages/interact/component/drawer/selector/index.tsx @@ -25,12 +25,12 @@ export const ModuleSelector = ({ /> ) : ( ); }; diff --git a/src/lib/pages/interact/component/drawer/types.ts b/src/lib/pages/interact/component/drawer/types.ts index adc7205f6..7bd6b48c7 100644 --- a/src/lib/pages/interact/component/drawer/types.ts +++ b/src/lib/pages/interact/component/drawer/types.ts @@ -1,8 +1,8 @@ import type { IndexedModule } from "lib/services/move/moduleService"; -import type { HumanAddr, HexAddr, ExposedFunction } from "lib/types"; +import type { BechAddr, HexAddr, ExposedFunction } from "lib/types"; export interface SelectedAddress { - address: HumanAddr; + address: BechAddr; hex: HexAddr; } diff --git a/src/lib/pages/interact/index.tsx b/src/lib/pages/interact/index.tsx index 0810b1261..3d289a7da 100644 --- a/src/lib/pages/interact/index.tsx +++ b/src/lib/pages/interact/index.tsx @@ -22,12 +22,7 @@ import { useAccountModules, useVerifyModule, } from "lib/services/move/moduleService"; -import type { - ExposedFunction, - HexAddr, - MoveAccountAddr, - Option, -} from "lib/types"; +import type { Addr, ExposedFunction } from "lib/types"; import { getFirstQueryParam } from "lib/utils"; import { @@ -92,7 +87,7 @@ export const Interact = () => { ); const { data: verificationData } = useVerifyModule({ - address: module?.address as Option, + address: module?.address, moduleName: module?.moduleName, }); @@ -101,7 +96,7 @@ export const Interact = () => { const functionNameParam = getFirstQueryParam(router.query.functionName); const functionTypeParam = getFirstQueryParam(router.query.functionType); const { refetch } = useAccountModules({ - address: addressParam as MoveAccountAddr, + address: addressParam as Addr, moduleName: moduleNameParam, functionName: functionNameParam, options: { diff --git a/src/lib/pages/migrate/components/MigrateContract.tsx b/src/lib/pages/migrate/components/MigrateContract.tsx index e9cca8814..a98fdf7b8 100644 --- a/src/lib/pages/migrate/components/MigrateContract.tsx +++ b/src/lib/pages/migrate/components/MigrateContract.tsx @@ -29,12 +29,12 @@ import { useSchemaStore } from "lib/providers/store"; import { useTxBroadcast } from "lib/providers/tx-broadcast"; import type { CodeIdInfoResponse } from "lib/services/code"; import { useLCDCodeInfo } from "lib/services/codeService"; -import type { ComposedMsg, ContractAddr, HumanAddr } from "lib/types"; +import type { BechAddr32, ComposedMsg } from "lib/types"; import { MsgType } from "lib/types"; import { composeMsg, isId, jsonValidate, resolvePermission } from "lib/utils"; interface MigrateContractProps { - contractAddress: ContractAddr; + contractAddress: BechAddr32; codeIdParam: string; handleBack: () => void; } @@ -129,7 +129,7 @@ export const MigrateContract = ({ setValue("codeHash", data.code_info.data_hash.toLowerCase()); if ( resolvePermission( - address as HumanAddr, + address, permission.permission, permission.addresses, permission.address @@ -216,14 +216,18 @@ export const MigrateContract = ({ useEffect(() => { if (enableMigrate) { setSimulateError(""); - const composedMsg = composeMsg(MsgType.MIGRATE, { - sender: address as HumanAddr, - contract: contractAddress as ContractAddr, - codeId: Long.fromString(codeId), - msg: Buffer.from(currentInput), - }); + const composedMsg = address + ? [ + composeMsg(MsgType.MIGRATE, { + sender: address, + contract: contractAddress, + codeId: Long.fromString(codeId), + msg: Buffer.from(currentInput), + }), + ] + : []; const timeoutId = setTimeout(() => { - setComposedTxMsg([composedMsg]); + setComposedTxMsg(composedMsg); }, 1000); return () => clearTimeout(timeoutId); } diff --git a/src/lib/pages/migrate/components/MigrateOptions.tsx b/src/lib/pages/migrate/components/MigrateOptions.tsx index f7e972088..a5572a5c3 100644 --- a/src/lib/pages/migrate/components/MigrateOptions.tsx +++ b/src/lib/pages/migrate/components/MigrateOptions.tsx @@ -4,7 +4,7 @@ import { useCelatoneApp, useCurrentChain } from "lib/app-provider"; import { ButtonCard } from "lib/components/ButtonCard"; import { CustomIcon } from "lib/components/icon"; import type { UploadAccess } from "lib/services/proposal"; -import type { HumanAddr, Option } from "lib/types"; +import type { Option } from "lib/types"; import { AccessConfigPermission } from "lib/types"; import { resolvePermission } from "lib/utils"; @@ -28,7 +28,7 @@ export const MigrateOptions = ({ const isPermissionedNetwork = uploadAccess?.permission !== AccessConfigPermission.EVERYBODY; const isAllowed = resolvePermission( - address as HumanAddr, + address, uploadAccess?.permission, uploadAccess?.addresses ); diff --git a/src/lib/pages/migrate/index.tsx b/src/lib/pages/migrate/index.tsx index 10e481a02..34eac4aa5 100644 --- a/src/lib/pages/migrate/index.tsx +++ b/src/lib/pages/migrate/index.tsx @@ -16,7 +16,7 @@ import { Stepper } from "lib/components/stepper"; import WasmPageContainer from "lib/components/WasmPageContainer"; import { useContractDetailByContractAddress } from "lib/services/contractService"; import { useUploadAccessParams } from "lib/services/proposalService"; -import type { ContractAddr } from "lib/types"; +import type { BechAddr32 } from "lib/types"; import { getFirstQueryParam } from "lib/utils"; import { MigrateContract } from "./components/MigrateContract"; @@ -26,7 +26,7 @@ import type { MigratePageState } from "./types"; const defaultValues: MigratePageState = { migrateStep: "migrate_options", - contractAddress: "" as ContractAddr, + contractAddress: "" as BechAddr32, admin: undefined, codeId: "", }; @@ -51,11 +51,11 @@ const Migrate = () => { const contractAddressParam = getFirstQueryParam( router.query.contract - ) as ContractAddr; + ) as BechAddr32; const codeIdParam = getFirstQueryParam(router.query["code-id"]); const onContractSelect = useCallback( - (contract: ContractAddr) => { + (contract: BechAddr32) => { navigate({ pathname: "/migrate", query: { diff --git a/src/lib/pages/migrate/types.ts b/src/lib/pages/migrate/types.ts index b946b4d9d..5675531f8 100644 --- a/src/lib/pages/migrate/types.ts +++ b/src/lib/pages/migrate/types.ts @@ -1,10 +1,10 @@ -import type { Addr, ContractAddr, Option } from "lib/types"; +import type { BechAddr, BechAddr32, Option } from "lib/types"; type MigrateStep = "migrate_options" | "upload_new_code" | "migrate_contract"; export interface MigratePageState { migrateStep: MigrateStep; - contractAddress: ContractAddr; - admin: Option; + contractAddress: BechAddr32; + admin: Option; codeId: string; } diff --git a/src/lib/pages/module-details/index.tsx b/src/lib/pages/module-details/index.tsx index 24b648479..97aebbd8c 100644 --- a/src/lib/pages/module-details/index.tsx +++ b/src/lib/pages/module-details/index.tsx @@ -19,7 +19,7 @@ import { } from "lib/services/move/moduleService"; import { useRelatedProposalsCountByModuleId } from "lib/services/proposalService"; import { useModuleTxsCount } from "lib/services/txService"; -import type { MoveAccountAddr } from "lib/types"; +import type { Addr } from "lib/types"; import { getFirstQueryParam } from "lib/utils"; import { @@ -262,7 +262,7 @@ export const ModuleDetails = () => { const moduleName = getFirstQueryParam(router.query.moduleName); const { data, isLoading } = useAccountModules({ - address: addr as MoveAccountAddr, + address: addr as Addr, moduleName, }); diff --git a/src/lib/pages/my-published-modules/components/MyPublishedModulesTable.tsx b/src/lib/pages/my-published-modules/components/MyPublishedModulesTable.tsx index 6ec2515bc..8cff3eeb6 100644 --- a/src/lib/pages/my-published-modules/components/MyPublishedModulesTable.tsx +++ b/src/lib/pages/my-published-modules/components/MyPublishedModulesTable.tsx @@ -10,7 +10,6 @@ import { import { ModulesTable } from "lib/components/table"; import { useFormatAddresses } from "lib/hooks/useFormatAddresses"; import { useModulesByAddress } from "lib/services/move/moduleService"; -import type { HumanAddr } from "lib/types"; export const MyPublishedModulesTable = () => { const [keyword, setKeyword] = useState(""); @@ -20,7 +19,7 @@ export const MyPublishedModulesTable = () => { data: modulesData, isFetching: isModulesLoading, error, - } = useModulesByAddress(address as HumanAddr); + } = useModulesByAddress(address); const formatAddresses = useFormatAddresses(); const mappedModules = modulesData?.map((module) => { diff --git a/src/lib/pages/past-txs/index.tsx b/src/lib/pages/past-txs/index.tsx index 38221556b..cacac2546 100644 --- a/src/lib/pages/past-txs/index.tsx +++ b/src/lib/pages/past-txs/index.tsx @@ -16,7 +16,7 @@ import { TxFilterSelection } from "lib/components/TxFilterSelection"; import { TxRelationSelection } from "lib/components/TxRelationSelection"; import { DEFAULT_TX_FILTERS } from "lib/data"; import { useTxsCountByAddress, useTxsByAddress } from "lib/services/txService"; -import type { HumanAddr, Option, TxFilters } from "lib/types"; +import type { Option, TxFilters } from "lib/types"; interface PastTxsState { search: string; @@ -45,7 +45,7 @@ const PastTxs = () => { const pastTxsState = watch(); const { data: rawTxCount, refetch: refetchCount } = useTxsCountByAddress( - address as HumanAddr, + address, pastTxsState.search, pastTxsState.isSigner, pastTxsState.filters @@ -69,7 +69,7 @@ const PastTxs = () => { }); const { data: txs, isLoading } = useTxsByAddress( - address as HumanAddr, + address, pastTxsState.search, pastTxsState.isSigner, pastTxsState.filters, diff --git a/src/lib/pages/proposal/store-code/index.tsx b/src/lib/pages/proposal/store-code/index.tsx index 2b36614a1..74da41a73 100644 --- a/src/lib/pages/proposal/store-code/index.tsx +++ b/src/lib/pages/proposal/store-code/index.tsx @@ -56,12 +56,7 @@ import { UploadCard } from "lib/components/upload/UploadCard"; import { useGetMaxLengthError } from "lib/hooks"; import { useTxBroadcast } from "lib/providers/tx-broadcast"; import { useGovParams } from "lib/services/proposalService"; -import type { - Addr, - HumanAddr, - SimulateStatus, - UploadSectionState, -} from "lib/types"; +import type { BechAddr, SimulateStatus, UploadSectionState } from "lib/types"; import { AccessType, AccessConfigPermission } from "lib/types"; import { composeStoreCodeProposalMsg, @@ -72,7 +67,7 @@ import { interface StoreCodeProposalState { title: string; proposalDesc: string; - runAs: Addr; + runAs: BechAddr; initialDeposit: Coin; unpinCode: boolean; builder: string; @@ -83,7 +78,7 @@ interface StoreCodeProposalState { const defaultValues: StoreCodeProposalState = { title: "", proposalDesc: "", - runAs: "" as Addr, + runAs: "" as BechAddr, initialDeposit: { denom: "", amount: "" } as Coin, unpinCode: false, builder: "", @@ -99,7 +94,7 @@ const StoreCodeProposal = () => { } = useCelatoneApp(); const { user: exampleUserAddress } = useExampleAddresses(); const getMaxLengthError = useGetMaxLengthError(); - const { address: walletAddress = "" } = useCurrentChain(); + const { address: walletAddress } = useCurrentChain(); const fabricateFee = useFabricateFee(); const { data: govParams } = useGovParams(); const minDeposit = govParams?.depositParams.minDeposit; @@ -138,7 +133,7 @@ const StoreCodeProposal = () => { wasmFile: undefined, codeName: "", permission: AccessType.ACCESS_TYPE_EVERYBODY, - addresses: [{ address: "" as Addr }], + addresses: [{ address: "" as BechAddr }], }, mode: "all", }); @@ -286,28 +281,32 @@ const StoreCodeProposal = () => { }); const submitStoreCodeProposalMsg = async () => { - return composeStoreCodeProposalMsg({ - proposer: walletAddress as HumanAddr, - title, - description: proposalDesc, - runAs: runAs as Addr, - wasmByteCode: await gzip(new Uint8Array(await wasmFile.arrayBuffer())), - permission, - addresses: addresses.map((addr) => addr.address), - unpinCode, - source, - builder, - codeHash: Uint8Array.from(Buffer.from(codeHash, "hex")), - initialDeposit, - precision: minDeposit?.precision, - }); + if (!walletAddress) return []; + return [ + composeStoreCodeProposalMsg({ + proposer: walletAddress, + title, + description: proposalDesc, + runAs, + wasmByteCode: await gzip( + new Uint8Array(await wasmFile.arrayBuffer()) + ), + permission, + addresses: addresses.map((addr) => addr.address), + unpinCode, + source, + builder, + codeHash: Uint8Array.from(Buffer.from(codeHash, "hex")), + initialDeposit, + precision: minDeposit?.precision, + }), + ]; }; - const craftMsg = await submitStoreCodeProposalMsg(); const stream = await submitStoreCodeProposalTx({ estimatedFee, - messages: [craftMsg], + messages: craftMsg, wasmFileName: wasmFile.name, amountToVote: getAmountToVote(initialDeposit, minDeposit), onTxSucceed: () => setProcessing(false), @@ -414,7 +413,7 @@ const StoreCodeProposal = () => { walletAddress ? () => { track(AmpEvent.USE_ASSIGN_ME); - setValue("runAs", walletAddress as HumanAddr); + setValue("runAs", walletAddress); trigger("runAs"); } : undefined diff --git a/src/lib/pages/proposal/whitelist/index.tsx b/src/lib/pages/proposal/whitelist/index.tsx index c7d810aa1..7ac22b6ea 100644 --- a/src/lib/pages/proposal/whitelist/index.tsx +++ b/src/lib/pages/proposal/whitelist/index.tsx @@ -45,21 +45,21 @@ import { StickySidebar } from "lib/components/StickySidebar"; import { useGetMaxLengthError } from "lib/hooks"; import { useTxBroadcast } from "lib/providers/tx-broadcast"; import { useGovParams } from "lib/services/proposalService"; +import type { BechAddr } from "lib/types"; import { AccessConfigPermission } from "lib/types"; -import type { Addr } from "lib/types"; import { composeSubmitWhitelistProposalMsg, getAmountToVote } from "lib/utils"; interface WhiteListState { title: string; description: string; - addresses: { address: Addr }[]; + addresses: { address: BechAddr }[]; initialDeposit: Coin; } const defaultValues: WhiteListState = { title: "", description: "", - addresses: [{ address: "" as Addr }], + addresses: [{ address: "" as BechAddr }], initialDeposit: { denom: "", amount: "" } as Coin, }; @@ -68,7 +68,7 @@ const ProposalToWhitelist = () => { const router = useRouter(); const { constants } = useCelatoneApp(); const getMaxLengthError = useGetMaxLengthError(); - const { address: walletAddress = "" } = useCurrentChain(); + const { address: walletAddress } = useCurrentChain(); const { chainConfig: { prettyName }, } = useCelatoneApp(); @@ -122,8 +122,9 @@ const ProposalToWhitelist = () => { ] ); - const submitWhitelistProposalMsg = useMemo( - () => + const submitWhitelistProposalMsg = useMemo(() => { + if (!walletAddress) return []; + return [ composeSubmitWhitelistProposalMsg({ title, description, @@ -135,24 +136,24 @@ const ProposalToWhitelist = () => { addresses: govParams?.uploadAccess.addresses?.concat(addressesArray), }), initialDeposit, - proposer: walletAddress as Addr, + proposer: walletAddress, precision: minDeposit?.precision, }), - [ - addressesArray, - description, - govParams?.uploadAccess, - initialDeposit, - minDeposit, - title, - walletAddress, - isPermissionless, - ] - ); + ]; + }, [ + addressesArray, + description, + govParams?.uploadAccess, + initialDeposit, + minDeposit, + title, + walletAddress, + isPermissionless, + ]); const { isFetching: isSimulating } = useSimulateFeeQuery({ enabled: enabledTx, - messages: [submitWhitelistProposalMsg], + messages: submitWhitelistProposalMsg, onSuccess: (fee) => { if (fee) { setSimulateError(undefined); @@ -179,7 +180,7 @@ const ProposalToWhitelist = () => { const proceed = useCallback(async () => { const stream = await submitProposalTx({ estimatedFee, - messages: [submitWhitelistProposalMsg], + messages: submitWhitelistProposalMsg, whitelistNumber: addressesArray.length, amountToVote: getAmountToVote(initialDeposit, minDeposit), @@ -348,7 +349,7 @@ const ProposalToWhitelist = () => { track(AmpEvent.USE_ASSIGN_ME); setValue( `addresses.${idx}.address`, - walletAddress as Addr + walletAddress ?? ("" as BechAddr) ); trigger(`addresses.${idx}.address`); }} @@ -376,7 +377,7 @@ const ProposalToWhitelist = () => {