Skip to content

Commit

Permalink
filtering out unsupported transfer types (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
marinhoarthur authored Mar 9, 2022
1 parent 743cc29 commit 3df5950
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/vue/src/components/SpGetTxList/SpGetTxList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,15 @@ 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 }
})
// computed
let list = computed<TxForUI[]>(() => {
return pager.value.page.value
.filter(filterSupportedTypes)
.map(normalize)
.slice(0, state.listSize)
.sort((a, b) => b.height - a.height)
Expand Down
15 changes: 12 additions & 3 deletions packages/vue/src/composables/useTxs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import useAPIPagination, {
} from './useAPIPagination'

type Response = {
filterSupportedTypes: (tx: object) => boolean
normalize: (tx: object) => TxForUI
pager: ComputedRef<Pager>
newTxs: Ref<number>
Expand Down Expand Up @@ -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'
Expand All @@ -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 =>
Expand All @@ -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
Expand Down Expand Up @@ -177,6 +185,7 @@ export default async function ({
return {
newTxs,
pager: recvAndSentPager,
normalize
normalize,
filterSupportedTypes
}
}

0 comments on commit 3df5950

Please sign in to comment.