Skip to content

Eason/bugfix #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@
"type": "git",
"url": "https://github.com/hyperweb-io/create-hyperweb-app"
},
"packageManager": "yarn@4.1.0"
"packageManager": "yarn@4.3.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const OverviewTransferWrapper = (
const toastHandlers = useToastHandlers();
const { data: signingClient } = useSigningClient(sourceChainName);
const { mutate: transfer, isLoading } = useTransfer({
clientResolver: signingClient,
clientResolver: signingClient as any,
options: {
context: defaultContext,
...toastHandlers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const TransferModalBody = (
const toastHandlers = useToastHandlers();
const { data: signingClient } = useSigningClient(sourceChainName);
const { mutate: transfer, isLoading } = useTransfer({
clientResolver: signingClient,
clientResolver: signingClient as any,
options: {
context: defaultContext,
...toastHandlers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const ConnectButton = () => {
const walletLogo =
typeof walletInfo?.logo === 'string'
? walletInfo.logo
: walletInfo.logo.major || walletInfo.logo.minor;
: walletInfo?.logo?.major || walletInfo?.logo?.minor;

return (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useMemo, useState } from 'react';
import { Box } from '@interchain-ui/react';
import { Asset } from '@chain-registry/v2-types';
import { Asset } from '@chain-registry/types';
import BigNumber from 'bignumber.js';
import { TbCurrencyDollarOff } from 'react-icons/tb';
import { LuListPlus } from 'react-icons/lu';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Dispatch, SetStateAction, useMemo } from 'react';
import { assetLists } from '@chain-registry/v2';
import { assetLists } from 'chain-registry';
import { LuPlus } from 'react-icons/lu';

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Dispatch, SetStateAction, useState } from 'react';
import { HiOutlineTrash } from 'react-icons/hi';
import { Asset } from '@chain-registry/v2-types';
import { Asset } from '@chain-registry/types';
import {
Avatar,
Box,
Expand Down Expand Up @@ -95,7 +95,7 @@ export const SelectAssetItem = ({
>
<PopoverTrigger>
<SelectButton
onClick={() => {}}
onClick={() => { }}
placeholder={selectedAssetWithAmount?.asset?.symbol ?? 'Select'}
_css={{ width: isMobile ? '100px' : '140px' }}
/>
Expand All @@ -108,9 +108,8 @@ export const SelectAssetItem = ({
py="10px"
bg="$background"
borderRadius="4px"
boxShadow={`0px 4px 20px 0px rgba(${
theme === 'light' ? '0,0,0' : '128,128,128'
}, 0.1)`}
boxShadow={`0px 4px 20px 0px rgba(${theme === 'light' ? '0,0,0' : '128,128,128'
}, 0.1)`}
maxHeight="220px"
overflowY="auto"
>
Expand Down
2 changes: 1 addition & 1 deletion templates/chain-admin/components/staking/DelegateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const DelegateModal = ({
const toastHandlers = useToastHandlers();
const { data: signingClient } = useSigningClient(chainName);
const { mutate: delegate, isLoading: isDelegating } = useDelegate({
clientResolver: signingClient,
clientResolver: signingClient as any,
options: {
context: defaultContext,
...toastHandlers,
Expand Down
2 changes: 1 addition & 1 deletion templates/chain-admin/components/staking/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const Overview = ({
const { data: signingClient } = useSigningClient(chainName);
const { mutate: withdrawDelegatorReward, isLoading: isClaiming } =
useWithdrawDelegatorReward({
clientResolver: signingClient,
clientResolver: signingClient as any,
options: {
context: defaultContext,
...toastHandlers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const RedelegateModal = ({
const { data: signingClient } = useSigningClient(chainName);
const { mutate: beginRedelegate, isLoading: isRedelegating } =
useBeginRedelegate({
clientResolver: signingClient,
clientResolver: signingClient as any,
options: {
context: defaultContext,
...toastHandlers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const UndelegateModal = ({
const toastHandlers = useToastHandlers();
const { data: signingClient } = useSigningClient(chainName);
const { mutate: undelegate, isLoading: isUndelegating } = useUndelegate({
clientResolver: signingClient,
clientResolver: signingClient as any,
options: {
context: defaultContext,
...toastHandlers,
Expand Down
84 changes: 42 additions & 42 deletions templates/chain-admin/components/voting/Voting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function Voting({ chainName }: VotingProps) {
const { modal, open: openModal, close: closeModal, setTitle } = useModal('');
const [tallies, setTallies] = useState<{ [key: string]: TallyResult }>({});

const chain = chains.find((c) => c.chain_name === chainName);
const chain = chains.find((c) => c.chainName === chainName);

useEffect(() => {
if (!data.proposals || data.proposals.length === 0) return;
Expand Down Expand Up @@ -86,7 +86,7 @@ export function Voting({ chainName }: VotingProps) {
};
});
break;
} catch (e) {}
} catch (e) { }
}
})();
}
Expand Down Expand Up @@ -119,46 +119,46 @@ export function Voting({ chainName }: VotingProps) {
{data.proposals?.length === 0
? empty
: data.proposals?.map((proposal, index) => {
let tally = proposal.finalTallyResult;
if (
proposal.status === ProposalStatus.PROPOSAL_STATUS_VOTING_PERIOD
) {
tally = tallies[proposal.id.toString()];
}
return (
<Box
my="$8"
key={proposal.id?.toString() || index}
position="relative"
attributes={{ onClick: () => onClickProposal(index) }}
>
{data.votes[proposal.id.toString()] ? (
<Box
position="absolute"
px="$4"
py="$2"
top="$4"
right="$6"
borderRadius="$md"
backgroundColor="$green400"
>
<Text color="$white" fontSize="$xs" fontWeight="$bold">
Voted
</Text>
</Box>
) : null}
<GovernanceProposalItem
id={`# ${proposal.id?.toString()}`}
key={proposal.submitTime?.getTime()}
// @ts-ignore
title={proposal.content?.title || proposal.title || ''}
status={status(proposal.status)}
votes={votes(tally!)}
endTime={formatDate(proposal.votingEndTime)!}
/>
</Box>
);
})}
let tally = proposal.finalTallyResult;
if (
proposal.status === ProposalStatus.PROPOSAL_STATUS_VOTING_PERIOD
) {
tally = tallies[proposal.id.toString()];
}
return (
<Box
my="$8"
key={proposal.id?.toString() || index}
position="relative"
attributes={{ onClick: () => onClickProposal(index) }}
>
{data.votes[proposal.id.toString()] ? (
<Box
position="absolute"
px="$4"
py="$2"
top="$4"
right="$6"
borderRadius="$md"
backgroundColor="$green400"
>
<Text color="$white" fontSize="$xs" fontWeight="$bold">
Voted
</Text>
</Box>
) : null}
<GovernanceProposalItem
id={`# ${proposal.id?.toString()}`}
key={proposal.submitTime?.getTime()}
// @ts-ignore
title={proposal.content?.title || proposal.title || ''}
status={status(proposal.status)}
votes={votes(tally!)}
endTime={formatDate(proposal.votingEndTime)!}
/>
</Box>
);
})}
</Box>
);

Expand Down
2 changes: 1 addition & 1 deletion templates/chain-admin/hooks/asset-list/useAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const useAssets = (chainName: string) => {
const dollarValue = calcCoinDollarValue(prices, { amount, denom });
return {
symbol,
logoUrl: asset.logo_URIs?.png || asset.logo_URIs?.svg,
logoUrl: asset.logoURIs?.png || asset.logoURIs?.svg,
prettyChainName: getPrettyChainName(denom),
displayAmount: convRawToDispAmount(denom, amount),
dollarValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ type CoinGeckoUSD = { usd: number };
type CoinGeckoUSDResponse = Record<CoinGeckoId, CoinGeckoUSD>;

const getAssetsWithGeckoIds = (assets: Asset[]) => {
return assets.filter((asset) => !!asset?.coingecko_id);
return assets.filter((asset) => !!asset?.coingeckoId);
};

const getGeckoIds = (assets: Asset[]) => {
return assets.map((asset) => asset.coingecko_id) as string[];
return assets.map((asset) => asset.coingeckoId) as string[];
};

const formatPrices = (
prices: CoinGeckoUSDResponse,
assets: Asset[]
): Record<string, number> => {
return Object.entries(prices).reduce((priceHash, cur) => {
const denom = assets.find((asset) => asset.coingecko_id === cur[0])!.base;
const denom = assets.find((asset) => asset.coingeckoId === cur[0])!.base;
return { ...priceHash, [denom]: cur[1].usd };
}, {});
};
Expand Down
28 changes: 14 additions & 14 deletions templates/chain-admin/hooks/asset-list/useChainUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useMemo } from 'react';
import { useWalletManager } from '@interchain-kit/react';
import { Asset, AssetList } from '@chain-registry/types';
import { asset_lists as ibcAssetLists } from '@chain-registry/assets';
import { assets as chainAssets, ibc } from 'chain-registry';
import { assetLists as chainAssets, ibcData as ibc } from 'chain-registry';
import { Coin } from '@interchainjs/react/types';
import BigNumber from 'bignumber.js';

Expand All @@ -18,14 +18,14 @@ export const useChainUtils = (chainName: string) => {
starshipData?.v1 ?? {};

const isStarshipChain = starshipChains.some(
(chain) => chain.chain_name === chainName
(chain) => chain.chainName === chainName
);

const filterAssets = (assetList: AssetList[]): Asset[] => {
return (
assetList
.find(({ chain_name }) => chain_name === chainName)
?.assets?.filter(({ type_asset }) => type_asset !== 'ics20') || []
.find(({ chainName }) => chainName === chainName)
?.assets?.filter(({ typeAsset }) => typeAsset !== 'ics20') || []
);
};

Expand Down Expand Up @@ -66,7 +66,7 @@ export const useChainUtils = (chainName: string) => {
(asset) =>
asset.symbol === symbol &&
(!chainName ||
asset.traces?.[0].counterparty.chain_name.toLowerCase() ===
asset.traces?.[0].counterparty.chainName.toLowerCase() ===
chainName.toLowerCase())
);
const base = asset?.base;
Expand All @@ -78,7 +78,7 @@ export const useChainUtils = (chainName: string) => {

const getExponentByDenom = (denom: CoinDenom): Exponent => {
const asset = getAssetByDenom(denom);
const unit = asset.denom_units.find(({ denom }) => denom === asset.display);
const unit = asset.denomUnits.find(({ denom }) => denom === asset.display);
return unit?.exponent || 0;
};

Expand All @@ -102,7 +102,7 @@ export const useChainUtils = (chainName: string) => {
return chainName;
}
const asset = ibcAssets.find((asset) => asset.base === ibcDenom);
const ibcChainName = asset?.traces?.[0].counterparty.chain_name;
const ibcChainName = asset?.traces?.[0].counterparty.chainName;
if (!ibcChainName)
throw Error('chainName not found for ibcDenom: ' + ibcDenom);
return ibcChainName;
Expand Down Expand Up @@ -140,15 +140,15 @@ export const useChainUtils = (chainName: string) => {

let ibcInfo = ibc.find(
(i) =>
i.chain_1.chain_name === fromChainName &&
i.chain_2.chain_name === toChainName
i.chain1.chainName === fromChainName &&
i.chain2.chainName === toChainName
);

if (!ibcInfo) {
ibcInfo = ibc.find(
(i) =>
i.chain_1.chain_name === toChainName &&
i.chain_2.chain_name === fromChainName
i.chain1.chainName === toChainName &&
i.chain2.chainName === fromChainName
);
flipped = true;
}
Expand All @@ -157,9 +157,9 @@ export const useChainUtils = (chainName: string) => {
throw new Error('cannot find IBC info');
}

const key = flipped ? 'chain_2' : 'chain_1';
const sourcePort = ibcInfo.channels[0][key].port_id;
const sourceChannel = ibcInfo.channels[0][key].channel_id;
const key = flipped ? 'chain2' : 'chain1';
const sourcePort = ibcInfo.channels[0][key].portId;
const sourceChannel = ibcInfo.channels[0][key].channelId;

return { sourcePort, sourceChannel };
};
Expand Down
18 changes: 12 additions & 6 deletions templates/chain-admin/hooks/common/useStarshipChains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AssetList, Chain } from '@chain-registry/types';
import {
Chain as ChainV2,
AssetList as AssetListV2,
} from '@chain-registry/v2-types';
} from '@chain-registry/types';

import { StarshipConfig } from '@/starship';
import { convertKeysToCamelCase } from '@/utils';
Expand Down Expand Up @@ -31,20 +31,26 @@ export const useStarshipChains = () => {
const { chains = [] } =
(await fetcher<{ chains: Chain[] }>(`${baseUrl}/chains`)) ?? {};

const chainsWithType = chains.map(chain => ({
...chain,
chainType: "cosmos" as const
}));

const assets = (await Promise.all(
chains.map((chain) =>
fetcher<AssetList>(`${baseUrl}/chains/${chain.chain_id}/assets`)
chainsWithType.map((chain) =>
// @ts-ignore
fetcher<AssetList>(`${baseUrl}/chains/${chain.chain_id}/assets`) // if use chainId, got error: Cannot read properties of undefined (reading 'chainName') at const { connect, disconnect, address, wallet } = useChain(selectedChain)
)
).then((assetLists) => assetLists.filter(Boolean))) as AssetList[];

return chains.length > 0 && assets.length > 0
return chainsWithType.length > 0 && assets.length > 0
? {
v1: {
chains,
chains: chainsWithType,
assets,
},
v2: {
chains: convertKeysToCamelCase(chains) as ChainV2[],
chains: convertKeysToCamelCase(chainsWithType) as ChainV2[],
assets: convertKeysToCamelCase(assets) as AssetListV2[],
},
}
Expand Down
Loading
Loading