Skip to content

Commit

Permalink
fix: evm contract address example
Browse files Browse the repository at this point in the history
  • Loading branch information
evilpeach committed Jan 16, 2025
1 parent 46414a2 commit 80e034e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 17 deletions.
23 changes: 10 additions & 13 deletions src/lib/app-provider/hooks/useExampleAddresses.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
import { toBech32 } from "@cosmjs/encoding";
import { toBech32, toHex } from "@cosmjs/encoding";
import { useMemo } from "react";

import type { BechAddr20, BechAddr32 } from "lib/types";
import { addrToValoper, bech32AddressToHex } from "lib/utils";
import { addrToValoper } from "lib/utils";

import { useCurrentChain } from "./useCurrentChain";

export const useExampleAddresses = () => {
const { bech32Prefix } = useCurrentChain();

const generateExampleAddresses = () => {
const bytes = Array.from(Array(32).keys());
const user = toBech32(
bech32Prefix,
Uint8Array.from(bytes.slice(0, 20))
) as BechAddr20;
const bytes32 = Array.from(Array(32).keys());
const bytes20 = bytes32.slice(0, 20);
const user = toBech32(bech32Prefix, Uint8Array.from(bytes20)) as BechAddr20;

// reverse the bytes so the initial characters are different from the user address
const contractBech = toBech32(
const evmContract = "0x" + toHex(Uint8Array.from(bytes20).reverse());
const wasmContract = toBech32(
bech32Prefix,
Uint8Array.from(bytes.reverse())
Uint8Array.from(bytes32.reverse())
) as BechAddr32;

const contractHex = bech32AddressToHex(contractBech);

const validator = addrToValoper(user);

return {
user,
contractBech,
contractHex,
wasmContract,
evmContract,
validator,
};
};
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/ContractInputSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const ContractInputSection = ({
}: ContractInputSectionProps) => {
const [isChangeContract, setIsChangeContract] = useState(false);
const { address } = useCurrentChain();
const { contractBech: contractExample } = useExampleAddresses();
const { wasmContract: contractExample } = useExampleAddresses();
const { control, setValue, watch } = useForm({
defaultValues: {
contractAddress: "",
Expand Down
1 change: 1 addition & 0 deletions src/lib/components/dropzone/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export function DropZone({
wasm: wasm.enabled ? wasm.storeCodeMaxFileSize : 0,
mv: move.enabled ? move.moduleMaxFileSize : 0,
toml: 1_000_000,
// TODO - Revisit
vy: 10_000_000,
};

Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/modal/contract/SaveNewContract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function SaveNewContractModal({
const { getContractLocalInfo } = useContractStore();
const { validateContractAddress } = useValidateAddress();

const { contractBech: exampleContractAddress } = useExampleAddresses();
const { wasmContract: exampleContractAddress } = useExampleAddresses();
const initialList =
list.value === formatSlugName(INSTANTIATED_LIST_NAME) ? [] : [list];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const SelectContractInstantiator = ({
onContractSelect,
}: SelectContractInstantiatorProps) => {
const isMobile = useMobile();
const { contractBech: exampleContractAddress } = useExampleAddresses();
const { wasmContract: exampleContractAddress } = useExampleAddresses();
const { isOpen, onOpen, onClose } = useDisclosure();
const { validateContractAddress } = useValidateAddress();

Expand Down
2 changes: 1 addition & 1 deletion src/lib/pages/evm-contract-verify/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const EvmContractVerify = () => {
const isMobile = useMobile();
const router = useRouter();
const contractAddressQueryParam = router.query.contractAddress ?? "";
const { contractHex: exampleContractAddress } = useExampleAddresses();
const { evmContract: exampleContractAddress } = useExampleAddresses();

useEffect(() => {
if (router.isReady) track(AmpEvent.TO_EVM_CONTRACT_VERIFY);
Expand Down

0 comments on commit 80e034e

Please sign in to comment.