Skip to content

Commit

Permalink
(WIP) useWaasRevalidation hook
Browse files Browse the repository at this point in the history
  • Loading branch information
SamueleA committed May 1, 2024
1 parent 3825a46 commit f68266a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
4 changes: 3 additions & 1 deletion examples/react-waas/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './App.css'
import { useOpenConnectModal, useWaasFeeOptions } from '@0xsequence/kit'
import { useOpenConnectModal, useWaasFeeOptions, useWaasRevalidation } from '@0xsequence/kit'
import {
useAccount,
useChainId,
Expand Down Expand Up @@ -105,6 +105,8 @@ export const App = () => {
}
}, [txnData])

useWaasRevalidation()

// Fee options are required when txn is not gas sponsored (not needed on testnets)
const [pendingFeeOptionConfirmation, confirmPendingFeeOption, rejectPendingFeeOption] = useWaasFeeOptions()

Expand Down
1 change: 1 addition & 0 deletions packages/connectors/src/connectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export * from './mock'
export * from './sequence'
export * from './twitch'
export * from './walletConnect'
export * from './wagmiConnectors'
export * from './types'
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SequenceWaaS, SequenceConfig, ExtendedSequenceConfig, Transaction, FeeOption } from '@0xsequence/waas'
import { LocalStorageKey } from '@0xsequence/kit'
import { TransactionRejectedRpcError, UserRejectedRequestError, getAddress } from 'viem'
import { createConnector } from 'wagmi'
import { createConnector, CreateConnectorFn } from 'wagmi'
import { ethers } from 'ethers'
import { v4 as uuidv4 } from 'uuid'
import { sequence } from '0xsequence'
Expand All @@ -18,7 +18,9 @@ export type BaseSequenceWaasConnectorOptions = SequenceConfig & SequenceWaasConn

sequenceWaasWallet.type = 'sequence-waas' as const

export function sequenceWaasWallet(params: BaseSequenceWaasConnectorOptions) {
export type SequenceWaasConnector = CreateConnectorFn<SequenceWaasProvider, any, {}>

export function sequenceWaasWallet(params: BaseSequenceWaasConnectorOptions): SequenceWaasConnector {
type Provider = SequenceWaasProvider
type Properties = { sequenceWaas: SequenceWaaS; sequenceWaasProvider: SequenceWaasProvider }

Expand Down
1 change: 1 addition & 0 deletions packages/kit/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './useOpenConnectModal'
export * from './useTheme'
export * from './useWalletSettings'
export * from './useWaasFeeOptions'
export * from './useWaasRevalidation'
39 changes: 39 additions & 0 deletions packages/kit/src/hooks/useWaasRevalidation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { SequenceWaaS } from '@0xsequence/waas'
import { commons } from '@0xsequence/core'
import { ethers } from 'ethers'
import { useState, useEffect } from 'react'
import { Deferred } from '../utils/deferred'
import { useAccount } from 'wagmi'
import type { SequenceWaasConnector } from '@0xsequence/kit-connectors'


export function useWaasRevalidation(
// waasConnector?: any
) {
const { connector } = useAccount()

const waasConnector = connector?.type === 'sequence-waas' ? connector : undefined


useEffect(() => {
async function setup() {
if (!waasConnector) {
return
}

// @ts-ignore-next-line
const sequenceWaas: SequenceWaaS = waasConnector.sequenceWaas

if (!sequenceWaas) {
return
}

sequenceWaas.onValidationRequired(() => {
console.log('TODO: requires validation!')
})
}
setup()
}, [waasConnector])

return
}

0 comments on commit f68266a

Please sign in to comment.