2023-09-22 19:57:35 +03:00
|
|
|
import { connectionMetaKey } from '../../src/connection/meta'
|
2023-08-02 08:13:19 +03:00
|
|
|
import { ConnectionType } from '../../src/connection/types'
|
2023-04-26 00:24:57 +03:00
|
|
|
import { UserState } from '../../src/state/user/reducer'
|
|
|
|
|
2023-08-02 08:13:19 +03:00
|
|
|
export const CONNECTED_WALLET_USER_STATE: Partial<UserState> = { selectedWallet: ConnectionType.INJECTED }
|
2023-07-07 00:01:13 +03:00
|
|
|
|
|
|
|
export const DISCONNECTED_WALLET_USER_STATE: Partial<UserState> = { selectedWallet: undefined }
|
2023-08-16 20:56:06 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This sets the initial value of the "user" slice in IndexedDB.
|
|
|
|
* Other persisted slices are not set, so they will be filled with their respective initial values
|
|
|
|
* when the app runs.
|
|
|
|
*/
|
2023-09-20 22:31:54 +03:00
|
|
|
export function setInitialUserState(win: Cypress.AUTWindow, state: UserState) {
|
|
|
|
// Selected wallet should also be reflected in localStorage, so that eager connections work.
|
|
|
|
if (state.selectedWallet) {
|
2023-09-22 19:57:35 +03:00
|
|
|
win.localStorage.setItem(
|
|
|
|
connectionMetaKey,
|
|
|
|
JSON.stringify({
|
|
|
|
type: state.selectedWallet,
|
|
|
|
})
|
|
|
|
)
|
2023-09-20 22:31:54 +03:00
|
|
|
}
|
2023-08-16 20:56:06 +03:00
|
|
|
|
2023-09-20 22:31:54 +03:00
|
|
|
win.indexedDB.deleteDatabase('redux')
|
2023-08-16 20:56:06 +03:00
|
|
|
const dbRequest = win.indexedDB.open('redux')
|
|
|
|
dbRequest.onsuccess = function () {
|
|
|
|
const db = dbRequest.result
|
|
|
|
const transaction = db.transaction('keyvaluepairs', 'readwrite')
|
|
|
|
const store = transaction.objectStore('keyvaluepairs')
|
|
|
|
store.put(
|
|
|
|
{
|
2023-09-20 22:31:54 +03:00
|
|
|
user: state,
|
2023-08-16 20:56:06 +03:00
|
|
|
},
|
|
|
|
'persist:interface'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
dbRequest.onupgradeneeded = function () {
|
|
|
|
const db = dbRequest.result
|
|
|
|
db.createObjectStore('keyvaluepairs')
|
|
|
|
}
|
|
|
|
}
|