useTypedFeatureVote.ts
1 import { useEthers } from '@usedapp/core' 2 import { useCallback } from 'react' 3 import { useContracts } from './useContracts' 4 import { BigNumber } from 'ethers' 5 import { TypedFeature } from '../models/TypedData' 6 7 export function useTypedFeatureVote() { 8 const { chainId } = useEthers() 9 const { featuredVotingContract } = useContracts() 10 11 const getTypedFeatureVote = useCallback( 12 (data: [string, string, BigNumber, BigNumber]) => { 13 return { 14 types: { 15 EIP712Domain: [ 16 { name: 'name', type: 'string' }, 17 { name: 'version', type: 'string' }, 18 { name: 'chainId', type: 'uint256' }, 19 { name: 'verifyingContract', type: 'address' }, 20 ], 21 Vote: [ 22 { name: 'voter', type: 'address' }, 23 { name: 'community', type: 'bytes' }, 24 { name: 'sntAmount', type: 'uint256' }, 25 { name: 'timestamp', type: 'uint256' }, 26 ], 27 }, 28 primaryType: 'Vote', 29 domain: { 30 name: 'Featured Voting Contract', 31 version: '1', 32 chainId: chainId, 33 verifyingContract: featuredVotingContract.address, 34 }, 35 message: { 36 voter: data[0], 37 community: data[1], 38 sntAmount: data[2].toHexString(), 39 timestamp: data[3].toHexString(), 40 }, 41 } as TypedFeature 42 }, 43 [chainId, featuredVotingContract.address], 44 ) 45 46 return { getTypedFeatureVote } 47 }