Skip to content

Commit

Permalink
Merge pull request #200 from cosmology-tech/eason/chain-template
Browse files Browse the repository at this point in the history
bug fixed for chain-template
  • Loading branch information
marslavish committed Aug 20, 2024
2 parents 0f4ba5d + c1b10e7 commit ef1bcd1
Show file tree
Hide file tree
Showing 17 changed files with 14,394 additions and 87 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/run-tests-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,18 @@ jobs:
- name: Set up Yarn
uses: threeal/setup-yarn-action@v2.0.0

- name: Get last git commit hash
run: |
echo "DIFF_HASH=$(git log -1 --pretty=format:%H)" >> $GITHUB_ENV
- name: Cache NextJS
uses: actions/cache@v4
with:
path: |
${{ github.workspace }}/.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
#key: ${{ runner.os }}-nextjs-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/yarn.lock') }}-${{ env.DIFF_HASH }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/yarn.lock') }}-
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ jobs:
run: |
cca --example nft --name nft
cd nft
touch yarn.lock
yarn install
yarn build
- name: authz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ const OverviewTransferWrapper = (
}
return new BigNumber(asset.amount).gt(0);
})
.filter((asset) => {
return asset.symbol !== transferToken.symbol;
})
// .filter((asset) => {
// return asset.symbol !== transferToken.symbol;
// })
.map((asset) => ({
available: new BigNumber(asset.displayAmount).toNumber(),
symbol: asset.symbol,
Expand All @@ -198,6 +198,7 @@ const OverviewTransferWrapper = (
).toNumber(),
}));
}, [assets, isDeposit, transferToken]);
console.log('assetOptions', assetOptions);

const handleOnChange = (
assetOption: Unpacked<OverviewTransferProps['dropdownList']>,
Expand Down Expand Up @@ -269,7 +270,7 @@ export const DropdownTransferModal = (props: OverviewTransferWrapperProps) => {
return (
<BasicModal
isOpen={modalControl.isOpen}
title="Deposit"
title={transferInfoState.transferInfo.type}
onClose={() => closeModal()}
>
{transferInfoState ? (
Expand Down
9 changes: 5 additions & 4 deletions examples/chain-template/components/staking/DelegateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import {
isGreaterThanZero,
shiftDigits,
calcDollarValue,
getCoin,
getExponent,
toBaseAmount,
} from '@/utils';
import { getCoin, getExponent } from '@/utils';
import { Prices, UseDisclosureReturn, useTx } from '@/hooks';

const { delegate } = cosmos.staking.v1beta1.MessageComposer.fromPartial;
Expand Down Expand Up @@ -84,7 +86,7 @@ export const DelegateModal = ({
delegatorAddress: address,
validatorAddress: selectedValidator.address,
amount: {
amount: shiftDigits(amount, exp),
amount: toBaseAmount(amount, exp), // shiftDigits(amount, exp),
denom: coin.base,
},
});
Expand Down Expand Up @@ -220,8 +222,7 @@ export const DelegateModal = ({
},
{
label: 'Max',
onClick: handleMaxClick,
isLoading: isSimulating,
onClick: () => setAmount(Number(balance)),
},
],
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
getAssetLogoUrl,
isGreaterThanZero,
shiftDigits,
toBaseAmount,
type ExtendedValidator as Validator,
} from '@/utils';
import { getCoin, getExponent } from '@/utils';
Expand Down Expand Up @@ -67,7 +68,7 @@ export const RedelegateModal = ({
validatorDstAddress: validatorToRedelegate.address,
amount: {
denom: coin.base,
amount: shiftDigits(amount, exp),
amount: toBaseAmount(amount, exp),
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
getAssetLogoUrl,
isGreaterThanZero,
shiftDigits,
toBaseAmount,
type ExtendedValidator as Validator,
} from '@/utils';

Expand Down Expand Up @@ -68,7 +69,7 @@ export const UndelegateModal = ({
delegatorAddress: address,
validatorAddress: selectedValidator.address,
amount: {
amount: shiftDigits(amount, exp),
amount: toBaseAmount(amount, exp),
denom: coin.base,
},
});
Expand Down
21 changes: 13 additions & 8 deletions examples/chain-template/components/voting/Proposal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function Proposal({
proposal,
chainName,
bondedTokens,
onVoteSuccess = () => {},
onVoteSuccess = () => { },
}: ProposalProps) {
const vote = votes?.[proposal.id.toString()];

Expand Down Expand Up @@ -92,9 +92,9 @@ export function Proposal({

const total = proposal.finalTallyResult
? Object.values(proposal.finalTallyResult).reduce(
(sum, val) => sum + Number(val),
0
)
(sum, val) => sum + Number(val),
0
)
: 0;

const turnout = total / Number(bondedTokens);
Expand Down Expand Up @@ -248,9 +248,8 @@ export function Proposal({
px: '$2',
}}
>
{`Minimum of staked ${minStakedTokens} ${coin.symbol}(${
quorum * 100
}%) need to vote
{`Minimum of staked ${minStakedTokens} ${coin.symbol}(${quorum * 100
}%) need to vote
for this proposal to pass.`}
</Text>
</Text>
Expand Down Expand Up @@ -347,14 +346,20 @@ export function Proposal({
</Text>

<Text fontSize="$sm" fontWeight="$normal" color="$textSecondary">
<div style={{ maxHeight: '128px', overflowY: 'scroll' }}>
<Markdown>{description}</Markdown>
</div>
</Text>

{/* <Text fontSize="$sm" fontWeight="$normal" color="$textSecondary">
{showMore ? <Markdown>{description}</Markdown> : renderedDescription}
</Text>
<Box mt="$8" width="100%" display="flex" justifyContent="center">
<Button intent="secondary" variant="ghost" onClick={toggleShowMore}>
{showMore ? 'Show less' : 'Show more'}
</Button>
</Box>
</Box> */}
</Box>
</Box>
);
Expand Down
4 changes: 2 additions & 2 deletions examples/chain-template/components/voting/Voting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function Voting({ chainName }: VotingProps) {
openModal();
setProposal(proposal);
// @ts-ignore
setTitle(`#${proposal.proposalId?.toString()} ${proposal.content?.title}`);
setTitle(`#${proposal.id?.toString()} ${proposal?.title}`);
}

const content = (
Expand Down Expand Up @@ -93,7 +93,7 @@ export function Voting({ chainName }: VotingProps) {
id={`# ${proposal.id?.toString()}`}
key={proposal.submitTime?.getTime()}
// @ts-ignore
title={proposal.content?.title || ""}
title={proposal.content?.title || proposal.title || ''}
status={status(proposal.status)}
votes={votes(proposal.finalTallyResult!)}
endTime={formatDate(proposal.votingEndTime)!}
Expand Down
2 changes: 1 addition & 1 deletion examples/chain-template/config/chains.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { chains } from 'chain-registry';
import osmosis from 'chain-registry/mainnet/osmosis/chain';

const chainNames = ['osmosistestnet', 'juno', 'stargaze'];
const chainNames = ['osmosistestnet', 'juno', 'stargaze', 'osmosis'];

export const chainOptions = chainNames.map(
(chainName) => chains.find((chain) => chain.chain_name === chainName)!
Expand Down
9 changes: 7 additions & 2 deletions examples/chain-template/hooks/asset-list/useAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,13 @@ export const useAssets = (chainName: string) => {
const isWithinLimit = ibcAssets.length <= MAX_TOKENS_TO_SHOW;
return isWithinLimit || topTokens.includes(asset.symbol);
})
.map((asset) => ({ denom: asset.base, amount: '0' }));

.map((asset) => ({ denom: asset.base, amount: '0' }))
.reduce((acc: { denom: string, amount: string }[], current) => {
if (!acc.some(balance => balance.denom === current.denom)) {
acc.push(current);
}
return acc;
}, []);
const finalAssets = [...(nativeAndIbcBalances ?? []), ...emptyBalances]
.map(({ amount, denom }) => {
const asset = getAssetByDenom(denom);
Expand Down
10 changes: 10 additions & 0 deletions examples/chain-template/utils/staking/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@ export const calcDollarValue = (
.decimalPlaces(2)
.toNumber();
};

export const toBaseAmount = (
num: string | number,
places: number
) => {
return new BigNumber(num)
.shiftedBy(places)
.integerValue(BigNumber.ROUND_DOWN)
.toString();
};
14 changes: 4 additions & 10 deletions examples/nft/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,14 @@
"locks": "npm run locks:remove && npm run locks:create",
"watch:codegen": "npx graphql-code-generator --config ./config/codegen.ts --watch"
},
"resolutions": {
"react": "18.2.0",
"react-dom": "18.2.0",
"@types/react": "18.0.25",
"@types/react-dom": "18.0.9"
},
"dependencies": {
"@chain-registry/types": "0.17.0",
"@chain-registry/types": "^0.16.0",
"@cosmjs/cosmwasm-stargate": "0.31.3",
"@cosmjs/stargate": "0.32.3",
"@cosmos-kit/react": "2.17.0",
"@emotion/react": "11.10.6",
"@emotion/styled": "11.10.6",
"@interchain-ui/react": "^1.23.29",
"@interchain-ui/react": "1.23.29",
"@interchain-ui/react-no-ssr": "^0.1.6",
"@tanstack/react-query": "4.32.0",
"bignumber.js": "9.1.0",
Expand All @@ -49,8 +43,8 @@
"@types/node": "^20.14.6",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"eslint": "8.56.0",
"eslint-config-next": "14.1.0",
"eslint": "8.57.0",
"eslint-config-next": "14.2.3",
"generate-lockfile": "0.0.12",
"typescript": "^5.1.6"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/nft/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function getLogo(from: Asset | Chain) {

export function getChainLogo(name: string) {
const chain = chains.find(chain => chain.chain_name === name)
return chain ? getLogo(chain) : null;
return chain ? getLogo(chain as any) : null;
}

export function getStargazeProfileLink(address: string | undefined) {
Expand Down
Loading

0 comments on commit ef1bcd1

Please sign in to comment.