Skip to content

Commit

Permalink
chore: contract transaction transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasRalee committed Sep 4, 2024
1 parent ea651d7 commit f7c2512
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 110 deletions.
49 changes: 38 additions & 11 deletions layer/components/QRCode.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
<script setup lang="ts">
import { useQRCode } from '@vueuse/integrations/useQRCode'
<script lang="ts" setup>
import QRCodeVue3 from 'qrcode-vue3'
import { injLogoBase64 } from './../data/token'
const props = defineProps({
text: {
type: String,
required: true
}
})
const qrcode = useQRCode(props.text)
withDefaults(
defineProps<{
text: string
}>(),
{}
)
</script>

<template>
<img :src="qrcode" alt="QR Code" />
<div class="p-2 bg-white">
<QRCodeVue3
v-bind="{
value: text,
image: injLogoBase64,
margin: 0,
dotsOptions: {
type: 'dots',
gradient: {
type: 'radial',
rotation: 0,
colorStops: [
{ offset: 0.5, color: '#007CF6' },
{ offset: 1, color: '#5208c7' }
]
}
},
imageOptions: { imageSize: 0.4, margin: 16 },
cornersDotOptions: {
type: 'dot',
color: '#000000'
},
cornersSquareOptions: {
type: 'extra-rounded',
color: '#000'
}
}"
/>
</div>
</template>
43 changes: 0 additions & 43 deletions layer/components/QRCodeNew.vue

This file was deleted.

1 change: 0 additions & 1 deletion layer/shim-vue.d.ts

This file was deleted.

57 changes: 31 additions & 26 deletions layer/transformer/explorer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
EventLog,
TokenType,
TokenVerification,
ContractTransaction,
ExplorerTransaction,
CW20BalanceExplorerApiResponse
} from '@injectivelabs/sdk-ts'
Expand All @@ -12,7 +13,11 @@ import { MsgType } from '@injectivelabs/ts-types'
import { unknownToken } from '../../data/token'
import { msgTypeMap } from '../../data/explorer'
import { sharedCoinStringToCoins } from './../../utils/formatter'
import { UiExplorerTransaction, SharedBalanceWithToken } from '../../types'
import {
UiContractTransaction,
UiExplorerTransaction,
SharedBalanceWithToken
} from '../../types'

export const toUiCw20Balance = (
cw20Balance: CW20BalanceExplorerApiResponse
Expand Down Expand Up @@ -115,33 +120,12 @@ export const getCoins = ({
}, [] as Coin[])
}

// todo remove once /api/explorer/v1/txs?skip=0&limit=20 add signatures
const getSender = (transaction: ExplorerTransaction): string => {
if (transaction.signatures) {
return transaction.signatures[0].address
}

const message = transaction.messages[0]?.message
const msgs = message.msgs

if (msgs) {
return msgs[0].sender
}

if (message.from_address) {
return message.from_address
}

return message.sender
}

export const toUiTransaction = (
transaction: ExplorerTransaction
): UiExplorerTransaction => {
const sender = getSender(transaction)
const getTypesAndCoins = (
transaction: ExplorerTransaction | ContractTransaction
) => {
const sender = transaction.signatures[0].address

return {
...transaction,
types: transaction.messages.map(
(message) => msgTypeMap[getMsgType(message)] || message.type
),
Expand All @@ -159,3 +143,24 @@ export const toUiTransaction = (
})
}
}

export const toUiTransaction = (
transaction: ExplorerTransaction
): UiExplorerTransaction => {
return {
...transaction,
...getTypesAndCoins(transaction)
}
}

export const toUiContractTransaction = (
transaction: ContractTransaction
): UiContractTransaction => {
return {
...transaction,
hash: transaction.txHash,
blockNumber: transaction.height,
blockTimestamp: transaction.time,
...getTypesAndCoins(transaction)
}
}
16 changes: 15 additions & 1 deletion layer/types/explorer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
import { Coin, BlockWithTxs, ExplorerTransaction } from '@injectivelabs/sdk-ts'
import {
Coin,
BlockWithTxs,
ContractTransaction,
ExplorerTransaction
} from '@injectivelabs/sdk-ts'

export interface UiExplorerTransaction extends ExplorerTransaction {
types: string[]
coinReceived: Coin[]
coinSpent: Coin[]
}

export interface UiContractTransaction extends ContractTransaction {
hash: string
blockNumber: number
blockTimestamp: number
types: string[]
coinReceived: Coin[]
coinSpent: Coin[]
}

export interface UiExplorerBlockWithTxs extends Omit<BlockWithTxs, 'txs'> {
txs: UiExplorerTransaction[]
}
Expand Down
31 changes: 3 additions & 28 deletions layer/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11055,16 +11055,7 @@ strict-uri-encode@^2.0.0:
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz#b9c7330c7042862f6b142dc274bbcc5866ce3546"
integrity sha512-QwiXZgpRcKkhTj2Scnn++4PKtWsH0kpzZ62L2R6c/LUVYv7hVnZqcg2+sMuT6R7Jusu1vviK/MFsu6kNJfWlEQ==

"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -11105,7 +11096,7 @@ string_decoder@~1.1.1:
dependencies:
safe-buffer "~5.1.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand All @@ -11119,13 +11110,6 @@ strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0:
dependencies:
ansi-regex "^4.1.0"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^7.0.1:
version "7.1.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
Expand Down Expand Up @@ -12194,7 +12178,7 @@ wordwrapjs@^4.0.0:
reduce-flatten "^2.0.0"
typical "^5.2.0"

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -12221,15 +12205,6 @@ wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down

0 comments on commit f7c2512

Please sign in to comment.