-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: transaction note from tx origin (#2223)
- Loading branch information
Showing
11 changed files
with
94 additions
and
0 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
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
54 changes: 54 additions & 0 deletions
54
...outes/transactions/mappers/multisig-transactions/multisig-transaction-note.mapper.spec.ts
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import { multisigTransactionBuilder } from '@/domain/safe/entities/__tests__/multisig-transaction.builder'; | ||
import { MultisigTransactionNoteMapper } from '@/routes/transactions/mappers/multisig-transactions/multisig-transaction-note.mapper'; | ||
|
||
const mapper = new MultisigTransactionNoteMapper(); | ||
|
||
describe('Multisig Transaction note mapper (Unit)', () => { | ||
it('should parse transaction `origin` and return a note', () => { | ||
const noteText = faker.lorem.sentence(); | ||
const transaction = multisigTransactionBuilder() | ||
.with( | ||
'origin', | ||
JSON.stringify({ name: JSON.stringify({ note: noteText }) }), | ||
) | ||
.build(); | ||
|
||
const note = mapper.mapTxNote(transaction); | ||
|
||
expect(note).toBe(noteText); | ||
}); | ||
|
||
it('should return undefined if `origin` is not a valid JSON', () => { | ||
const transaction = multisigTransactionBuilder() | ||
.with('origin', 'invalid-json') | ||
.build(); | ||
|
||
const note = mapper.mapTxNote(transaction); | ||
|
||
expect(note).toBeNull(); | ||
}); | ||
|
||
it('should return undefined if `origin` does not contain a note', () => { | ||
const transaction = multisigTransactionBuilder() | ||
.with( | ||
'origin', | ||
JSON.stringify({ name: faker.word.noun(), url: faker.internet.url() }), | ||
) | ||
.build(); | ||
|
||
const note = mapper.mapTxNote(transaction); | ||
|
||
expect(note).toBeNull(); | ||
}); | ||
|
||
it('should return undefined if `origin` is null', () => { | ||
const transaction = multisigTransactionBuilder() | ||
.with('origin', null) | ||
.build(); | ||
|
||
const note = mapper.mapTxNote(transaction); | ||
|
||
expect(note).toBeNull(); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
src/routes/transactions/mappers/multisig-transactions/multisig-transaction-note.mapper.ts
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { MultisigTransaction } from '@/domain/safe/entities/multisig-transaction.entity'; | ||
|
||
@Injectable() | ||
export class MultisigTransactionNoteMapper { | ||
mapTxNote(transaction: MultisigTransaction): string | null { | ||
if (transaction.origin) { | ||
try { | ||
const origin = JSON.parse(transaction.origin); | ||
const parsedName = origin.name && JSON.parse(String(origin.name)); | ||
if (typeof parsedName.note === 'string') { | ||
return parsedName.note; | ||
} | ||
} catch { | ||
// Ignore, no note | ||
} | ||
} | ||
return null; | ||
} | ||
} |
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