Skip to content

Commit

Permalink
Merge pull request #421 from alleslabs/feat/example-addresses
Browse files Browse the repository at this point in the history
feat: generate sample addresses
  • Loading branch information
evilpeach committed Jul 18, 2023
2 parents bc89f47 + 438076f commit 0fc0db7
Show file tree
Hide file tree
Showing 19 changed files with 71 additions and 113 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Improvements

- [#421](https://github.com/alleslabs/celatone-frontend/pull/421) Generate example addresses from a fixed-bytes array
- [#431](https://github.com/alleslabs/celatone-frontend/pull/431) Add new Osmosis v16 tx messages
- [#414](https://github.com/alleslabs/celatone-frontend/pull/414) Add jest test cases for funds and assetValue in utils, and remove isDecimalNumber in utils
- [#435](https://github.com/alleslabs/celatone-frontend/pull/435) Refactor chain's config, add new chain configs
Expand Down
7 changes: 0 additions & 7 deletions src/config/chain/default.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { ContractAddr, HumanAddr, ValidatorAddr } from "lib/types";

import type { ChainConfig } from "./types";

export const DEFAULT_CHAIN_CONFIG: ChainConfig = {
Expand Down Expand Up @@ -32,11 +30,6 @@ export const DEFAULT_CHAIN_CONFIG: ChainConfig = {
gasAdjustment: 1.0,
maxGasLimit: 0,
},
exampleAddresses: {
user: "" as HumanAddr,
contract: "" as ContractAddr,
validator: "" as ValidatorAddr,
},
explorerLink: {
validator: "",
proposal: "",
Expand Down
16 changes: 0 additions & 16 deletions src/config/chain/neutron.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { ContractAddr, HumanAddr, ValidatorAddr } from "lib/types";

import type { ChainConfigs } from "./types";

export const NEUTRON_CHAIN_CONFIGS: ChainConfigs = {
Expand Down Expand Up @@ -35,13 +33,6 @@ export const NEUTRON_CHAIN_CONFIGS: ChainConfigs = {
gasAdjustment: 1.5,
maxGasLimit: 25_000_000,
},
exampleAddresses: {
user: "neutron19glux3jzdfyyz6ylmuksgxfj5phdaxfr2uhy86" as HumanAddr,
contract:
"neutron1suhgf5svhu4usrurvxzlgn54ksxmn8gljarjtxqnapv8kjnp4nrstdxvff" as ContractAddr,
validator:
"neutronvaloper1c4k24jzduc365kywrsvf5ujz4ya6mwym69umfr" as ValidatorAddr,
},
explorerLink: {
validator: "https://www.mintscan.io/neutron/validators",
proposal: "",
Expand Down Expand Up @@ -79,13 +70,6 @@ export const NEUTRON_CHAIN_CONFIGS: ChainConfigs = {
gasAdjustment: 1.5,
maxGasLimit: 25_000_000,
},
exampleAddresses: {
user: "neutron19glux3jzdfyyz6ylmuksgxfj5phdaxfr2uhy86" as HumanAddr,
contract:
"neutron1suhgf5svhu4usrurvxzlgn54ksxmn8gljarjtxqnapv8kjnp4nrstdxvff" as ContractAddr,
validator:
"neutronvaloper1c4k24jzduc365kywrsvf5ujz4ya6mwym69umfr" as ValidatorAddr,
},
explorerLink: {
validator: "https://www.mintscan.io/neutron/validators",
proposal: "",
Expand Down
23 changes: 0 additions & 23 deletions src/config/chain/osmosis.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { ContractAddr, HumanAddr, ValidatorAddr } from "lib/types";

import type { ChainConfigs } from "./types";

export const OSMOSIS_CHAIN_CONFIGS: ChainConfigs = {
Expand Down Expand Up @@ -36,13 +34,6 @@ export const OSMOSIS_CHAIN_CONFIGS: ChainConfigs = {
gasAdjustment: 1.5,
maxGasLimit: 25_000_000,
},
exampleAddresses: {
user: "osmo14wk9zecqam9jsac7xwtf8e349ckquzzlx9k8c3" as HumanAddr,
contract:
"osmo1p0pxllmqjgl2tefy7grypt34jdpdltg3ka98n8unnl322wqps7lqtu576h" as ContractAddr,
validator:
"osmovaloper1hh0g5xf23e5zekg45cmerc97hs4n2004dy2t26" as ValidatorAddr,
},
explorerLink: {
validator: "https://www.mintscan.io/osmosis/validators",
proposal: "https://www.mintscan.io/osmosis/proposals",
Expand Down Expand Up @@ -82,13 +73,6 @@ export const OSMOSIS_CHAIN_CONFIGS: ChainConfigs = {
gasAdjustment: 1.5,
maxGasLimit: 25_000_000,
},
exampleAddresses: {
user: "osmo14wk9zecqam9jsac7xwtf8e349ckquzzlx9k8c3" as HumanAddr,
contract:
"osmo1p0pxllmqjgl2tefy7grypt34jdpdltg3ka98n8unnl322wqps7lqtu576h" as ContractAddr,
validator:
"osmovaloper1hh0g5xf23e5zekg45cmerc97hs4n2004dy2t26" as ValidatorAddr,
},
explorerLink: {
validator: "https://testnet.mintscan.io/osmosis-testnet/validators",
proposal: "https://testnet.mintscan.io/osmosis-testnet/proposals",
Expand Down Expand Up @@ -127,13 +111,6 @@ export const OSMOSIS_CHAIN_CONFIGS: ChainConfigs = {
gasAdjustment: 1.5,
maxGasLimit: 25_000_000,
},
exampleAddresses: {
user: "osmo14wk9zecqam9jsac7xwtf8e349ckquzzlx9k8c3" as HumanAddr,
contract:
"osmo1p0pxllmqjgl2tefy7grypt34jdpdltg3ka98n8unnl322wqps7lqtu576h" as ContractAddr,
validator:
"osmovaloper1hh0g5xf23e5zekg45cmerc97hs4n2004dy2t26" as ValidatorAddr,
},
explorerLink: {
validator: "",
proposal: "",
Expand Down
16 changes: 0 additions & 16 deletions src/config/chain/sei.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { ContractAddr, HumanAddr, ValidatorAddr } from "lib/types";

import type { ChainConfigs } from "./types";

export const SEI_CHAIN_CONFIGS: ChainConfigs = {
Expand Down Expand Up @@ -35,13 +33,6 @@ export const SEI_CHAIN_CONFIGS: ChainConfigs = {
gasAdjustment: 1.5,
maxGasLimit: 25_000_000,
},
exampleAddresses: {
user: "sei1acqpnvg2t4wmqfdv8hq47d3petfksjs5xjfnyj" as HumanAddr,
contract:
"sei18l6zzyyhrl7j9zw2lew50677va25rtsa2s4yy5gdpg4nxz3y3j9se47f0k" as ContractAddr,
validator:
"seivaloper1hh0g5xf23e5zekg45cmerc97hs4n2004dy2t26" as ValidatorAddr,
},
explorerLink: {
validator: "",
proposal: "",
Expand Down Expand Up @@ -79,13 +70,6 @@ export const SEI_CHAIN_CONFIGS: ChainConfigs = {
gasAdjustment: 1.5,
maxGasLimit: 25_000_000,
},
exampleAddresses: {
user: "sei1acqpnvg2t4wmqfdv8hq47d3petfksjs5xjfnyj" as HumanAddr,
contract:
"sei18l6zzyyhrl7j9zw2lew50677va25rtsa2s4yy5gdpg4nxz3y3j9se47f0k" as ContractAddr,
validator:
"seivaloper1hh0g5xf23e5zekg45cmerc97hs4n2004dy2t26" as ValidatorAddr,
},
explorerLink: {
validator: "https://testnet.mintscan.io/sei-testnet/validators",
proposal: "https://testnet.mintscan.io/sei-testnet/proposals",
Expand Down
9 changes: 0 additions & 9 deletions src/config/chain/stargaze.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { ContractAddr, HumanAddr, ValidatorAddr } from "lib/types";

import type { ChainConfigs } from "./types";

export const STARGAZE_CHAIN_CONFIGS: ChainConfigs = {
Expand Down Expand Up @@ -35,13 +33,6 @@ export const STARGAZE_CHAIN_CONFIGS: ChainConfigs = {
gasAdjustment: 1.5,
maxGasLimit: 25_000_000,
},
exampleAddresses: {
user: "stars16hetkn089m2s8nsjwppwhjed4ecp4dqtvltv82" as HumanAddr,
contract:
"stars1m4ns69zvkk2zv0946mw298tlky5ckvu08rtxggtg29p784kc5sxqwgx4h0" as ContractAddr,
validator:
"starsvaloper1mz2qks48v486d9m8wp4l9fxm2e9l0e0kzk79m5" as ValidatorAddr,
},
explorerLink: {
validator: "https://www.mintscan.io/stargaze/validators",
proposal: "https://www.mintscan.io/stargaze/proposals",
Expand Down
7 changes: 0 additions & 7 deletions src/config/chain/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { HumanAddr, ValidatorAddr, ContractAddr } from "lib/types";

type FaucetConfig =
| {
enabled: true;
Expand Down Expand Up @@ -53,11 +51,6 @@ export interface ChainConfig {
gasAdjustment: number;
maxGasLimit: number;
};
exampleAddresses: {
user: HumanAddr;
validator: ValidatorAddr;
contract: ContractAddr;
};
explorerLink: ExplorerConfig;
}

Expand Down
10 changes: 9 additions & 1 deletion src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ export const SUPPORTED_CHAIN_IDS: string[] = (() => {
// Remark: We've already checked that the first element is not empty on the above code
export const DEFAULT_SUPPORTED_CHAIN_ID = SUPPORTED_CHAIN_IDS[0];

export const DUMMY_MNEMONIC = process.env.NEXT_PUBLIC_DUMMY_MNEMONIC;
export const DUMMY_MNEMONIC = (() => {
const mnemonic = process.env.NEXT_PUBLIC_DUMMY_MNEMONIC;
if (!mnemonic)
throw new Error(
"NEXT_PUBLIC_DUMMY_MNEMONIC is empty. Please include a valid mnemonic."
);

return mnemonic;
})();

export const CELATONE_API_OVERRIDE =
process.env.NEXT_PUBLIC_CELATONE_API_OVERRIDE;
Expand Down
1 change: 1 addition & 0 deletions src/lib/app-provider/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from "./useAddress";
export * from "./useAmplitude";
export * from "./useDummyWallet";
export * from "./useExampleAddresses";
export * from "./useFabricateFee";
export * from "./useInternalNavigate";
export * from "./useLCDEndpoint";
Expand Down
7 changes: 3 additions & 4 deletions src/lib/app-provider/hooks/useAddress.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { fromBech32 } from "@cosmjs/encoding";
import { useCallback, useMemo } from "react";

import { useCelatoneApp } from "../contexts";
import type { Option } from "lib/types";

import { useCurrentChain } from "./useCurrentChain";
import { useExampleAddresses } from "./useExampleAddresses";

export type AddressReturnType =
| "user_address"
Expand All @@ -13,9 +13,8 @@ export type AddressReturnType =
| "invalid_address";

export const useGetAddressTypeByLength = () => {
const {
chainConfig: { exampleAddresses },
} = useCelatoneApp();
const exampleAddresses = useExampleAddresses();

const addressLengthMap = useMemo(
() =>
Object.entries(exampleAddresses).reduce<{
Expand Down
37 changes: 37 additions & 0 deletions src/lib/app-provider/hooks/useExampleAddresses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { toBech32 } from "@cosmjs/encoding";
import { useMemo } from "react";

import type { ContractAddr, HumanAddr } from "lib/types";
import { addrToValoper } from "lib/utils";

import { useCurrentChain } from "./useCurrentChain";

export const useExampleAddresses = () => {
const {
chain: { bech32_prefix: prefix },
} = useCurrentChain();

const generateExampleAddresses = () => {
const bytes = Array.from(Array(32).keys());
const user = toBech32(
prefix,
new Uint8Array(bytes.slice(0, 20))
) as HumanAddr;

// reverse the bytes so the initial characters are different from the user address
const contract = toBech32(
prefix,
new Uint8Array(bytes.reverse())
) as ContractAddr;

const validator = addrToValoper(user);

return {
user,
contract,
validator,
};
};

return useMemo(generateExampleAddresses, [prefix]);
};
10 changes: 3 additions & 7 deletions src/lib/components/AddressInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
} from "react-hook-form";
import { useWatch } from "react-hook-form";

import { useCelatoneApp, useValidateAddress } from "lib/app-provider";
import { useExampleAddresses, useValidateAddress } from "lib/app-provider";
import type { FormStatus, TextInputProps } from "lib/components/forms";
import { ControllerInput } from "lib/components/forms";
import type { Option } from "lib/types";
Expand Down Expand Up @@ -43,11 +43,7 @@ export const AddressInput = <T extends FieldValues>({
helperAction,
requiredText = "Address is empty",
}: AddressInputProps<T>) => {
const {
chainConfig: {
exampleAddresses: { user: exampleAddr },
},
} = useCelatoneApp();
const { user: exampleUserAddress } = useExampleAddresses();
const { validateUserAddress, validateContractAddress } = useValidateAddress();
const validateAddress = useCallback(
(input: string) =>
Expand All @@ -69,7 +65,7 @@ export const AddressInput = <T extends FieldValues>({
name={name}
control={control}
label={label}
placeholder={placeholder ?? exampleAddr}
placeholder={placeholder ?? exampleUserAddress}
type="text"
variant="floating"
status={status}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/button/ResendButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const ResendButton = ({ messages }: ResendButtonProps) => {
const { isFetching: isSimulating } = useSimulateFeeQuery({
enabled: isProcessing,
messages: composedMsgs,
onSuccess: (estimatedGasUsed) => proceed(estimatedGasUsed),
onSuccess: proceed,
onError: () => setIsProcessing(false),
});

Expand Down
7 changes: 2 additions & 5 deletions src/lib/components/modal/contract/SaveNewContract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ActionModal } from "../ActionModal";
import {
useBaseApiRoute,
useCelatoneApp,
useExampleAddresses,
useValidateAddress,
} from "lib/app-provider";
import type { FormStatus } from "lib/components/forms";
Expand Down Expand Up @@ -47,11 +48,7 @@ export function SaveNewContractModal({
const { getContractLocalInfo } = useContractStore();
const { validateContractAddress } = useValidateAddress();

const {
chainConfig: {
exampleAddresses: { contract: exampleContractAddress },
},
} = useCelatoneApp();
const { contract: 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 @@ -20,7 +20,7 @@ import { useState } from "react";
import { CustomIcon } from "../icon";
import {
useBaseApiRoute,
useCelatoneApp,
useExampleAddresses,
useMobile,
useValidateAddress,
} from "lib/app-provider";
Expand All @@ -43,11 +43,7 @@ export const SelectContractInstantiator = ({
notSelected,
onContractSelect,
}: SelectContractInstantiatorProps) => {
const {
chainConfig: {
exampleAddresses: { contract: exampleContractAddress },
},
} = useCelatoneApp();
const { contract: exampleContractAddress } = useExampleAddresses();
const { isOpen, onOpen, onClose } = useDisclosure();
const [listSlug, setListSlug] = useState("");
const { validateContractAddress } = useValidateAddress();
Expand Down
4 changes: 3 additions & 1 deletion src/lib/components/table/codes/CodesTableRow.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Text, Grid, HStack } from "@chakra-ui/react";

import { TableRow } from "../tableComponents";
import { useGetAddressType } from "lib/app-provider";
import { InstantiateButton } from "lib/components/button";
import { ExplorerLink } from "lib/components/ExplorerLink";
import { SaveOrRemoveCodeModal } from "lib/components/modal";
Expand All @@ -23,6 +24,7 @@ export const CodesTableRow = ({
onRowSelect,
isReadOnly,
}: CodesTableRowProps) => {
const getAddressType = useGetAddressType();
const cw2Info = getCw2Info(codeInfo.cw2Contract, codeInfo.cw2Version);
return (
<Grid
Expand Down Expand Up @@ -64,7 +66,7 @@ export const CodesTableRow = ({
<TableRow>
<ExplorerLink
value={codeInfo.uploader}
type="user_address"
type={getAddressType(codeInfo.uploader)}
showCopyOnHover
isReadOnly={isReadOnly}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/table/contracts/ContractsTableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const InstantiatorRender = ({
return instantiator ? (
<ExplorerLink
value={instantiator}
type="user_address"
type={getAddressType(instantiator)}
showCopyOnHover
isReadOnly={isReadOnly}
/>
Expand Down
Loading

2 comments on commit 0fc0db7

@vercel
Copy link

@vercel vercel bot commented on 0fc0db7 Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 0fc0db7 Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.