Include Update Admins action in Whitelist dashboard > Execute

This commit is contained in:
Serkan Reis 2023-03-09 00:24:15 +03:00
parent deb149809e
commit 3b378b2232
4 changed files with 69 additions and 9 deletions

View File

@ -33,6 +33,7 @@ export interface WhiteListInstance {
removeMembers: (memberList: string[]) => Promise<string>
updatePerAddressLimit: (limit: number) => Promise<string>
increaseMemberLimit: (limit: number) => Promise<string>
updateAdmins: (admins: string[]) => Promise<string>
}
export interface WhitelistMessages {
@ -42,6 +43,7 @@ export interface WhitelistMessages {
removeMembers: (memberList: string[]) => RemoveMembersMessage
updatePerAddressLimit: (limit: number) => UpdatePerAddressLimitMessage
increaseMemberLimit: (limit: number) => IncreaseMemberLimitMessage
updateAdmins: (admins: string[]) => UpdateAdminsMessage
}
export interface UpdateStartTimeMessage {
@ -62,6 +64,14 @@ export interface UpdateEndTimeMessage {
funds: Coin[]
}
export interface UpdateAdminsMessage {
sender: string
contract: string
msg: {
update_admins: { admins: string[] }
}
funds: Coin[]
}
export interface AddMembersMessage {
sender: string
contract: string
@ -170,6 +180,20 @@ export const WhiteList = (client: SigningCosmWasmClient, txSigner: string): Whit
return res.transactionHash
}
const updateAdmins = async (admins: string[]): Promise<string> => {
const res = await client.execute(
txSigner,
contractAddress,
{
update_admins: {
admins,
},
},
'auto',
)
return res.transactionHash
}
const removeMembers = async (memberList: string[]): Promise<string> => {
const res = await client.execute(
txSigner,
@ -199,6 +223,7 @@ export const WhiteList = (client: SigningCosmWasmClient, txSigner: string): Whit
contractAddress,
updateStartTime,
updateEndTime,
updateAdmins,
addMembers,
removeMembers,
updatePerAddressLimit,
@ -263,6 +288,17 @@ export const WhiteList = (client: SigningCosmWasmClient, txSigner: string): Whit
}
}
const updateAdmins = (admins: string[]) => {
return {
sender: txSigner,
contract: contractAddress,
msg: {
update_admins: { admins },
},
funds: [],
}
}
const removeMembers = (memberList: string[]) => {
return {
sender: txSigner,
@ -299,6 +335,7 @@ export const WhiteList = (client: SigningCosmWasmClient, txSigner: string): Whit
return {
updateStartTime,
updateEndTime,
updateAdmins,
addMembers,
removeMembers,
updatePerAddressLimit,

View File

@ -6,6 +6,7 @@ export type ExecuteType = typeof EXECUTE_TYPES[number]
export const EXECUTE_TYPES = [
'update_start_time',
'update_end_time',
'update_admins',
'add_members',
'remove_members',
'update_per_address_limit',
@ -29,6 +30,11 @@ export const EXECUTE_LIST: ExecuteListItem[] = [
name: 'Update End Time',
description: `Update the end time of the whitelist`,
},
{
id: 'update_admins',
name: 'Update Admins',
description: `Update the list of administrators for the whitelist`,
},
{
id: 'add_members',
name: 'Add Members',
@ -70,6 +76,7 @@ export type DispatchExecuteArgs = {
| { type: Select<'remove_members'>; members: string[] }
| { type: Select<'update_per_address_limit'>; limit: number }
| { type: Select<'increase_member_limit'>; limit: number }
| { type: Select<'update_admins'>; admins: string[] }
)
export const dispatchExecute = async (args: DispatchExecuteArgs) => {
@ -84,6 +91,9 @@ export const dispatchExecute = async (args: DispatchExecuteArgs) => {
case 'update_end_time': {
return messages.updateEndTime(args.timestamp)
}
case 'update_admins': {
return messages.updateAdmins(args.admins)
}
case 'add_members': {
return messages.addMembers(args.members)
}
@ -113,6 +123,9 @@ export const previewExecutePayload = (args: DispatchExecuteArgs) => {
case 'update_end_time': {
return messages(contract)?.updateEndTime(args.timestamp)
}
case 'update_admins': {
return messages(contract)?.updateAdmins(args.admins)
}
case 'add_members': {
return messages(contract)?.addMembers(args.members)
}

View File

@ -64,6 +64,7 @@ const WhitelistExecutePage: NextPage = () => {
const showLimitState = isEitherType(type, ['update_per_address_limit', 'increase_member_limit'])
const showTimestamp = isEitherType(type, ['update_start_time', 'update_end_time'])
const showMemberList = isEitherType(type, ['add_members', 'remove_members'])
const showAdminList = isEitherType(type, ['update_admins'])
const messages = useMemo(() => contract?.use(contractState.value), [contract, contractState.value])
const payload: DispatchExecuteArgs = {
@ -80,6 +81,13 @@ const WhitelistExecutePage: NextPage = () => {
.concat(memberList),
),
],
admins: [
...new Set(
addressListState.values
.map((a) => a.address.trim())
.filter((address) => address !== '' && isValidAddress(address.trim()) && address.startsWith('stars')),
),
] || [wallet.address],
}
const { isLoading, mutate } = useMutation(
async (event: FormEvent) => {
@ -146,21 +154,23 @@ const WhitelistExecutePage: NextPage = () => {
<InputDateTime minDate={new Date()} onChange={(date) => setTimestamp(date)} value={timestamp} />
</FormControl>
</Conditional>
<Conditional test={showMemberList}>
<Conditional test={showMemberList || showAdminList}>
<AddressList
entries={addressListState.entries}
isRequired
onAdd={addressListState.add}
onChange={addressListState.update}
onRemove={addressListState.remove}
subtitle="Enter the member addresses"
subtitle={type === 'update_admins' ? 'Enter the admin addresses' : 'Enter the member addresses'}
title="Addresses"
/>
<Conditional test={showMemberList}>
<Alert className="mt-8" type="info">
You may optionally choose a text file of additional member addresses.
</Alert>
<WhitelistUpload onChange={setMemberList} />
</Conditional>
</Conditional>
</div>
<div className="space-y-8">
<div className="relative">

View File

@ -85,12 +85,12 @@ const WhitelistInstantiatePage: NextPage = () => {
per_address_limit: perAddressLimitState.value,
member_limit: memberLimitState.value,
admins: [
...(new Set(
...new Set(
addressListState.values
.map((a) => a.address.trim())
.filter((address) => address !== '' && isValidAddress(address.trim()) && address.startsWith('stars')),
) || [wallet.address]),
],
),
] || [wallet.address],
admins_mutable: adminsMutable,
}
return toast.promise(contract.instantiate(1835, msg, 'Stargaze Whitelist Contract', wallet.address), {