Skip to content

Commit

Permalink
Add to parameter to the decodeData function
Browse files Browse the repository at this point in the history
  • Loading branch information
yagopv committed Nov 22, 2024
1 parent 32b408b commit 9dfa2a8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/api-kit/src/SafeApiKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,21 @@ class SafeApiKit {
/**
* Decodes the specified Safe transaction data.
*
* @param data - The Safe transaction data
* @param data - The Safe transaction data. '0x' prefixed hexadecimal string.
* @param to - The address of the receiving contract. If provided, the decoded data will be more accurate, as in case of an ABI collision the Safe Transaction Service would know which ABI to use
* @returns The transaction data decoded
* @throws "Invalid data"
* @throws "Not Found"
* @throws "Ensure this field has at least 1 hexadecimal chars (not counting 0x)."
*/
async decodeData(data: string): Promise<any> {
async decodeData(data: string, to: string = ''): Promise<any> {

Check warning on line 125 in packages/api-kit/src/SafeApiKit.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type
if (data === '') {
throw new Error('Invalid data')
}
return sendRequest({
url: `${this.#txServiceBaseUrl}/v1/data-decoder/`,
method: HttpMethod.Post,
body: { data }
body: { data, to }
})
}

Expand Down
18 changes: 18 additions & 0 deletions packages/api-kit/tests/e2e/decodeData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,22 @@ describe('decodeData', () => {
})
)
})

it('should decode the data and allow to specify the receiving contract', async () => {
const data = '0x610b592500000000000000000000000090F8bf6A479f320ead074411a4B0e7944Ea8c9C1'
const to = '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1'
const decodedData = await safeApiKit.decodeData(data, to)
chai.expect(JSON.stringify(decodedData)).to.be.equal(
JSON.stringify({
method: 'enableModule',
parameters: [
{
name: 'module',
type: 'address',
value: '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1'
}
]
})
)
})
})

0 comments on commit 9dfa2a8

Please sign in to comment.