Skip to content

Commit

Permalink
fix(api-kit): Missing to parameter (#1058)
Browse files Browse the repository at this point in the history
  • Loading branch information
yagopv authored Nov 25, 2024
1 parent 920d159 commit e0317d5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/api-kit/src/SafeApiKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,28 @@ 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> {
if (data === '') {
throw new Error('Invalid data')
}

const dataDecoderRequest: { data: string; to?: string } = { data }

if (to) {
dataDecoderRequest.to = to
}

return sendRequest({
url: `${this.#txServiceBaseUrl}/v1/data-decoder/`,
method: HttpMethod.Post,
body: { data }
body: dataDecoderRequest
})
}

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 e0317d5

Please sign in to comment.