Skip to content

Commit

Permalink
Change browser behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljscript committed Aug 2, 2024
1 parent d4d01ea commit 69a1884
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,28 @@ export const BrowserProvider = ({
initialState?: Partial<BrowserState>
}) => {
const {
selected: {wallet},
selected: {wallet, network},
} = useWalletManager()

const walletId = wallet?.id
const storageId = wallet?.id != null ? `${wallet.id}-${network}` : null

const [browserState, dispatch] = React.useReducer(browserReducer, {...defaultState, ...initialState})

React.useEffect(() => {
if (walletId === undefined) return
memoryStorage.set(walletId, browserState)
if (storageId === null) return
memoryStorage.set(storageId, browserState)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [browserState])

React.useEffect(() => {
if (walletId === undefined) return
const state = memoryStorage.get(walletId)
if (storageId === null) return
const state = memoryStorage.get(storageId)
if (state) {
dispatch({type: BrowserActionType.SetState, state})
} else {
dispatch({type: BrowserActionType.SetState, state: {...defaultState, ...initialState}})
}
}, [walletId, initialState])
}, [storageId, initialState])

const actions = React.useRef<BrowserActions>({
addTab: (url, id) => {
Expand Down
1 change: 1 addition & 0 deletions packages/dapp-connector/src/manager.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {DappListResponse} from './adapters/api'

export const managerMock: DappConnectorManager = {
chainId: 1,
walletId: 'walletId',
getDAppList(): Promise<DappListResponse> {
return Promise.resolve(mockedDAppList)
},
Expand Down

0 comments on commit 69a1884

Please sign in to comment.