From 1cfffdd048c820eb5c8c2f130f47da7ade7f5745 Mon Sep 17 00:00:00 2001 From: Kristof Csillag Date: Fri, 4 Oct 2024 01:46:02 +0200 Subject: [PATCH] Define ACL address as a simple field --- frontend/src/components/ACLs/allowAll.ts | 3 +-- frontend/src/components/ACLs/allowList.ts | 3 +-- frontend/src/components/ACLs/common.ts | 5 ++++- frontend/src/components/ACLs/tokenHolder.tsx | 3 +-- frontend/src/components/ACLs/xchain.tsx | 7 +++---- frontend/src/pages/CreatePollPage/useCreatePollForm.ts | 2 +- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/frontend/src/components/ACLs/allowAll.ts b/frontend/src/components/ACLs/allowAll.ts index f27d809..0709114 100644 --- a/frontend/src/components/ACLs/allowAll.ts +++ b/frontend/src/components/ACLs/allowAll.ts @@ -4,6 +4,7 @@ import { denyWithReason, useOneOfField } from '../InputFields' export const allowAll = defineACL({ value: 'acl_allowAll', + address: VITE_CONTRACT_ACL_ALLOWALL, label: 'Everybody', costEstimation: 0.1, useConfiguration: active => { @@ -26,8 +27,6 @@ export const allowAll = defineACL({ } }, - getAclAddress: () => VITE_CONTRACT_ACL_ALLOWALL, - getAclOptions: () => ({ data: '0x', // Empty bytes is passed options: { allowAll: true }, diff --git a/frontend/src/components/ACLs/allowList.ts b/frontend/src/components/ACLs/allowList.ts index e63cd2f..30c4dd7 100644 --- a/frontend/src/components/ACLs/allowList.ts +++ b/frontend/src/components/ACLs/allowList.ts @@ -14,6 +14,7 @@ const splitAddresses = (addressSoup: string): string[] => export const allowList = defineACL({ value: 'acl_allowList', + address: VITE_CONTRACT_ACL_VOTERALLOWLIST, label: 'Address Whitelist', costEstimation: 0.1, description: 'You can specify a list of addresses that are allowed to vote.', @@ -68,8 +69,6 @@ export const allowList = defineACL({ } }, - getAclAddress: () => VITE_CONTRACT_ACL_VOTERALLOWLIST, - getAclOptions: props => { if (!props.addresses) throw new Error('Internal errors: parameter mismatch, addresses missing.') return { diff --git a/frontend/src/components/ACLs/common.ts b/frontend/src/components/ACLs/common.ts index 7a61a45..92d03c7 100644 --- a/frontend/src/components/ACLs/common.ts +++ b/frontend/src/components/ACLs/common.ts @@ -20,7 +20,10 @@ export type ACL = Ch */ useConfiguration: (selected: boolean) => { fields: FieldConfiguration; values: ConfigInputValues } - getAclAddress: () => string + /** + * The address of the ACL contract to use + */ + address: string /** * Compose the ACL options when creating a poll diff --git a/frontend/src/components/ACLs/tokenHolder.tsx b/frontend/src/components/ACLs/tokenHolder.tsx index c030128..cf081e9 100644 --- a/frontend/src/components/ACLs/tokenHolder.tsx +++ b/frontend/src/components/ACLs/tokenHolder.tsx @@ -12,6 +12,7 @@ import { FLAG_WEIGHT_LOG10, FLAG_WEIGHT_ONE } from '../../types' export const tokenHolder = defineACL({ value: 'acl_tokenHolder', + address: VITE_CONTRACT_ACL_TOKENHOLDER, costEstimation: 0.2, label: `Active Token or NFT balance on ${configuredNetworkName}`, description: @@ -111,8 +112,6 @@ export const tokenHolder = defineACL({ } }, - getAclAddress: () => VITE_CONTRACT_ACL_TOKENHOLDER, - getAclOptions: props => { if (!props.tokenAddress) throw new Error('Internal errors: parameter mismatch, addresses missing.') return { diff --git a/frontend/src/components/ACLs/xchain.tsx b/frontend/src/components/ACLs/xchain.tsx index 1bc1f63..7f651fc 100644 --- a/frontend/src/components/ACLs/xchain.tsx +++ b/frontend/src/components/ACLs/xchain.tsx @@ -38,6 +38,7 @@ import { FLAG_WEIGHT_LOG10, FLAG_WEIGHT_ONE } from '../../types' export const xchain = defineACL({ value: 'acl_xchain', + address: VITE_CONTRACT_ACL_STORAGEPROOF, label: 'Token Snapshot voting', costEstimation: 0.2, description: 'take a snapshot of token or NFT balances from another chain', @@ -290,8 +291,6 @@ export const xchain = defineACL({ } }, - getAclAddress: () => VITE_CONTRACT_ACL_STORAGEPROOF, - getAclOptions: async ({ chainId, contractAddress, slotNumber, blockHash, flags }, updateStatus) => { const showStatus = updateStatus ?? ((message?: string | undefined) => console.log(message)) const rpc = xchainRPC(chainId) @@ -333,8 +332,8 @@ export const xchain = defineACL({ const { xchain: { c: chainId, s: slot }, } = xChainOptions - const tokenAddress = hexlify(xChainOptions.xchain.a); - const blockHash = hexlify(xChainOptions.xchain.b); + const tokenAddress = hexlify(xChainOptions.xchain.a) + const blockHash = hexlify(xChainOptions.xchain.b) const provider = xchainRPC(chainId) const chainDefinition = getChainDefinition(chainId) diff --git a/frontend/src/pages/CreatePollPage/useCreatePollForm.ts b/frontend/src/pages/CreatePollPage/useCreatePollForm.ts index ab73ef9..d8ddaf3 100644 --- a/frontend/src/pages/CreatePollPage/useCreatePollForm.ts +++ b/frontend/src/pages/CreatePollPage/useCreatePollForm.ts @@ -340,7 +340,7 @@ export const useCreatePollForm = () => { description: description.value, answers: answers.value, isHidden: hidden.value, - aclAddress: currentAcl.getAclAddress(), + aclAddress: currentAcl.address, aclData, aclOptions, pollFlags,