Skip to content

Commit

Permalink
Don't expose sequenceWaasProvider and sequenceWaas on connector use g…
Browse files Browse the repository at this point in the history
…etProvider instead
  • Loading branch information
corbanbrook committed May 1, 2024
1 parent 63035a0 commit cb1769c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
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
Expand Up @@ -21,8 +21,6 @@ sequenceWaasWallet.type = 'sequence-waas' as const
export function sequenceWaasWallet(params: BaseSequenceWaasConnectorOptions) {
type Provider = SequenceWaasProvider
type Properties = {
sequenceWaas: SequenceWaaS
sequenceWaasProvider: SequenceWaasProvider
params: BaseSequenceWaasConnectorOptions
}
type StorageItem = {
Expand Down Expand Up @@ -67,8 +65,6 @@ export function sequenceWaasWallet(params: BaseSequenceWaasConnectorOptions) {
id: `sequence-waas`,
name: 'Sequence WaaS',
type: sequenceWaasWallet.type,
sequenceWaas,
sequenceWaasProvider,
params,

async setup() {
Expand Down
5 changes: 4 additions & 1 deletion packages/kit/src/hooks/useWaasConfirmationHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { commons } from '@0xsequence/core'
import { useState, useEffect } from 'react'
import { Deferred } from '../utils/deferred'
import { SequenceWaasProvider } from '@0xsequence/kit-connectors'

let _pendingConfirmation: Deferred<{ id: string; confirmed: boolean }> | undefined

Expand Down Expand Up @@ -35,13 +36,14 @@ export function useWaasConfirmationHandler(
return
}

const waasProvider = waasConnector.sequenceWaasProvider
const waasProvider = (await waasConnector.getProvider()) as SequenceWaasProvider

if (!waasProvider) {
return
}

waasProvider.requestConfirmationHandler = {
// @ts-ignore-next-line
confirmSignTransactionRequest(
id: string,
txs: commons.transaction.Transaction[],
Expand All @@ -52,6 +54,7 @@ export function useWaasConfirmationHandler(
_pendingConfirmation = pending
return pending.promise
},

confirmSignMessageRequest(id: string, message: string, chainId: number): Promise<{ id: string; confirmed: boolean }> {
const pending = new Deferred<{ id: string; confirmed: boolean }>()
setPendingRequestConfirmation({ id, type: 'signMessage', message, chainId })
Expand Down
9 changes: 6 additions & 3 deletions packages/kit/src/hooks/useWaasEmailAuth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from 'react'
import { ExtendedConnector } from '../utils'
import { SequenceWaasProvider } from '@0xsequence/kit-connectors'

export function useEmailAuth({ connector, onSuccess }: { connector?: ExtendedConnector; onSuccess: (idToken: string) => void }) {
if (!connector) {
Expand All @@ -22,7 +23,8 @@ export function useEmailAuth({ connector, onSuccess }: { connector?: ExtendedCon

try {
const connectorAny: any = connector
const { instance } = await connectorAny.sequenceWaas?.email.initiateAuth({ email })
const provider = (await connectorAny.getProvider()) as SequenceWaasProvider
const { instance } = await provider.sequenceWaas?.email.initiateAuth({ email })
setInstance(instance)
setEmail(email)
} catch (e: any) {
Expand All @@ -37,8 +39,9 @@ export function useEmailAuth({ connector, onSuccess }: { connector?: ExtendedCon

try {
const connectorAny: any = connector
const sessionHash = await connectorAny.sequenceWaas?.getSessionHash()
const { idToken } = await connectorAny.sequenceWaas?.email.finalizeAuth({ instance, answer, email, sessionHash })
const provider = (await connectorAny.getProvider()) as SequenceWaasProvider
const sessionHash = await provider.sequenceWaas?.getSessionHash()
const { idToken } = await provider.sequenceWaas?.email.finalizeAuth({ instance, answer, email, sessionHash })
onSuccess(idToken)
} catch (e: any) {
setError(e.message || 'Unknown error')
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/hooks/useWaasFeeOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Deferred } from '../utils/deferred'
import { Connector, useConnections } from 'wagmi'
import { FeeOption } from '@0xsequence/waas'
import { ethers } from 'ethers'
import { SequenceWaasProvider } from '@0xsequence/kit-connectors'

// null means it's native token
let _pendingFeeConfirmation: Deferred<{ id: string; feeTokenAddress?: string | null; confirmed: boolean }> | undefined
Expand Down Expand Up @@ -41,8 +42,7 @@ export function useWaasFeeOptions(): [
return
}

// @ts-ignore-next-line
const waasProvider = waasConnector.sequenceWaasProvider
const waasProvider = (await waasConnector.getProvider()) as SequenceWaasProvider

if (!waasProvider) {
return
Expand Down

0 comments on commit cb1769c

Please sign in to comment.