fix(margin trading): response parsing (#354)
This commit is contained in:
parent
be671efd64
commit
85bdb4b267
@ -2,16 +2,20 @@ export default function getTokenOutFromSwapResponse(
|
|||||||
response: BroadcastResult,
|
response: BroadcastResult,
|
||||||
denom: string,
|
denom: string,
|
||||||
): Coin {
|
): Coin {
|
||||||
if (response.result) {
|
try {
|
||||||
const rawLogs = JSON.parse(response.result.rawLogs)
|
if (response.result) {
|
||||||
const events = rawLogs[0].events
|
const rawLogs = JSON.parse(response.result.rawLogs)
|
||||||
const tokenSwappedEvent = events.find((e: { type: string }) => e.type === 'token_swapped')
|
const events = rawLogs[0].events
|
||||||
const tokensOutValue = tokenSwappedEvent.attributes.find(
|
const tokenSwappedEvent = events.find((e: { type: string }) => e.type === 'token_swapped')
|
||||||
(a: { key: string }) => a.key === 'tokens_out',
|
const tokensOutValue = tokenSwappedEvent.attributes.find(
|
||||||
).value
|
(a: { key: string }) => a.key === 'tokens_out',
|
||||||
const amount = tokensOutValue.split(denom)[0]
|
).value
|
||||||
|
const amount = tokensOutValue.split(denom)[0]
|
||||||
|
|
||||||
return { denom, amount }
|
return { denom, amount }
|
||||||
|
}
|
||||||
|
} catch (ex) {
|
||||||
|
console.error(ex)
|
||||||
}
|
}
|
||||||
|
|
||||||
return { denom: '', amount: '' }
|
return { denom: '', amount: '' }
|
||||||
|
Loading…
Reference in New Issue
Block a user