mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
c11888f287
See [`no-empty-function`](https://eslint.org/docs/rules/no-empty-function) for more information. This change enables `no-empty-function` and fixes the issues raised by the rule.
66 lines
1.5 KiB
JavaScript
66 lines
1.5 KiB
JavaScript
function delay (time) {
|
|
return new Promise((resolve) => setTimeout(resolve, time))
|
|
}
|
|
|
|
async function loadFromMock3Box (key) {
|
|
const res = await window.fetch('http://localhost:8889?key=' + key)
|
|
const text = await res.text()
|
|
return text.length ? JSON.parse(text) : null
|
|
}
|
|
|
|
async function saveToMock3Box (key, newDataAtKey) {
|
|
const res = await window.fetch('http://localhost:8889', {
|
|
method: 'POST',
|
|
body: JSON.stringify({
|
|
key,
|
|
data: newDataAtKey,
|
|
}),
|
|
})
|
|
|
|
return res.text()
|
|
}
|
|
|
|
class Mock3Box {
|
|
static openBox (address) {
|
|
this.address = address
|
|
return Promise.resolve({
|
|
onSyncDone: (cb) => {
|
|
setTimeout(cb, 200)
|
|
},
|
|
openSpace: async (spaceName, config) => {
|
|
const { onSyncDone } = config
|
|
this.spaceName = spaceName
|
|
|
|
setTimeout(onSyncDone, 150)
|
|
|
|
await delay(50)
|
|
|
|
return {
|
|
private: {
|
|
get: async (key) => {
|
|
await delay(50)
|
|
const res = await loadFromMock3Box(`${this.address}-${this.spaceName}-${key}`)
|
|
return res
|
|
},
|
|
set: async (key, data) => {
|
|
await saveToMock3Box(`${this.address}-${this.spaceName}-${key}`, data)
|
|
await delay(50)
|
|
return null
|
|
},
|
|
},
|
|
}
|
|
},
|
|
logout: () => undefined,
|
|
})
|
|
}
|
|
|
|
static async getConfig (address) {
|
|
const backup = await loadFromMock3Box(`${address}-metamask-metamaskBackup`)
|
|
return backup
|
|
? { spaces: { metamask: {} } }
|
|
: {}
|
|
}
|
|
}
|
|
|
|
module.exports = Mock3Box
|