Skip to content

Commit d96708c

Browse files
authored
Merge pull request #130 from cosmology-tech/refactor/folder-structure
refactor folder structure
2 parents 66314ee + b492f09 commit d96708c

File tree

170 files changed

+7474
-4729
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+7474
-4729
lines changed

examples/asset-list/hooks/queries/useTotalAssets.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ export const useTotalAssets = (chainName: string) => {
124124
queriesData;
125125

126126
const stakedTotal = delegations
127-
.map((coin) => calcCoinDollarValue(prices, coin))
127+
?.map((coin) => calcCoinDollarValue(prices, coin))
128128
.reduce((total, cur) => total.plus(cur), zero)
129129
.toString();
130130

131131
const balancesTotal = allBalances
132-
.filter(({ denom }) => !denom.startsWith('gamm') && prices[denom])
132+
?.filter(({ denom }) => !denom.startsWith('gamm') && prices[denom])
133133
.map((coin) => calcCoinDollarValue(prices, coin))
134134
.reduce((total, cur) => total.plus(cur), zero)
135135
.toString();

examples/asset-list/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,19 @@
3434
"chakra-react-select": "4.4.3",
3535
"fast-fuzzy": "1.12.0",
3636
"framer-motion": "9.0.7",
37-
"long": "5.2.1",
3837
"next": "12.2.5",
3938
"osmo-query": "16.5.1",
4039
"react": "18.2.0",
4140
"react-dom": "18.2.0",
42-
"react-icons": "4.6.0"
41+
"react-icons": "4.6.0",
42+
"react-no-ssr": "1.1.0"
4343
},
4444
"devDependencies": {
4545
"@tanstack/react-query-devtools": "4.32.0",
4646
"@types/node": "18.11.9",
4747
"@types/react": "18.0.25",
4848
"@types/react-dom": "18.0.9",
49+
"@types/react-no-ssr": "1.1.3",
4950
"eslint": "8.28.0",
5051
"eslint-config-next": "13.0.5",
5152
"generate-lockfile": "0.0.12",
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
import { AssetListSection, Layout, WalletSection } from '@/components';
2-
import { useEffect, useState } from 'react';
1+
import { useState } from 'react';
2+
import NoSSR from 'react-no-ssr';
33
import { ChainName } from '@cosmos-kit/core';
4+
import { AssetListSection, Layout, WalletSection } from '@/components';
45

56
export default function MultiChain() {
67
const [chainName, setChainName] = useState<ChainName>();
7-
const [content, setContent] = useState<JSX.Element>();
8-
9-
useEffect(() => {
10-
if (!chainName) return;
11-
setContent(<AssetListSection chainName={chainName} />);
12-
}, [chainName]);
138

149
return (
1510
<Layout>
@@ -18,7 +13,7 @@ export default function MultiChain() {
1813
providedChainName={chainName}
1914
setChainName={setChainName}
2015
/>
21-
{content}
16+
<NoSSR>{chainName && <AssetListSection chainName={chainName} />}</NoSSR>
2217
</Layout>
2318
);
2419
}
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1+
import NoSSR from 'react-no-ssr';
12
import { defaultChainName } from '@/config';
2-
import { AssetListSection, Layout } from '@/components';
3-
import { WalletSection } from '@/components/wallet';
4-
import { useState, useEffect } from 'react';
3+
import { AssetListSection, Layout, WalletSection } from '@/components';
54

65
export default function SingleChain() {
7-
const [content, setContent] = useState<JSX.Element>();
8-
9-
useEffect(() => {
10-
setContent(<AssetListSection chainName={defaultChainName} />);
11-
}, []);
12-
136
return (
147
<Layout>
158
<WalletSection isMultiChain={false} />
16-
{content}
9+
<NoSSR>
10+
<AssetListSection chainName={defaultChainName} />
11+
</NoSSR>
1712
</Layout>
1813
);
1914
}

examples/ibc-transfer/__tests__/index.test.js

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { denomToAsset, denomToExponent, getIbcInfo } from '../utils';
2+
3+
describe('denomToAsset()', () => {
4+
it('should return OSMO', () => {
5+
const denom =
6+
'ibc/ED07A3391A112B175915CD8FAF43A2DA8E4790EDE12566649D0C2F97716B8518';
7+
const symbol = denomToAsset('juno', denom)?.symbol;
8+
expect(symbol).toBe('OSMO');
9+
});
10+
11+
it('should return ATOM', () => {
12+
const denom =
13+
'ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9';
14+
const symbol = denomToAsset('juno', denom)?.symbol;
15+
expect(symbol).toBe('ATOM');
16+
});
17+
18+
it('should return JUNO', () => {
19+
const denom = 'ujuno';
20+
const symbol = denomToAsset('juno', denom)?.symbol;
21+
expect(symbol).toBe('JUNO');
22+
});
23+
24+
it('should return undefined', () => {
25+
const denom = 'ujuno';
26+
const symbol = denomToAsset('osmosis', denom)?.symbol;
27+
expect(symbol).toBeUndefined();
28+
});
29+
30+
it('should return ION', () => {
31+
const denom = 'uion';
32+
const symbol = denomToAsset('osmosis', denom)?.symbol;
33+
expect(symbol).toBe('ION');
34+
});
35+
});
36+
37+
describe('denomToExponent()', () => {
38+
it('should return 6', () => {
39+
const denom =
40+
'ibc/F6B367385300865F654E110976B838502504231705BAC0849B0651C226385885';
41+
expect(denomToExponent('juno', denom)).toBe(6);
42+
});
43+
44+
it('should return 18', () => {
45+
const denom =
46+
'ibc/7E4A6EEFA0425CF99DE169A586D9BADF39C40153194CD6784BF8C9F6123BF5D0';
47+
expect(denomToExponent('juno', denom)).toBe(18);
48+
});
49+
50+
it('should return 6', () => {
51+
const denom = 'ujuno';
52+
expect(denomToExponent('juno', denom)).toBe(6);
53+
});
54+
55+
it('should return 6', () => {
56+
const denom = 'uion';
57+
expect(denomToExponent('osmosis', denom)).toBe(6);
58+
});
59+
});
60+
61+
describe('getIbcInfo()', () => {
62+
it('should return channel-2', () => {
63+
expect(getIbcInfo('agoric', 'crescent').sourceChannel).toBe('channel-2');
64+
});
65+
66+
it('should return channel-11', () => {
67+
expect(getIbcInfo('crescent', 'agoric').sourceChannel).toBe('channel-11');
68+
});
69+
});

examples/ibc-transfer/components/features.tsx renamed to examples/ibc-transfer/components/common/Footer.tsx

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
import { LinkIcon } from '@chakra-ui/icons';
21
import {
32
Box,
3+
Divider,
4+
Grid,
45
Heading,
5-
Icon,
6-
Link,
7-
Stack,
86
Text,
9-
useColorModeValue
7+
Stack,
8+
Link,
9+
Icon,
10+
useColorModeValue,
1011
} from '@chakra-ui/react';
11-
import { FeatureProps } from './types';
12+
import { dependencies, products } from '../../config';
13+
import { LinkIcon } from '@chakra-ui/icons';
1214

13-
export const Product = ({ title, text, href }: FeatureProps) => {
15+
interface IFeature {
16+
title: string;
17+
text: string;
18+
href: string;
19+
}
20+
21+
const Product = ({ title, text, href }: IFeature) => {
1422
return (
1523
<Link href={href} target="_blank" _hover={{ textDecoration: 'none' }}>
1624
<Stack
@@ -29,7 +37,7 @@ export const Product = ({ title, text, href }: FeatureProps) => {
2937
boxShadow: useColorModeValue(
3038
'0 2px 5px #bca5e9',
3139
'0 0 3px rgba(150, 75, 213, 0.8), 0 3px 8px -2px rgba(175, 89, 246, 0.9)'
32-
)
40+
),
3341
}}
3442
>
3543
<Heading fontSize="xl">{title}&ensp;&rarr;</Heading>
@@ -39,7 +47,7 @@ export const Product = ({ title, text, href }: FeatureProps) => {
3947
);
4048
};
4149

42-
export const Dependency = ({ title, text, href }: FeatureProps) => {
50+
const Dependency = ({ title, text, href }: IFeature) => {
4351
return (
4452
<Link href={href} target="_blank" _hover={{ textDecoration: 'none' }}>
4553
<Stack
@@ -56,7 +64,7 @@ export const Dependency = ({ title, text, href }: FeatureProps) => {
5664
boxShadow: useColorModeValue(
5765
'0 2px 5px #ccc',
5866
'0 1px 3px #727272, 0 2px 12px -2px #2f2f2f'
59-
)
67+
),
6068
}}
6169
>
6270
<Box color={useColorModeValue('primary.500', 'primary.200')}>
@@ -77,3 +85,46 @@ export const Dependency = ({ title, text, href }: FeatureProps) => {
7785
</Link>
7886
);
7987
};
88+
89+
export const Footer = () => {
90+
return (
91+
<>
92+
<Grid
93+
templateColumns={{
94+
md: 'repeat(2, 1fr)',
95+
lg: 'repeat(3, 1fr)',
96+
}}
97+
gap={8}
98+
mb={14}
99+
>
100+
{products.map((product) => (
101+
<Product key={product.title} {...product}></Product>
102+
))}
103+
</Grid>
104+
<Grid templateColumns={{ md: '1fr 1fr' }} gap={8} mb={20}>
105+
{dependencies.map((dependency) => (
106+
<Dependency key={dependency.title} {...dependency}></Dependency>
107+
))}
108+
</Grid>
109+
<Box mb={3}>
110+
<Divider />
111+
</Box>
112+
<Stack
113+
isInline={true}
114+
spacing={1}
115+
justifyContent="center"
116+
opacity={0.5}
117+
fontSize="sm"
118+
>
119+
<Text>Built with</Text>
120+
<Link
121+
href="https://cosmology.tech/"
122+
target="_blank"
123+
rel="noopener noreferrer"
124+
>
125+
Cosmology
126+
</Link>
127+
</Stack>
128+
</>
129+
);
130+
};
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import {
2+
Box,
3+
Heading,
4+
Text,
5+
Button,
6+
Flex,
7+
Icon,
8+
useColorMode,
9+
useColorModeValue,
10+
} from '@chakra-ui/react';
11+
import { BsFillMoonStarsFill, BsFillSunFill } from 'react-icons/bs';
12+
13+
const stacks = ['CosmosKit', 'Next.js'];
14+
15+
export const Header = () => {
16+
const { colorMode, toggleColorMode } = useColorMode();
17+
18+
return (
19+
<>
20+
<Flex justifyContent="end" mb={4}>
21+
<Button variant="outline" px={0} onClick={toggleColorMode}>
22+
<Icon
23+
as={colorMode === 'light' ? BsFillMoonStarsFill : BsFillSunFill}
24+
/>
25+
</Button>
26+
</Flex>
27+
<Box textAlign="center">
28+
<Heading
29+
as="h1"
30+
fontSize={{ base: '3xl', sm: '4xl', md: '5xl' }}
31+
fontWeight="extrabold"
32+
mb={3}
33+
>
34+
Create Cosmos App
35+
</Heading>
36+
<Heading
37+
as="h1"
38+
fontWeight="bold"
39+
fontSize={{ base: '2xl', sm: '3xl', md: '4xl' }}
40+
>
41+
<Text as="span">Welcome to&nbsp;</Text>
42+
<Text
43+
as="span"
44+
color={useColorModeValue('primary.500', 'primary.200')}
45+
>
46+
{stacks.join(' + ')}
47+
</Text>
48+
</Heading>
49+
</Box>
50+
</>
51+
);
52+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Head from 'next/head';
2+
import { Container } from '@chakra-ui/react';
3+
import { Header } from './Header';
4+
import { Footer } from './Footer';
5+
6+
export const Layout = ({ children }: { children: React.ReactNode }) => {
7+
return (
8+
<Container maxW="5xl" py={10}>
9+
<Head>
10+
<title>Create Cosmos App</title>
11+
<meta name="description" content="Generated by create cosmos app" />
12+
<link rel="icon" href="/favicon.ico" />
13+
</Head>
14+
<Header />
15+
{children}
16+
<Footer />
17+
</Container>
18+
);
19+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './Layout';

0 commit comments

Comments
 (0)