From 3df595005fd632c191e26a2cd4434d0f04bf74da Mon Sep 17 00:00:00 2001 From: Arthur Marinho Date: Wed, 9 Mar 2022 15:30:23 -0300 Subject: [PATCH] filtering out unsupported transfer types (#256) --- .../src/components/SpGetTxList/SpGetTxList.vue | 3 ++- packages/vue/src/composables/useTxs.ts | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/vue/src/components/SpGetTxList/SpGetTxList.vue b/packages/vue/src/components/SpGetTxList/SpGetTxList.vue index 93197eee..6b0f99c7 100644 --- a/packages/vue/src/components/SpGetTxList/SpGetTxList.vue +++ b/packages/vue/src/components/SpGetTxList/SpGetTxList.vue @@ -82,7 +82,7 @@ export default defineComponent({ // composables let { address } = useAddress({ $s }) - let { pager, normalize, newTxs } = await useTxs({ + let { pager, normalize, newTxs, filterSupportedTypes } = await useTxs({ $s, opts: { order: 'desc', realTime: true } }) @@ -90,6 +90,7 @@ export default defineComponent({ // computed let list = computed(() => { return pager.value.page.value + .filter(filterSupportedTypes) .map(normalize) .slice(0, state.listSize) .sort((a, b) => b.height - a.height) diff --git a/packages/vue/src/composables/useTxs.ts b/packages/vue/src/composables/useTxs.ts index 2f7726df..29eb75bc 100644 --- a/packages/vue/src/composables/useTxs.ts +++ b/packages/vue/src/composables/useTxs.ts @@ -12,6 +12,7 @@ import useAPIPagination, { } from './useAPIPagination' type Response = { + filterSupportedTypes: (tx: object) => boolean normalize: (tx: object) => TxForUI pager: ComputedRef newTxs: Ref @@ -55,6 +56,12 @@ export default async function ({ total: Number(pagination.total) } } + let filterSupportedTypes = (tx: any) => { + let isIBC = (tx.body.messages[0]['@type'] as string).includes('ibc.applications.transfer.v1.MsgTransfer') + let isBankTransfer = (tx.body.messages[0]['@type'] as string).includes('cosmos.bank.v1beta1.MsgSend') + + return isBankTransfer || isIBC + } let normalize = (tx: any): TxForUI => { let findOutDir = (tx: TxForUI): TxDirection => { let dir: TxDirection = 'in' @@ -71,7 +78,8 @@ export default async function ({ let normalized: any = {} - let isIBC = (tx.body.messages[0]['@type'] as string).includes('ibc') + let isIBC = (tx.body.messages[0]['@type'] as string).includes('ibc.applications.transfer.v1.MsgTransfer') + let isBankTransfer = (tx.body.messages[0]['@type'] as string).includes('cosmos.bank.v1beta1.MsgSend') if (isIBC) { let decodeIBC = (dataAs64: string): object => @@ -83,7 +91,7 @@ export default async function ({ normalized.receiver = decoded.receiver normalized.amount = { amount: decoded.amount, denom: decoded.denom } normalized.height = Number(tx.height) - } else { + } else if (isBankTransfer) { normalized.sender = tx.body.messages[0].from_address normalized.receiver = tx.body.messages[0].to_address normalized.amount = tx.body.messages[0].amount @@ -177,6 +185,7 @@ export default async function ({ return { newTxs, pager: recvAndSentPager, - normalize + normalize, + filterSupportedTypes } }