fix(margin trading): response parsing (#354)

This commit is contained in:
Yusuf Seyrek 2023-08-09 15:53:32 +03:00 committed by GitHub
parent be671efd64
commit 85bdb4b267
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,16 +2,20 @@ export default function getTokenOutFromSwapResponse(
response: BroadcastResult,
denom: string,
): Coin {
if (response.result) {
const rawLogs = JSON.parse(response.result.rawLogs)
const events = rawLogs[0].events
const tokenSwappedEvent = events.find((e: { type: string }) => e.type === 'token_swapped')
const tokensOutValue = tokenSwappedEvent.attributes.find(
(a: { key: string }) => a.key === 'tokens_out',
).value
const amount = tokensOutValue.split(denom)[0]
try {
if (response.result) {
const rawLogs = JSON.parse(response.result.rawLogs)
const events = rawLogs[0].events
const tokenSwappedEvent = events.find((e: { type: string }) => e.type === 'token_swapped')
const tokensOutValue = tokenSwappedEvent.attributes.find(
(a: { key: string }) => a.key === 'tokens_out',
).value
const amount = tokensOutValue.split(denom)[0]
return { denom, amount }
return { denom, amount }
}
} catch (ex) {
console.error(ex)
}
return { denom: '', amount: '' }