Skip to content

Commit f7c2512

Browse files
committed
chore: contract transaction transformer
1 parent ea651d7 commit f7c2512

File tree

6 files changed

+87
-110
lines changed

6 files changed

+87
-110
lines changed

layer/components/QRCode.vue

+38-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,43 @@
1-
<script setup lang="ts">
2-
import { useQRCode } from '@vueuse/integrations/useQRCode'
1+
<script lang="ts" setup>
2+
import QRCodeVue3 from 'qrcode-vue3'
3+
import { injLogoBase64 } from './../data/token'
34
4-
const props = defineProps({
5-
text: {
6-
type: String,
7-
required: true
8-
}
9-
})
10-
11-
const qrcode = useQRCode(props.text)
5+
withDefaults(
6+
defineProps<{
7+
text: string
8+
}>(),
9+
{}
10+
)
1211
</script>
1312

1413
<template>
15-
<img :src="qrcode" alt="QR Code" />
14+
<div class="p-2 bg-white">
15+
<QRCodeVue3
16+
v-bind="{
17+
value: text,
18+
image: injLogoBase64,
19+
margin: 0,
20+
dotsOptions: {
21+
type: 'dots',
22+
gradient: {
23+
type: 'radial',
24+
rotation: 0,
25+
colorStops: [
26+
{ offset: 0.5, color: '#007CF6' },
27+
{ offset: 1, color: '#5208c7' }
28+
]
29+
}
30+
},
31+
imageOptions: { imageSize: 0.4, margin: 16 },
32+
cornersDotOptions: {
33+
type: 'dot',
34+
color: '#000000'
35+
},
36+
cornersSquareOptions: {
37+
type: 'extra-rounded',
38+
color: '#000'
39+
}
40+
}"
41+
/>
42+
</div>
1643
</template>

layer/components/QRCodeNew.vue

-43
This file was deleted.

layer/shim-vue.d.ts

-1
This file was deleted.

layer/transformer/explorer/index.ts

+31-26
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
EventLog,
55
TokenType,
66
TokenVerification,
7+
ContractTransaction,
78
ExplorerTransaction,
89
CW20BalanceExplorerApiResponse
910
} from '@injectivelabs/sdk-ts'
@@ -12,7 +13,11 @@ import { MsgType } from '@injectivelabs/ts-types'
1213
import { unknownToken } from '../../data/token'
1314
import { msgTypeMap } from '../../data/explorer'
1415
import { sharedCoinStringToCoins } from './../../utils/formatter'
15-
import { UiExplorerTransaction, SharedBalanceWithToken } from '../../types'
16+
import {
17+
UiContractTransaction,
18+
UiExplorerTransaction,
19+
SharedBalanceWithToken
20+
} from '../../types'
1621

1722
export const toUiCw20Balance = (
1823
cw20Balance: CW20BalanceExplorerApiResponse
@@ -115,33 +120,12 @@ export const getCoins = ({
115120
}, [] as Coin[])
116121
}
117122

118-
// todo remove once /api/explorer/v1/txs?skip=0&limit=20 add signatures
119-
const getSender = (transaction: ExplorerTransaction): string => {
120-
if (transaction.signatures) {
121-
return transaction.signatures[0].address
122-
}
123-
124-
const message = transaction.messages[0]?.message
125-
const msgs = message.msgs
126-
127-
if (msgs) {
128-
return msgs[0].sender
129-
}
130-
131-
if (message.from_address) {
132-
return message.from_address
133-
}
134-
135-
return message.sender
136-
}
137-
138-
export const toUiTransaction = (
139-
transaction: ExplorerTransaction
140-
): UiExplorerTransaction => {
141-
const sender = getSender(transaction)
123+
const getTypesAndCoins = (
124+
transaction: ExplorerTransaction | ContractTransaction
125+
) => {
126+
const sender = transaction.signatures[0].address
142127

143128
return {
144-
...transaction,
145129
types: transaction.messages.map(
146130
(message) => msgTypeMap[getMsgType(message)] || message.type
147131
),
@@ -159,3 +143,24 @@ export const toUiTransaction = (
159143
})
160144
}
161145
}
146+
147+
export const toUiTransaction = (
148+
transaction: ExplorerTransaction
149+
): UiExplorerTransaction => {
150+
return {
151+
...transaction,
152+
...getTypesAndCoins(transaction)
153+
}
154+
}
155+
156+
export const toUiContractTransaction = (
157+
transaction: ContractTransaction
158+
): UiContractTransaction => {
159+
return {
160+
...transaction,
161+
hash: transaction.txHash,
162+
blockNumber: transaction.height,
163+
blockTimestamp: transaction.time,
164+
...getTypesAndCoins(transaction)
165+
}
166+
}

layer/types/explorer.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1-
import { Coin, BlockWithTxs, ExplorerTransaction } from '@injectivelabs/sdk-ts'
1+
import {
2+
Coin,
3+
BlockWithTxs,
4+
ContractTransaction,
5+
ExplorerTransaction
6+
} from '@injectivelabs/sdk-ts'
27

38
export interface UiExplorerTransaction extends ExplorerTransaction {
49
types: string[]
510
coinReceived: Coin[]
611
coinSpent: Coin[]
712
}
813

14+
export interface UiContractTransaction extends ContractTransaction {
15+
hash: string
16+
blockNumber: number
17+
blockTimestamp: number
18+
types: string[]
19+
coinReceived: Coin[]
20+
coinSpent: Coin[]
21+
}
22+
923
export interface UiExplorerBlockWithTxs extends Omit<BlockWithTxs, 'txs'> {
1024
txs: UiExplorerTransaction[]
1125
}

layer/yarn.lock

+3-28
Original file line numberDiff line numberDiff line change
@@ -11055,16 +11055,7 @@ strict-uri-encode@^2.0.0:
1105511055
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz#b9c7330c7042862f6b142dc274bbcc5866ce3546"
1105611056
integrity sha512-QwiXZgpRcKkhTj2Scnn++4PKtWsH0kpzZ62L2R6c/LUVYv7hVnZqcg2+sMuT6R7Jusu1vviK/MFsu6kNJfWlEQ==
1105711057

11058-
"string-width-cjs@npm:string-width@^4.2.0":
11059-
version "4.2.3"
11060-
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
11061-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
11062-
dependencies:
11063-
emoji-regex "^8.0.0"
11064-
is-fullwidth-code-point "^3.0.0"
11065-
strip-ansi "^6.0.1"
11066-
11067-
"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
11058+
"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:
1106811059
version "4.2.3"
1106911060
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
1107011061
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -11105,7 +11096,7 @@ string_decoder@~1.1.1:
1110511096
dependencies:
1110611097
safe-buffer "~5.1.0"
1110711098

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

11122-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
11123-
version "6.0.1"
11124-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
11125-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
11126-
dependencies:
11127-
ansi-regex "^5.0.1"
11128-
1112911113
strip-ansi@^7.0.1:
1113011114
version "7.1.0"
1113111115
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
@@ -12194,7 +12178,7 @@ wordwrapjs@^4.0.0:
1219412178
reduce-flatten "^2.0.0"
1219512179
typical "^5.2.0"
1219612180

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

12224-
wrap-ansi@^7.0.0:
12225-
version "7.0.0"
12226-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
12227-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
12228-
dependencies:
12229-
ansi-styles "^4.0.0"
12230-
string-width "^4.1.0"
12231-
strip-ansi "^6.0.0"
12232-
1223312208
wrap-ansi@^8.1.0:
1223412209
version "8.1.0"
1223512210
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
 (0)