Skip to content

Commit

Permalink
Set weighting options on the xchain ACL
Browse files Browse the repository at this point in the history
  • Loading branch information
csillag committed Oct 3, 2024
1 parent 83f86a3 commit 73d028e
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions frontend/src/components/ACLs/xchain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
addMockValidation,
Choice,
DecisionWithReason,
deny,
denyWithReason,
useLabel,
useOneOfField,
Expand Down Expand Up @@ -35,6 +34,7 @@ import classes from './index.module.css'
import { BytesLike, getUint } from 'ethers'
import { ReactNode, useMemo } from 'react'
import { StringUtils } from '../../utils/string.utils'
import { FLAG_WEIGHT_LOG10, FLAG_WEIGHT_ONE } from '../../types'

export const xchain = defineACL({
value: 'acl_xchain',
Expand Down Expand Up @@ -244,17 +244,31 @@ export const xchain = defineACL({
{
value: 'weight_perWallet',
label: '1 vote per wallet',
enabled: deny('Coming soon'),
},
{
value: 'weight_perToken',
label: 'According to token distribution',
},
{
value: 'weight_perLog10Token',
label: 'According to log10(token distribution)',
},
],
hideDisabledChoices: designDecisions.hideDisabledSelectOptions,
disableIfOnlyOneVisibleChoice: designDecisions.disableSelectsWithOnlyOneVisibleOption,
} as const)

const weightToFlags = (selection: typeof voteWeighting.value): bigint => {
switch (selection) {
case 'weight_perWallet':
return FLAG_WEIGHT_ONE
case 'weight_perToken':
return 0n
case 'weight_perLog10Token':
return FLAG_WEIGHT_LOG10
}
}

return {
fields: [
chain,
Expand All @@ -271,10 +285,11 @@ export const xchain = defineACL({
contractAddress: contractAddress.value,
slotNumber: slotNumber.value,
blockHash: blockHash.value,
flags: weightToFlags(voteWeighting.value),
},
}
},
getAclOptions: async ({ chainId, contractAddress, slotNumber, blockHash }, updateStatus) => {
getAclOptions: async ({ chainId, contractAddress, slotNumber, blockHash, flags }, updateStatus) => {
const showStatus = updateStatus ?? ((message?: string | undefined) => console.log(message))
const rpc = xchainRPC(chainId)
showStatus('Getting block header RLP')
Expand Down Expand Up @@ -302,7 +317,7 @@ export const xchain = defineACL({
address: VITE_CONTRACT_ACL_STORAGEPROOF,
options,
},
flags: 0n,
flags,
}
},

Expand Down

0 comments on commit 73d028e

Please sign in to comment.