Skip to content

Commit

Permalink
Code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
csillag committed Oct 17, 2024
1 parent 985d051 commit 9c47933
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions frontend/src/utils/poll.utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { AbiCoder, BytesLike, ContractTransactionReceipt, getAddress, getBytes, JsonRpcProvider, ParamType } from 'ethers'
import {
AbiCoder,
BytesLike,
ContractTransactionReceipt,
getAddress,
getBytes,
JsonRpcProvider,
ParamType,
} from 'ethers'

// XXX: cborg module types can cause error:
// There are types at './dapp-sidedao/frontend/node_modules/cborg/types/cborg.d.ts',
Expand Down Expand Up @@ -271,26 +279,23 @@ export const createPoll = async (
* @param receipt Receipt of the `close` or `destroy` transaction
* @param pollManager Instance of the poll manager
*/
async function detectGasRefundOnCompletion(
receipt: ContractTransactionReceipt,
pollManager: PollManager
) {
const iface = GaslessVoting__factory.createInterface();
const gvAddr = await pollManager.GASLESS_VOTER();
for( const log of receipt.logs ) {
if( log.address !== gvAddr ) {
continue;
async function detectGasRefundOnCompletion(receipt: ContractTransactionReceipt, pollManager: PollManager) {
const iface = GaslessVoting__factory.createInterface()
const gvAddr = await pollManager.GASLESS_VOTER()
for (const log of receipt.logs) {
if (log.address !== gvAddr) {
continue
}
const result = iface.parseLog({
topics: log.topics as string[],
data: log.data
});
if( result && result.name === 'GasWithdrawTransaction' ) {
const refundTx = await pollManager.runner?.provider?.broadcastTransaction(result.args[0]);
console.log('refundTx', refundTx);
refundTx?.wait().then((receipt) => {
console.log('Refund tx completed, receipt:', receipt);
});
data: log.data,
})
if (result && result.name === 'GasWithdrawTransaction') {
const refundTx = await pollManager.runner?.provider?.broadcastTransaction(result.args[0])
console.log('refundTx', refundTx)
refundTx?.wait().then(receipt => {
console.log('Refund tx completed, receipt:', receipt)
})
}
}
}
Expand All @@ -299,17 +304,17 @@ export const completePoll = async (eth: EthereumContext, pollManager: PollManage
await eth.switchNetwork() // ensure we're on the correct network first!
const tx = await pollManager.close(proposalId)
const receipt = await tx.wait()
if ( ! receipt || receipt!.status != 1) throw new Error('Complete ballot tx failed')
await detectGasRefundOnCompletion(receipt, pollManager);
if (!receipt || receipt!.status != 1) throw new Error('Complete ballot tx failed')
await detectGasRefundOnCompletion(receipt, pollManager)
}

// Destroying the poll will automatically close it first
export const destroyPoll = async (eth: EthereumContext, pollManager: PollManager, proposalId: string) => {
await eth.switchNetwork() // ensure we're on the correct network first!
const tx = await pollManager.destroy(proposalId)
const receipt = await tx.wait()
if ( ! receipt || receipt!.status != 1) throw new Error('Destroy poll tx failed')
await detectGasRefundOnCompletion(receipt, pollManager);
if (!receipt || receipt!.status != 1) throw new Error('Destroy poll tx failed')
await detectGasRefundOnCompletion(receipt, pollManager)
}

export type PollPermissions = {
Expand Down

0 comments on commit 9c47933

Please sign in to comment.