Skip to content

Commit

Permalink
update error handling on pick winners
Browse files Browse the repository at this point in the history
  • Loading branch information
AnonJon committed May 25, 2023
1 parent b3be529 commit 57d1f92
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState, useEffect } from 'react'
import { Button, Text, Flex, Heading, Link } from '@chakra-ui/react'
import { ExternalLinkIcon } from '@chakra-ui/icons'
import { useNetwork } from 'wagmi'

import { pickWinners } from '@ui/features/raffleDetail'
Expand All @@ -26,13 +27,12 @@ export const PickWinners = ({ id, reset, asyncManager, store }) => {
</Heading>
<Text>Successfully picked winners for raffle id `{id}`.</Text>
{txHash && (
<Text>
<Link
href={`${chain.blockExplorers.default.url}/tx/${txHash}/#eventlogs`}
isExternal>
View VRF Request
</Link>
</Text>
<Link
href={`${chain.blockExplorers.default.url}/tx/${txHash}/#eventlog`}
isExternal
color="blue.500">
View VRF Request <ExternalLinkIcon mx="2px" />
</Link>
)}
<Flex mt="2" justify="end">
<Button variant="default" onClick={() => reset(store)}>
Expand Down
15 changes: 13 additions & 2 deletions client/packages/ui/src/features/raffleDetail/methods/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,17 @@ export const pickWinners = async ({ id, asyncManager, success, txHash }) => {
* and (b) the owner can withdraw excess link amount after the raffle has been resolved.
*/
asyncManager.start()

let update: boolean
const raffle = await getRaffle({ id, asyncManager, update }, true)
if (typeof raffle === 'object') {
const totalWinners = raffle.totalWinners as number
const totalPar = raffle.contestantsAddresses as string[]
if (totalWinners > totalPar.length) {
throw new Error(
`Total winners cannot be greater than total participants`
)
}
}
const value = BigNumber.from('100000000000000000') // 0.1 LINK
const payload: contracts.ResolveRaffleParams = { id, value }
const { wait, hash } = await contracts.resolveRaffle(payload)
Expand All @@ -105,7 +115,8 @@ export const pickWinners = async ({ id, asyncManager, success, txHash }) => {
success(true)
return true
} catch (error) {
asyncManager.fail(`Could not pick winners for raffle id \`${id}\``)
asyncManager.fail(`
Could not pick winners for raffle id \`${id}\` \n${error}`)
return false
}
}
Expand Down

0 comments on commit 57d1f92

Please sign in to comment.