Skip to content

Commit

Permalink
fix: remove hardcoded chain name
Browse files Browse the repository at this point in the history
  • Loading branch information
fmorency committed Dec 17, 2024
1 parent cbdb3d5 commit 7afd10d
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 82 deletions.
3 changes: 2 additions & 1 deletion components/react/authSignerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { decodePubkey } from '@cosmjs/proto-signing';
import { useWallet, useChain } from '@cosmos-kit/react';
import { getRealLogo } from '@/utils';
import { useTheme } from '@/contexts';
import env from '@/config/env';

type DisplayDataToSignProps = {
data: SignData;
Expand Down Expand Up @@ -116,7 +117,7 @@ const SignModal = ({
reject: () => void;
}) => {
const wallet = useWallet();
const { address } = useChain('manifest');
const { address } = useChain(env.chain);
const walletIcon = wallet.wallet?.logo;
const walletName = wallet.wallet?.prettyName;
const { theme } = useTheme();
Expand Down
3 changes: 2 additions & 1 deletion components/react/header.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import env from '@/config/env';
import { WalletSection } from '../wallet';

export default function Header() {
Expand All @@ -6,7 +7,7 @@ export default function Header() {
<nav className="bg-white border-b border-gray-200 dark:bg-gray-800 dark:border-gray-700 px-4 fixed w-full lg:px-6 py-2 ">
<div className="flex justify-end items-center mx-auto max-w-screen-6xl">
{/* Log Out Button */}
<WalletSection chainName="manifest" />
<WalletSection chainName={env.chain} />
</div>
</nav>
</header>
Expand Down
2 changes: 1 addition & 1 deletion components/react/mobileNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default function MobileNav() {
</li>

<div className="justify-between items-center">
<WalletSection chainName="manifest" />
<WalletSection chainName={env.chain} />
</div>

{/* Updated close button - now uses flex-1 and mt-auto to push to bottom */}
Expand Down
4 changes: 2 additions & 2 deletions components/react/sideNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default function SideNav({ isDrawerVisible, setDrawerVisible }: SideNavPr
</span>
</button>
<div className="flex justify-center w-full text-[#00000066] dark:text-[#FFFFFF66]">
<IconWallet chainName="manifest" />
<IconWallet chainName={env.chain} />
</div>
<label className="swap swap-rotate text-[#00000066] dark:text-[#FFFFFF66] hover:text-primary dark:hover:text-primary transition-all duration-300 ease-in-out">
<input
Expand Down Expand Up @@ -189,7 +189,7 @@ export default function SideNav({ isDrawerVisible, setDrawerVisible }: SideNavPr

<ul className="pt-5 pb-4">
<div className="mx-auto w-full justify-center items-center h-full">
<WalletSection chainName="manifest" />
<WalletSection chainName={env.chain} />
</div>
</ul>
<div className="flex flex-row justify-between items-center">
Expand Down
3 changes: 2 additions & 1 deletion components/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ArrowUpIcon, CopyIcon } from './icons';
import { useChain } from '@cosmos-kit/react';
import { WalletStatus } from 'cosmos-kit';
import { MdWallet } from 'react-icons/md';
import env from '@/config/env';

const buttons = {
Disconnected: {
Expand Down Expand Up @@ -277,7 +278,7 @@ export function WalletNotConnected({
{description}
</p>
<div className="w-[50%]">
<WalletSection chainName="manifest" />
<WalletSection chainName={env.chain} />
</div>
</div>
<div className="hidden lg:mt-0 lg:ml-24 lg:col-span-5 lg:flex">{icon}</div>
Expand Down
4 changes: 2 additions & 2 deletions config/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AssetList, Chain } from '@chain-registry/types';
import env from './env';

export const manifestChain: Chain = {
chain_name: 'manifest',
chain_name: env.chain,
status: 'live',
network_type: env.chainTier,
website: '',
Expand Down Expand Up @@ -64,7 +64,7 @@ export const manifestChain: Chain = {
},
};
export const manifestAssets: AssetList = {
chain_name: 'manifest',
chain_name: env.chain,
assets: [
{
description: 'Manifest testnet native token',
Expand Down
2 changes: 1 addition & 1 deletion pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function ManifestApp({ Component, pageProps }: ManifestAppProps) {
const endpointOptions = {
isLazy: true,
endpoints: {
manifest: {
[env.chain]: {
rpc: [env.rpcUrl],
rest: [env.apiUrl],
},
Expand Down
5 changes: 3 additions & 2 deletions pages/admins.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WalletNotConnected, WalletSection } from '@/components';
import { WalletNotConnected } from '@/components';
import { useChain } from '@cosmos-kit/react';
import ValidatorList from '@/components/admins/components/validatorList';
import Head from 'next/head';
Expand All @@ -9,8 +9,9 @@ import { ValidatorSDKType } from '@liftedinit/manifestjs/dist/codegen/cosmos/sta
import { PiWarning } from 'react-icons/pi';
import { AdminsIcon } from '@/components/icons';
import { StakeHolderPayout, ChainUpgrader } from '@/components/admins/components';
import env from '@/config/env';
export default function Admins() {
const { address, isWalletConnected } = useChain('manifest');
const { address, isWalletConnected } = useChain(env.chain);
const { poaAdmin } = usePoaGetAdmin();
const { pendingValidators, isPendingValidatorsLoading } = usePendingValidators();
const { validators, isActiveValidatorsLoading } = useValidators();
Expand Down
6 changes: 0 additions & 6 deletions utils/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ export function truncateString(str: string, num: number) {
return str;
}
}

export const isValidAddress = (address: string, prefix?: string): boolean => {
const actualPrefix = prefix || 'manifest';
return address.startsWith(actualPrefix) && address.length === actualPrefix.length + 39;
};

export const isValidIPFSCID = (cid: string): boolean => {
const cidV0Regex = /^Qm[1-9A-HJ-NP-Za-km-z]{44}$/;
const cidV1Regex = /^b[A-Za-z2-7]{58}$/;
Expand Down
68 changes: 3 additions & 65 deletions utils/transactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { useTx } from '@/hooks/useTx';
import { osmosis } from '@liftedinit/manifestjs';
import { useChain } from '@cosmos-kit/react';
import { DenomUnit } from '@liftedinit/manifestjs/dist/codegen/cosmos/bank/v1beta1/bank';
import env from '@/config/env';

export const useSimulateDenomCreation = () => {
const [isSimulating, setIsSimulating] = useState(false);
const { tx } = useTx('manifest');
const { address } = useChain('manifest');
const { tx } = useTx(env.chain);
const { address } = useChain(env.chain);

const simulateDenomCreation = async (subdenom: string): Promise<boolean> => {
if (!address) {
Expand Down Expand Up @@ -49,66 +50,3 @@ export const useSimulateDenomCreation = () => {

return { simulateDenomCreation, isSimulating };
};

export const useSimulateDenomMetadata = () => {
const [isSimulating, setIsSimulating] = useState(false);
const { tx } = useTx('manifest');
const { address } = useChain('manifest');

const simulateDenomCreation = async (
subdenom: string,
fullDenom: string,
description: string,
denomUnits: DenomUnit[],
display: string,
symbol: string,
uri: string
): Promise<boolean> => {
if (!address) {
console.log('Simulation failed: No address available');
return false;
}

setIsSimulating(true);
const { setDenomMetadata } = osmosis.tokenfactory.v1beta1.MessageComposer.withTypeUrl;

const msg = setDenomMetadata({
sender: address,
metadata: {
description: description,
denomUnits: denomUnits,
base: fullDenom,
display: display,
name: display,
symbol: symbol,
uri: uri ?? '',
uriHash: '',
},
});

try {
console.log(`Simulating metadata creation for subdenom: ${subdenom}`);
const result = await tx([msg], { simulate: true, returnError: true });

if (result === undefined) {
console.log('Simulation result is undefined');
return false;
}

if ('error' in result) {
console.error('Simulation error:', result.error);
return false;
}

console.log('Simulation successful');
return true;
} catch (error) {
console.error('Unexpected error during simulation:', error);
return false;
} finally {
setIsSimulating(false);
}
};

return { simulateDenomCreation, isSimulating };
};

0 comments on commit 7afd10d

Please sign in to comment.