Skip to content

Commit 8aed165

Browse files
committed
authz code
1 parent 8963961 commit 8aed165

File tree

638 files changed

+161994
-0
lines changed

Some content is hidden

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

638 files changed

+161994
-0
lines changed

examples/authz/.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}

examples/authz/.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
/main
18+
19+
# misc
20+
.DS_Store
21+
*.pem
22+
23+
# debug
24+
npm-debug.log*
25+
yarn-debug.log*
26+
yarn-error.log*
27+
.pnpm-debug.log*
28+
29+
# local env files
30+
.env*.local
31+
32+
# vercel
33+
.vercel
34+
35+
# typescript
36+
*.tsbuildinfo
37+
next-env.d.ts

examples/authz/.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

examples/authz/CHANGELOG.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5+
6+
# 1.1.0 (2024-10-08)
7+
8+
9+
### Bug Fixes
10+
11+
* deps ([b2aa70b](https://github.com/cosmology-tech/create-cosmos-app/commit/b2aa70ba9ef34fd96954c033220ff160d2c8ece7))
12+
* old ci job yarn4 issues ([#182](https://github.com/cosmology-tech/create-cosmos-app/issues/182)) ([2bb19f7](https://github.com/cosmology-tech/create-cosmos-app/commit/2bb19f75fcc6ffaa4bcb63ecf071009d2f9d7e76))
13+
* rename telescope-authz to authz ([9ba95fd](https://github.com/cosmology-tech/create-cosmos-app/commit/9ba95fd9d2e23620b1997e87f780460602507d60))
14+
* try locks update script ([000aa5f](https://github.com/cosmology-tech/create-cosmos-app/commit/000aa5fc73faa0182a23f50a6402e8b2351a587c))
15+
* upgrade deps and fix multi chain dropdown ([eecbcaa](https://github.com/cosmology-tech/create-cosmos-app/commit/eecbcaad5e7729f00f9121250c04eb40d201ed80))
16+
17+
18+
19+
20+
21+
# 1.0.0 (2024-04-06)
22+
23+
24+
### Bug Fixes
25+
26+
* rename telescope-authz to authz ([e30689d](https://github.com/cosmology-tech/create-cosmos-app/commit/e30689d1ff5f5c42a1c962aecc8b568511e0d0c2))
27+
28+
29+
30+
31+
32+
## [0.0.4](https://github.com/cosmology-tech/create-cosmos-app/compare/@cosmology/[email protected]...@cosmology/[email protected]) (2024-01-20)
33+
34+
**Note:** Version bump only for package @cosmology/telescope-authz-example
35+
36+
37+
38+
39+
40+
## [0.0.3](https://github.com/cosmology-tech/create-cosmos-app/compare/@cosmology/[email protected]...@cosmology/[email protected]) (2024-01-20)
41+
42+
**Note:** Version bump only for package @cosmology/telescope-authz-example
43+
44+
45+
46+
47+
48+
## 0.0.2 (2024-01-19)
49+
50+
**Note:** Version bump only for package @cosmology/telescope-authz-example

examples/authz/README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
This is a Cosmos App project bootstrapped with [`create-cosmos-app`](https://github.com/cosmology-tech/create-cosmos-app).
2+
3+
## Getting Started
4+
5+
First, install the packages and run the development server:
6+
7+
```bash
8+
yarn && yarn dev
9+
```
10+
11+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
12+
13+
You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.
14+
15+
## Learn More
16+
17+
### Chain Registry
18+
19+
The npm package for the Official Cosmos chain registry. Get chain and token data for you application.
20+
21+
* https://github.com/cosmology-tech/chain-registry
22+
23+
### Cosmology Videos
24+
25+
Checkout more videos for how to use various frontend tooling in the Cosmos!
26+
27+
* https://cosmology.zone/learn
28+
29+
### Cosmos Kit
30+
31+
A wallet connector for the Cosmos ⚛️
32+
33+
* https://github.com/cosmology-tech/cosmos-kit
34+
35+
### Telescope
36+
37+
A "babel for the Cosmos", Telescope is a TypeScript Transpiler for Cosmos Protobufs. Telescope is used to generate libraries for Cosmos blockchains. Simply point to your protobuffer files and create developer-friendly Typescript libraries for teams to build on your blockchain.
38+
39+
* https://github.com/cosmology-tech/telescope
40+
41+
🎥 [Checkout the Telescope video playlist](https://www.youtube.com/watch?v=n82MsLe82mk&list=PL-lMkVv7GZwyQaK6bp6kMdOS5mzosxytC) to learn how to use `telescope`!
42+
43+
### CosmWasm TS Codegen
44+
45+
The quickest and easiest way to interact with CosmWasm Contracts. @cosmwasm/ts-codegen converts your CosmWasm smart contracts into dev-friendly TypeScript classes so you can focus on shipping code.
46+
47+
* https://github.com/CosmWasm/ts-codegen
48+
49+
🎥 [Checkout the CosmWasm/ts-codegen video playlist](https://www.youtube.com/watch?v=D_A5V2PfNLA&list=PL-lMkVv7GZwz1KO3jANwr5W4MoziruXwK) to learn how to use `ts-codegen`!
50+
51+
52+
## Learn More about Next.js
53+
54+
To learn more about Next.js, take a look at the following resources:
55+
56+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
57+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
58+
59+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
60+
61+
## Deploy on Vercel
62+
63+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
64+
65+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
66+
67+
## Related
68+
69+
Checkout these related projects:
70+
71+
* [@cosmology/telescope](https://github.com/cosmology-tech/telescope) Your Frontend Companion for Building with TypeScript with Cosmos SDK Modules.
72+
* [@cosmwasm/ts-codegen](https://github.com/CosmWasm/ts-codegen) Convert your CosmWasm smart contracts into dev-friendly TypeScript classes.
73+
* [chain-registry](https://github.com/cosmology-tech/chain-registry) Everything from token symbols, logos, and IBC denominations for all assets you want to support in your application.
74+
* [cosmos-kit](https://github.com/cosmology-tech/cosmos-kit) Experience the convenience of connecting with a variety of web3 wallets through a single, streamlined interface.
75+
* [create-cosmos-app](https://github.com/cosmology-tech/create-cosmos-app) Set up a modern Cosmos app by running one command.
76+
* [interchain-ui](https://github.com/cosmology-tech/interchain-ui) The Interchain Design System, empowering developers with a flexible, easy-to-use UI kit.
77+
* [starship](https://github.com/cosmology-tech/starship) Unified Testing and Development for the Interchain.
78+
79+
## Credits
80+
81+
🛠 Built by Cosmology — if you like our tools, please consider delegating to [our validator ⚛️](https://cosmology.zone/validator)
82+
83+
84+
## Disclaimer
85+
86+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED “AS IS”, AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
87+
88+
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// TODO fix type issues
2+
// @ts-nocheck
3+
4+
import { useState } from 'react';
5+
import { ChainName } from 'cosmos-kit';
6+
import { useChain } from '@cosmos-kit/react';
7+
import { Box, Button, Tabs, Text } from '@interchain-ui/react';
8+
9+
import { Grants } from './Grants';
10+
import { GrantModal } from './GrantModal';
11+
12+
export const AuthzSection = ({ chainName }: { chainName: ChainName }) => {
13+
const [isOpen, setIsOpen] = useState(false);
14+
const [activeTab, setActiveTab] = useState(0);
15+
const { address } = useChain(chainName);
16+
17+
if (!address) {
18+
return (
19+
<Text
20+
fontWeight="$semibold"
21+
fontSize="$lg"
22+
textAlign="center"
23+
color="$textSecondary"
24+
attributes={{ my: '$24' }}
25+
>
26+
Please connect your wallet to view and create grants
27+
</Text>
28+
);
29+
}
30+
31+
return (
32+
<Box mb="$18" minHeight="500px" display="flex" flexDirection="column">
33+
<Box
34+
display="flex"
35+
justifyContent="space-between"
36+
alignItems="center"
37+
mb="$16"
38+
>
39+
<Tabs
40+
tabs={[
41+
{
42+
label: 'Grants to me',
43+
content: null,
44+
},
45+
{
46+
label: 'Grants by me',
47+
content: null,
48+
},
49+
]}
50+
activeTab={activeTab}
51+
onActiveTabChange={(tabId) => setActiveTab(tabId)}
52+
attributes={{ width: '$min' }}
53+
/>
54+
<Button intent="tertiary" onClick={() => setIsOpen(true)}>
55+
Create Grant
56+
</Button>
57+
</Box>
58+
59+
<Grants
60+
chainName={chainName}
61+
role={activeTab === 0 ? 'grantee' : 'granter'}
62+
/>
63+
64+
<GrantModal
65+
isOpen={isOpen}
66+
onClose={() => setIsOpen(false)}
67+
chainName={chainName}
68+
/>
69+
</Box>
70+
);
71+
};
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// TODO fix type issues
2+
// @ts-nocheck
3+
4+
import { Dispatch, SetStateAction, useState } from 'react';
5+
import { Box, NumberField, SelectButton, Text } from '@interchain-ui/react';
6+
7+
import { useValidators } from '@/hooks';
8+
import { Permission, PermissionId } from '@/configs';
9+
import { SelectValidatorsModal } from './SelectValidatorsModal';
10+
import { AccessList } from './GrantModal';
11+
12+
// ==============================================
13+
14+
type SendCustomizationProps = {
15+
value: number | undefined;
16+
onChange: (value: string) => void;
17+
};
18+
19+
const SendCustomization = ({ value, onChange }: SendCustomizationProps) => {
20+
return (
21+
<NumberField
22+
placeholder="Spend Limit (Optional)"
23+
value={value}
24+
onInput={(e) => {
25+
// @ts-ignore
26+
onChange(e.target.value);
27+
}}
28+
formatOptions={{
29+
maximumFractionDigits: 6,
30+
}}
31+
/>
32+
);
33+
};
34+
35+
// ==============================================
36+
37+
type DelegateCustomizationProps = {
38+
value: number | undefined;
39+
onChange: (value: string) => void;
40+
chainName: string;
41+
accessList: AccessList;
42+
setAccessList: Dispatch<SetStateAction<AccessList>>;
43+
};
44+
45+
const DelegateCustomization = ({
46+
value,
47+
onChange,
48+
chainName,
49+
accessList,
50+
setAccessList,
51+
}: DelegateCustomizationProps) => {
52+
const [isOpen, setIsOpen] = useState(false);
53+
54+
const { data } = useValidators(chainName);
55+
56+
const validatorNames = data
57+
? accessList.addresses.map(
58+
(address) => data.find((v) => v.address === address)!.name
59+
)
60+
: [];
61+
62+
return (
63+
<>
64+
<NumberField
65+
placeholder="Max Tokens (Optional)"
66+
value={value}
67+
onInput={(e) => {
68+
// @ts-ignore
69+
onChange(e.target.value);
70+
}}
71+
formatOptions={{
72+
maximumFractionDigits: 6,
73+
}}
74+
/>
75+
<SelectButton
76+
placeholder="Select Validators (Optional)"
77+
onClick={() => setIsOpen(true)}
78+
/>
79+
<Box
80+
display={validatorNames.length > 0 ? 'block' : 'none'}
81+
mt="$2"
82+
px="$2"
83+
>
84+
<Text>
85+
<Text
86+
as="span"
87+
fontWeight="$semibold"
88+
color={
89+
accessList.type === 'allowList' ? '$textSuccess' : '$textDanger'
90+
}
91+
>
92+
{accessList.type === 'allowList' ? 'Allow List' : 'Deny List'}
93+
:&nbsp;
94+
</Text>
95+
{validatorNames.join(', ')}
96+
</Text>
97+
</Box>
98+
<SelectValidatorsModal
99+
chainName={chainName}
100+
accessList={accessList}
101+
setAccessList={setAccessList}
102+
isOpen={isOpen}
103+
onClose={() => setIsOpen(false)}
104+
/>
105+
</>
106+
);
107+
};
108+
109+
// ==============================================
110+
111+
type CustomizationFieldProps =
112+
| ({
113+
permissionType: typeof Permission['Send'];
114+
} & SendCustomizationProps)
115+
| ({
116+
permissionType: typeof Permission['Delegate'];
117+
} & DelegateCustomizationProps);
118+
119+
export const CustomizationField = ({
120+
permissionType,
121+
...rest
122+
}: CustomizationFieldProps): JSX.Element | null => {
123+
const fields: Partial<Record<PermissionId, JSX.Element | null>> = {
124+
send:
125+
permissionType === 'send' ? (
126+
<SendCustomization {...(rest as SendCustomizationProps)} />
127+
) : null,
128+
delegate:
129+
permissionType === 'delegate' ? (
130+
<DelegateCustomization {...(rest as DelegateCustomizationProps)} />
131+
) : null,
132+
};
133+
134+
return fields[permissionType] ?? null;
135+
};

0 commit comments

Comments
 (0)