Skip to content

Commit 47a8d0d

Browse files
authored
Merge pull request #722 from Adamant-im/fix/usdt-tx-fee
fix: display fee in ETH
2 parents bb40107 + 049453b commit 47a8d0d

File tree

3 files changed

+63
-84
lines changed

3 files changed

+63
-84
lines changed

src/components/transactions/Erc20Transaction.vue

Lines changed: 55 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
:inconsistent-status="inconsistentStatus"
1313
:adm-tx="admTx"
1414
:crypto="crypto"
15+
:feeCrypto="AllCryptos.ETH"
1516
@refetch-status="refetch"
1617
/>
1718
</template>
1819

19-
<script lang="ts">
20-
import { computed, defineComponent, PropType } from 'vue'
20+
<script lang="ts" setup>
21+
import { computed, PropType } from 'vue'
2122
import { useStore } from 'vuex'
2223
import TransactionTemplate from './TransactionTemplate.vue'
2324
import { getExplorerTxUrl } from '@/config/utils'
@@ -32,93 +33,66 @@ import { useErc20TransactionQuery } from '@/hooks/queries/transaction'
3233
import { useClearPendingTransaction } from './hooks/useClearPendingTransaction'
3334
import { getPartnerAddress } from './utils/getPartnerAddress'
3435
35-
export default defineComponent({
36-
name: 'Erc20Transaction',
37-
components: {
38-
TransactionTemplate
36+
const props = defineProps({
37+
crypto: {
38+
required: true,
39+
type: String as PropType<CryptoSymbol>
3940
},
40-
props: {
41-
crypto: {
42-
required: true,
43-
type: String as PropType<CryptoSymbol>
44-
},
45-
id: {
46-
required: true,
47-
type: String
48-
}
49-
},
50-
setup(props) {
51-
const store = useStore()
52-
53-
const cryptoAddress = computed(() => store.state.eth.address)
41+
id: {
42+
required: true,
43+
type: String
44+
}
45+
})
5446
55-
const {
56-
status: queryStatus,
57-
isFetching,
58-
data: transaction,
59-
refetch
60-
} = useErc20TransactionQuery(props.crypto)(props.id)
61-
const inconsistentStatus = useInconsistentStatus(transaction, props.crypto)
62-
const transactionStatus = useTransactionStatus(isFetching, queryStatus, inconsistentStatus)
63-
useClearPendingTransaction(props.crypto, transaction)
47+
const store = useStore()
6448
65-
const admTx = useFindAdmTransaction(props.id)
66-
const senderAdmAddress = computed(() => admTx.value?.senderId || '')
67-
const recipientAdmAddress = computed(() => admTx.value?.recipientId || '')
68-
const partnerAdmAddress = computed(() =>
69-
admTx.value
70-
? getPartnerAddress(admTx.value?.senderId, admTx.value?.recipientId, cryptoAddress.value)
71-
: ''
72-
)
49+
const cryptoAddress = computed(() => store.state.eth.address)
7350
74-
const senderFormatted = useCryptoAddressPretty(
75-
transaction,
76-
cryptoAddress,
77-
senderAdmAddress,
78-
'sender'
79-
)
80-
const recipientFormatted = useCryptoAddressPretty(
81-
transaction,
82-
cryptoAddress,
83-
recipientAdmAddress,
84-
'recipient'
85-
)
51+
const {
52+
status: queryStatus,
53+
isFetching,
54+
data: transaction,
55+
refetch
56+
} = useErc20TransactionQuery(props.crypto)(props.id)
57+
const inconsistentStatus = useInconsistentStatus(transaction, props.crypto)
58+
const transactionStatus = useTransactionStatus(isFetching, queryStatus, inconsistentStatus)
59+
useClearPendingTransaction(props.crypto, transaction)
8660
87-
const explorerLink = computed(() => getExplorerTxUrl(Cryptos.ETH, props.id))
88-
const blockHeight = useBlockHeight('ETH', {
89-
enabled: () => transactionStatus.value === 'CONFIRMED'
90-
})
91-
const confirmations = computed(() => {
92-
if (!blockHeight.value || !transaction.value) return NaN
61+
const admTx = useFindAdmTransaction(props.id)
62+
const senderAdmAddress = computed(() => admTx.value?.senderId || '')
63+
const recipientAdmAddress = computed(() => admTx.value?.recipientId || '')
64+
const partnerAdmAddress = computed(() =>
65+
admTx.value
66+
? getPartnerAddress(admTx.value?.senderId, admTx.value?.recipientId, cryptoAddress.value)
67+
: ''
68+
)
9369
94-
if ('blockNumber' in transaction.value && transaction.value.blockNumber) {
95-
return blockHeight.value - transaction.value.blockNumber + 1
96-
}
70+
const senderFormatted = useCryptoAddressPretty(
71+
transaction,
72+
cryptoAddress,
73+
senderAdmAddress,
74+
'sender'
75+
)
76+
const recipientFormatted = useCryptoAddressPretty(
77+
transaction,
78+
cryptoAddress,
79+
recipientAdmAddress,
80+
'recipient'
81+
)
9782
98-
return transaction.value?.confirmations
99-
})
100-
const fee = computed(() => {
101-
const ethFee = transaction.value?.fee || 0
102-
const currentCurrency = store.state.options.currentRate
103-
const currentRate = store.state.rate.rates[`${AllCryptos.ETH}/${currentCurrency}`]
104-
const feeRate = (ethFee * currentRate).toFixed(2)
105-
return +feeRate
106-
})
83+
const explorerLink = computed(() => getExplorerTxUrl(Cryptos.ETH, props.id))
84+
const blockHeight = useBlockHeight('ETH', {
85+
enabled: () => transactionStatus.value === 'CONFIRMED'
86+
})
87+
const confirmations = computed(() => {
88+
if (!blockHeight.value || !transaction.value) return NaN
10789
108-
return {
109-
refetch,
110-
transaction,
111-
fee,
112-
senderFormatted,
113-
recipientFormatted,
114-
partnerAdmAddress,
115-
explorerLink,
116-
confirmations,
117-
admTx,
118-
queryStatus,
119-
transactionStatus,
120-
inconsistentStatus
121-
}
90+
if ('blockNumber' in transaction.value && transaction.value.blockNumber) {
91+
return blockHeight.value - transaction.value.blockNumber + 1
12292
}
93+
94+
return transaction.value?.confirmations
12395
})
96+
97+
const fee = computed(() => transaction.value?.fee)
12498
</script>

src/components/transactions/TransactionTemplate.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
<v-divider />
8484

8585
<TransactionListItem :title="t('transaction.commission')">
86-
{{ typeof fee === 'number' ? formatAmount(fee) + ` ${crypto}` : placeholder }}
86+
{{ typeof fee === 'number' ? formatAmount(fee) + ` ${feeCrypto ?? crypto}` : placeholder }}
8787
</TransactionListItem>
8888

8989
<v-divider />
@@ -236,7 +236,10 @@ export default defineComponent({
236236
},
237237
recipientFormatted: {
238238
type: String
239-
}
239+
},
240+
feeCrypto: {
241+
type: String
242+
},
240243
},
241244
emits: ['refetch-status'],
242245
setup(props, { emit }) {

src/lib/nodes/eth/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ export function normalizeErc20Transaction(
6565
): Erc20Transaction {
6666
const gasPrice = 'gasPrice' in transaction ? transaction.gasPrice : 0
6767
const effectiveGasPrice = 'effectiveGasPrice' in transaction ? transaction.effectiveGasPrice : 0
68-
const fee = utils.calculateFee(transaction.gas, gasPrice.toString())
68+
const gasUsed = receipt && 'gasUsed' in receipt ? receipt.gasUsed : 0
69+
70+
const fee = utils.calculateFee(gasUsed.toString(), gasPrice.toString())
6971
const direction = transaction.from.toLowerCase() === address.toLowerCase() ? 'from' : 'to'
7072
const confirmations =
7173
blockTimestamp && receipt?.blockNumber

0 commit comments

Comments
 (0)