This repository has been archived by the owner on Mar 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #462 from AztecProtocol/fix/sdk-event-service
Fix sdk EventService and some minor issues
- Loading branch information
Showing
20 changed files
with
172 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 27 additions & 2 deletions
29
packages/extension/src/background/services/EventService/utils/note/createBulkNotes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,31 @@ | ||
import { | ||
warnLog, | ||
} from '~/utils/log'; | ||
import Note from '~/background/database/models/note'; | ||
|
||
import NoteService from '~/background/services/NoteService'; | ||
import Web3Service from '~/helpers/Web3Service'; | ||
|
||
export default async function createBulkNotes(notes, networkId) { | ||
return Note.bulkAdd(notes, { networkId }); | ||
let created; | ||
try { | ||
created = await Note.bulkAdd(notes, { networkId }); | ||
} catch (e) { | ||
// TODO - some of the notes might be valid, create them individually | ||
warnLog('Failed to create notes in indexedDB', e); | ||
return null; | ||
} | ||
|
||
if (created && created.length) { | ||
const { | ||
address, | ||
} = Web3Service.account; | ||
|
||
NoteService.addNotes( | ||
networkId, | ||
address, | ||
notes.filter(({ owner }) => owner === address), | ||
); | ||
} | ||
|
||
return created; | ||
} |
30 changes: 28 additions & 2 deletions
30
packages/extension/src/background/services/EventService/utils/note/createNote.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,32 @@ | ||
import { | ||
warnLog, | ||
} from '~/utils/log'; | ||
import Note from '~/background/database/models/note'; | ||
|
||
import NoteService from '~/background/services/NoteService'; | ||
import Web3Service from '~/helpers/Web3Service'; | ||
|
||
export default async function createNote(note, networkId) { | ||
return Note.add(note, { networkId }); | ||
let newNote; | ||
try { | ||
newNote = await Note.add(note, { networkId }); | ||
} catch (e) { | ||
warnLog('Failed to create a note in indexedDB', e); | ||
return null; | ||
} | ||
|
||
if (newNote) { | ||
const { | ||
address, | ||
} = Web3Service.account; | ||
|
||
if (newNote.owner === address) { | ||
NoteService.addNotes( | ||
networkId, | ||
address, | ||
[note], | ||
); | ||
} | ||
} | ||
|
||
return newNote; | ||
} |
35 changes: 33 additions & 2 deletions
35
packages/extension/src/background/services/EventService/utils/note/updateBulkNotes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,37 @@ | ||
import { | ||
warnLog, | ||
} from '~/utils/log'; | ||
import Note from '~/background/database/models/note'; | ||
|
||
import NoteService from '~/background/services/NoteService'; | ||
import Web3Service from '~/helpers/Web3Service'; | ||
|
||
export default async function updateBulkNotes(notes, networkId) { | ||
return Promise.all(notes.map(note => Note.update(note, { networkId }))); | ||
const updatedNotes = []; | ||
|
||
await Promise.all( | ||
notes.map(async (note) => { | ||
let updated; | ||
try { | ||
updated = await Note.update(note, { networkId }); | ||
updatedNotes.push(note); | ||
} catch (e) { | ||
warnLog('Failed to update note in indexedDB', e); | ||
} | ||
return updated; | ||
}), | ||
); | ||
|
||
if (updatedNotes.length) { | ||
const { | ||
address, | ||
} = Web3Service.account; | ||
|
||
NoteService.addNotes( | ||
networkId, | ||
address, | ||
updatedNotes.filter(({ owner }) => owner === address), | ||
); | ||
} | ||
|
||
return updatedNotes; | ||
} |
28 changes: 26 additions & 2 deletions
28
packages/extension/src/background/services/EventService/utils/note/updateNote.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,30 @@ | ||
import { | ||
warnLog, | ||
} from '~/utils/log'; | ||
import Note from '~/background/database/models/note'; | ||
|
||
import NoteService from '~/background/services/NoteService'; | ||
import Web3Service from '~/helpers/Web3Service'; | ||
|
||
export default async function updateNote(note, networkId) { | ||
return Note.update(note, { networkId }); | ||
let updated; | ||
try { | ||
updated = await Note.update(note, { networkId }); | ||
} catch (e) { | ||
warnLog('Failed to update note in indexedDB', e); | ||
return null; | ||
} | ||
|
||
if (updated) { | ||
const { | ||
address, | ||
} = Web3Service.account; | ||
|
||
NoteService.addNotes( | ||
networkId, | ||
address, | ||
[note], | ||
); | ||
} | ||
|
||
return updated; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.