-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
async function initOPFS() { | ||
const root = await navigator.storage.getDirectory(); | ||
Check warning on line 2 in packages/app/src/systems/Core/utils/opfs.ts GitHub Actions / TestRETRY 1: Connections › should do the entire connection management flow
Check warning on line 2 in packages/app/src/systems/Core/utils/opfs.ts GitHub Actions / TestRETRY 2: Connections › should do the entire connection management flow
Check warning on line 2 in packages/app/src/systems/Core/utils/opfs.ts GitHub Actions / TestRETRY 4: Connections › should do the entire connection management flow
Check failure on line 2 in packages/app/src/systems/Core/utils/opfs.ts GitHub Actions / TestConnections › should do the entire connection management flow
Check warning on line 2 in packages/app/src/systems/Core/utils/opfs.ts GitHub Actions / TestRETRY 1: importAccountMachine › import › should be able to import from private key
Check warning on line 2 in packages/app/src/systems/Core/utils/opfs.ts GitHub Actions / TestRETRY 1: importAccountMachine › import › should throw a error if private key is already imported
Check warning on line 2 in packages/app/src/systems/Core/utils/opfs.ts GitHub Actions / TestRETRY 1: ConnectionEdit › should disconnect account
Check warning on line 2 in packages/app/src/systems/Core/utils/opfs.ts GitHub Actions / TestRETRY 2: ConnectionEdit › should disconnect account
Check warning on line 2 in packages/app/src/systems/Core/utils/opfs.ts GitHub Actions / TestRETRY 3: ConnectionEdit › should disconnect account
Check failure on line 2 in packages/app/src/systems/Core/utils/opfs.ts GitHub Actions / TestConnectionEdit › should disconnect account
Check warning on line 2 in packages/app/src/systems/Core/utils/opfs.ts GitHub Actions / TestRETRY 1: addAccountMachine › add › should be able to add an account
|
||
return root; | ||
} | ||
|
||
// biome-ignore lint/suspicious/noExplicitAny: <explanation> | ||
export async function saveToOPFS(data: any) { | ||
if ( | ||
!data.accounts?.length || | ||
!data.vaults?.length || | ||
!data.networks?.length | ||
) { | ||
return; | ||
} | ||
|
||
console.log('saving data to opfs', data); | ||
const root = await initOPFS(); | ||
const fileHandle = await root.getFileHandle('backup.json', { create: true }); | ||
const writable = await fileHandle.createWritable(); | ||
await writable.write(JSON.stringify(data)); | ||
await writable.close(); | ||
} | ||
|
||
export async function readFromOPFS() { | ||
const root = await initOPFS(); | ||
try { | ||
const fileHandle = await root.getFileHandle('backup.json'); | ||
const file = await fileHandle.getFile(); | ||
const text = await file.text(); | ||
return JSON.parse(text); | ||
} catch (_) { | ||
// Create empty backup file if it doesn't exist | ||
return {}; | ||
} | ||
} |