-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef87061
commit 43867de
Showing
18 changed files
with
580 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
examples/chain-template/components/contract/BackButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Box, Icon, Text } from '@interchain-ui/react'; | ||
|
||
export const BackButton = ({ onClick }: { onClick: () => void }) => { | ||
return ( | ||
<Box | ||
display="flex" | ||
gap="6px" | ||
alignItems="center" | ||
cursor="pointer" | ||
attributes={{ onClick }} | ||
> | ||
<Icon | ||
name="arrowRightLine" | ||
attributes={{ transform: 'rotate(180deg)' }} | ||
/> | ||
<Text color="$text" fontSize="16px" fontWeight="500"> | ||
Back | ||
</Text> | ||
</Box> | ||
); | ||
}; |
18 changes: 18 additions & 0 deletions
18
examples/chain-template/components/contract/CreateFromUpload.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Box } from '@interchain-ui/react'; | ||
import { UploadContract } from './UploadContract'; | ||
import { BackButton } from './BackButton'; | ||
|
||
type CreateFromUploadProps = { | ||
onBack: () => void; | ||
}; | ||
|
||
export const CreateFromUpload = ({ onBack }: CreateFromUploadProps) => { | ||
return ( | ||
<Box position="relative"> | ||
<Box position="absolute" top="0" left="0"> | ||
<BackButton onClick={onBack} /> | ||
</Box> | ||
<UploadContract show /> | ||
</Box> | ||
); | ||
}; |
47 changes: 47 additions & 0 deletions
47
examples/chain-template/components/contract/InputField.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Box, Text } from '@interchain-ui/react'; | ||
|
||
const InputField = ({ | ||
children, | ||
title, | ||
required = false, | ||
}: { | ||
title: string; | ||
children: React.ReactNode; | ||
required?: boolean; | ||
}) => { | ||
return ( | ||
<Box display="flex" flexDirection="column" gap="10px"> | ||
<Text color="$blackAlpha600" fontSize="16px" fontWeight="700"> | ||
{title}{' '} | ||
{required && ( | ||
<Text as="span" color="$red600" fontSize="16px"> | ||
* | ||
</Text> | ||
)} | ||
</Text> | ||
{children} | ||
</Box> | ||
); | ||
}; | ||
|
||
const Description = ({ | ||
children, | ||
intent = 'default', | ||
}: { | ||
children: string; | ||
intent?: 'error' | 'default'; | ||
}) => { | ||
return ( | ||
<Text | ||
color={intent === 'error' ? '$red600' : '$blackAlpha500'} | ||
fontSize="12px" | ||
fontWeight="500" | ||
> | ||
{children} | ||
</Text> | ||
); | ||
}; | ||
|
||
InputField.Description = Description; | ||
|
||
export { InputField }; |
154 changes: 154 additions & 0 deletions
154
examples/chain-template/components/contract/InstantiatePermissionRadio.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import { useEffect } from 'react'; | ||
import { Box, Text, TextField } from '@interchain-ui/react'; | ||
import { HiOutlineTrash } from 'react-icons/hi'; | ||
import { LuPlus } from 'react-icons/lu'; | ||
import { cosmwasm } from 'interchain-query'; | ||
import { useChain } from '@cosmos-kit/react'; | ||
import { GrGroup } from 'react-icons/gr'; | ||
import { MdOutlineHowToVote } from 'react-icons/md'; | ||
import { MdChecklistRtl } from 'react-icons/md'; | ||
|
||
import { Button, Radio, RadioGroup } from '../common'; | ||
import { InputField } from './InputField'; | ||
import { validateChainAddress } from '@/utils'; | ||
import { useChainStore } from '@/contexts'; | ||
|
||
export const AccessType = cosmwasm.wasm.v1.AccessType; | ||
|
||
export type Permission = (typeof AccessType)[keyof typeof AccessType]; | ||
|
||
export type Address = { | ||
value: string; | ||
isValid?: boolean; | ||
errorMsg?: string | null; | ||
}; | ||
|
||
type Props = { | ||
addresses: Address[]; | ||
permission: Permission; | ||
setAddresses: (addresses: Address[]) => void; | ||
setPermission: (permission: Permission) => void; | ||
}; | ||
|
||
export const InstantiatePermissionRadio = ({ | ||
addresses, | ||
permission, | ||
setAddresses, | ||
setPermission, | ||
}: Props) => { | ||
const { selectedChain } = useChainStore(); | ||
const { chain } = useChain(selectedChain); | ||
|
||
const onAddAddress = () => { | ||
setAddresses([...addresses, { value: '' }]); | ||
}; | ||
|
||
const onDeleteAddress = (index: number) => { | ||
const newAddresses = [...addresses]; | ||
newAddresses.splice(index, 1); | ||
setAddresses(newAddresses); | ||
}; | ||
|
||
const onAddressChange = (value: string, index: number) => { | ||
const newAddresses = [...addresses]; | ||
newAddresses[index].value = value; | ||
setAddresses(newAddresses); | ||
}; | ||
|
||
useEffect(() => { | ||
if (permission !== AccessType.ACCESS_TYPE_ANY_OF_ADDRESSES) return; | ||
|
||
const newAddresses = addresses.map((addr, index) => { | ||
const isDuplicate = | ||
addresses.findIndex((a) => a.value === addr.value) !== index; | ||
|
||
const errorMsg = isDuplicate | ||
? 'Address already exists' | ||
: validateChainAddress(addr.value, chain.bech32_prefix); | ||
|
||
return { | ||
...addr, | ||
isValid: !!addr.value && !errorMsg, | ||
errorMsg: addr.value ? errorMsg : null, | ||
}; | ||
}); | ||
|
||
setAddresses(newAddresses); | ||
}, [JSON.stringify(addresses.map((addr) => addr.value))]); | ||
|
||
return ( | ||
<> | ||
<RadioGroup | ||
direction="row" | ||
name="instantiate_permission" | ||
value={permission.toString()} | ||
onChange={(val) => { | ||
setPermission(Number(val) as Permission); | ||
}} | ||
> | ||
<Radio | ||
icon={<GrGroup size="22px" />} | ||
value={AccessType.ACCESS_TYPE_EVERYBODY.toString()} | ||
> | ||
Everybody | ||
</Radio> | ||
<Radio | ||
icon={<MdOutlineHowToVote size="22px" />} | ||
value={AccessType.ACCESS_TYPE_NOBODY.toString()} | ||
> | ||
Governance only | ||
</Radio> | ||
<Radio | ||
icon={<MdChecklistRtl size="22px" />} | ||
value={AccessType.ACCESS_TYPE_ANY_OF_ADDRESSES.toString()} | ||
> | ||
Approved addresses | ||
</Radio> | ||
</RadioGroup> | ||
|
||
{permission === AccessType.ACCESS_TYPE_ANY_OF_ADDRESSES && ( | ||
<InputField title="Addresses"> | ||
{addresses.map(({ value, errorMsg }, index) => ( | ||
<Box display="flex" gap="10px" key={index}> | ||
<Box width="$full"> | ||
<TextField | ||
id={`address-${index}`} | ||
value={value} | ||
onChange={(e) => onAddressChange(e.target.value, index)} | ||
attributes={{ width: '100%' }} | ||
intent={errorMsg ? 'error' : 'default'} | ||
autoComplete="off" | ||
/> | ||
{errorMsg && ( | ||
<Text | ||
color="$red600" | ||
fontSize="12px" | ||
fontWeight="500" | ||
wordBreak="break-all" | ||
attributes={{ mt: '6px' }} | ||
> | ||
{errorMsg} | ||
</Text> | ||
)} | ||
</Box> | ||
<Button | ||
leftIcon={<HiOutlineTrash size="18px" />} | ||
px="10px" | ||
disabled={addresses.length === 1} | ||
onClick={() => onDeleteAddress(index)} | ||
/> | ||
</Box> | ||
))} | ||
<Button | ||
leftIcon={<LuPlus size="20px" />} | ||
width="$fit" | ||
px="10px" | ||
onClick={onAddAddress} | ||
> | ||
Add More Address | ||
</Button> | ||
</InputField> | ||
)} | ||
</> | ||
); | ||
}; |
Oops, something went wrong.