import { BigNumber } from '@ethersproject/bignumber' ; import { makeTxConfigFromTx , toTxReceipt } from '@helpers' ; import { ExtendedAsset , ExtendedContact , ITxConfig , ITxReceipt , ITxStatus , ITxType , Network , NetworkId , StoreAccount , TAddress } from '@types' ; import { ITxFaucetResult } from './types' ; export const possibleSolution = ( solution ) => { return /^[a-zA-Z0-9]{4}$/ . test ( solution ) ; } ; const getNetworkByLowercaseId = ( id , networks = [ ] ) : Network => { const capitalizedNetworkId = ( id . charAt ( 0 ) . toUpperCase ( ) + id . slice ( 1 ) ) as NetworkId ; return networks . find ( ( network ) => network . id === capitalizedNetworkId ) as Network ; } ; export const makeTxConfig = ( txResult , networks , assets , accounts , getContactByAddressAndNetworkId ) : ITxConfig => { const network = getNetworkByLowercaseId ( txResult . network , networks ) ; const senderContact = getContactByAddressAndNetworkId ( txResult . from , network . id ) ! ; const newTxResult = { ... txResult , gasLimit : BigNumber . from ( txResult . gasLimit ) , maxPriorityFeePerGas : BigNumber . from ( txResult . maxPriorityFeePerGas ) , maxFeePerGas : BigNumber . from ( txResult . maxFeePerGas ) , type : 2 , value : BigNumber . from ( txResult . value ) } ; const txConfig = { ... makeTxConfigFromTx ( newTxResult , assets , network , accounts ) , senderAccount : ( senderContact as unknown ) as StoreAccount } ; return txConfig ; } ; export const makeTxReceipt = ( txResult , txConfig ) : ITxReceipt => { const txReceipt = toTxReceipt ( txResult . hash , ITxStatus . PENDING ) ( ITxType . FAUCET , txConfig ) ; return txReceipt ; } ;