Skip to content

Commit

Permalink
Fixing de/serialization of EthAuthProof and EthAuthSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
corbanbrook committed May 1, 2024
1 parent c2af918 commit 191d72e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/connectors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@0xsequence/auth": "^1.9.26",
"@0xsequence/provider": "^1.9.26",
"@0xsequence/waas": "^1.9.26",
"@0xsequence/waas-ethers": "^1.9.26",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { sequence } from '0xsequence'
import { ETHAuthProof } from '@0xsequence/auth'
import { LocalStorageKey, EthAuthSettings } from '@0xsequence/kit'

import { UserRejectedRequestError, getAddress } from 'viem'
Expand Down Expand Up @@ -43,9 +44,9 @@ export function sequenceWallet(params: BaseSequenceConnectorOptions) {
type Provider = sequence.provider.SequenceProvider
type Properties = { params: BaseSequenceConnectorOptions }
type StorageItem = {
[LocalStorageKey.EthAuthProof]: string
[LocalStorageKey.EthAuthProof]: ETHAuthProof
[LocalStorageKey.Theme]: string
[LocalStorageKey.EthAuthSettings]: string
[LocalStorageKey.EthAuthSettings]: EthAuthSettings
}

return createConnector<Provider, Properties, StorageItem>(config => ({
Expand All @@ -70,12 +71,11 @@ export function sequenceWallet(params: BaseSequenceConnectorOptions) {

if (!provider.isConnected()) {
const localStorageTheme = await config.storage?.getItem(LocalStorageKey.Theme)
const ethAuthSettingsRaw = await config.storage?.getItem(LocalStorageKey.EthAuthSettings)
const parseEthAuthSettings = (ethAuthSettingsRaw ? JSON.parse(ethAuthSettingsRaw) : {}) as EthAuthSettings
const ethAuthSettings = (await config.storage?.getItem(LocalStorageKey.EthAuthSettings)) ?? {}

const connectOptionsWithTheme = {
authorize: true,
...parseEthAuthSettings,
...ethAuthSettings,
...connect,
settings: {
theme: localStorageTheme || 'dark',
Expand All @@ -93,11 +93,11 @@ export function sequenceWallet(params: BaseSequenceConnectorOptions) {

const proofString = e.proof?.proofString
const proofTypedData = e.proof?.typedData
if (proofString) {
const jsonEthAuthProof = JSON.stringify({
if (proofString && proofTypedData) {
const jsonEthAuthProof: ETHAuthProof = {
proofString,
typedData: proofTypedData
})
}

await config.storage?.setItem(LocalStorageKey.EthAuthProof, jsonEthAuthProof)
}
Expand Down
9 changes: 6 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 191d72e

Please sign in to comment.