60
60
>
61
61
<template #value >
62
62
<TransactionSpeedPicker
63
+ v-model =" feeSelectedIndex"
63
64
:fee-list =" feeList"
64
- @changeFee =" (value) => setFee(value)"
65
65
/>
66
66
</template >
67
67
</DetailsItem >
@@ -82,34 +82,36 @@ import {
82
82
watch ,
83
83
} from ' vue' ;
84
84
import { useStore } from ' vuex' ;
85
+ import { useI18n } from ' vue-i18n' ;
85
86
import BigNumber from ' bignumber.js' ;
86
87
import { toBitcoin } from ' satoshi-bitcoin' ;
87
88
88
- import { useNetworks } from ' @/composables/networks ' ;
89
+ import type { TransferFormModel } from ' @/types ' ;
89
90
import {
90
91
useAccounts ,
91
92
useBalances ,
93
+ useNetworks ,
92
94
} from ' @/composables' ;
93
- import type { TransferFormModel } from ' @/types' ;
94
- import {
95
- BTC_COIN_NAME ,
96
- BTC_SYMBOL ,
97
- DUST_AMOUNT ,
98
- } from ' @/protocols/bitcoin/config' ;
99
95
import { useTransferSendForm } from ' @/composables/transferSendForm' ;
100
96
import { NETWORK_TYPE_TESTNET , PROTOCOL_BITCOIN } from ' @/constants' ;
101
97
import {
102
98
executeAndSetInterval ,
103
99
fetchJson ,
104
100
} from ' @/utils' ;
105
-
106
101
import { ProtocolAdapterFactory } from ' @/lib/ProtocolAdapterFactory' ;
102
+ import Logger from ' @/lib/logger' ;
103
+ import {
104
+ BTC_COIN_NAME ,
105
+ BTC_SYMBOL ,
106
+ DUST_AMOUNT ,
107
+ } from ' @/protocols/bitcoin/config' ;
108
+
107
109
import { INFO_BOX_TYPES } from ' @/popup/components/InfoBox.vue' ;
108
110
import DetailsItem from ' @/popup/components/DetailsItem.vue' ;
109
111
import TransferSendFormBase from ' @/popup/components/TransferSendFormBase.vue' ;
110
112
import TransferSendRecipient from ' @/popup/components/TransferSend/TransferSendRecipient.vue' ;
111
113
import TransferSendAmount from ' @/popup/components/TransferSend/TransferSendAmount.vue' ;
112
- import TransactionSpeedPicker from ' @/popup/components/TransactionSpeedPicker.vue' ;
114
+ import TransactionSpeedPicker , { FeeItem } from ' @/popup/components/TransactionSpeedPicker.vue' ;
113
115
import BtnPlain from ' @/popup/components/buttons/BtnPlain.vue' ;
114
116
115
117
import EditIcon from ' @/icons/pencil.svg?vue-component' ;
@@ -134,7 +136,10 @@ export default defineComponent({
134
136
},
135
137
emits: [' update:transferData' , ' success' , ' error' ],
136
138
setup(props , { emit }) {
139
+ const bitcoinAdapter = ProtocolAdapterFactory .getAdapter (PROTOCOL_BITCOIN );
140
+
137
141
const store = useStore ();
142
+ const { t } = useI18n ();
138
143
const { activeNetwork } = useNetworks ();
139
144
140
145
const hasMultisigTokenWarning = ref (false );
@@ -159,20 +164,21 @@ export default defineComponent({
159
164
protocol: PROTOCOL_BITCOIN ,
160
165
});
161
166
162
- const fee = ref (new BigNumber (0 ));
163
- const feeList = ref ([
164
- { fee: new BigNumber (0.00002 ), time: 3540 },
165
- { fee: new BigNumber (0.00004 ), time: 600 },
166
- { fee: new BigNumber (0.00005 ), time: 25 },
167
+ const feeSelectedIndex = ref (1 );
168
+ const feeSlow = ref (new BigNumber (0.00002 ));
169
+ const feeMedium = ref (new BigNumber (0.00002 ));
170
+ const feeHigh = ref (new BigNumber (0.00002 ));
171
+
172
+ const feeList = computed ((): FeeItem [] => [
173
+ { fee: feeSlow .value , time: 3540 , label: t (' common.transferSpeed.slow' ) },
174
+ { fee: feeMedium .value , time: 600 , label: t (' common.transferSpeed.medium' ) },
175
+ { fee: feeHigh .value , time: 25 , label: t (' common.transferSpeed.fast' ) },
167
176
]);
177
+ const fee = computed (() => feeList .value [feeSelectedIndex .value ].fee );
168
178
169
179
const numericFee = computed (() => + fee .value .toFixed ());
170
180
const max = computed (() => balance .value .minus (fee .value ));
171
181
172
- function setFee(value : BigNumber ) {
173
- fee .value = value ;
174
- }
175
-
176
182
function emitCurrentFormModelState() {
177
183
const inputPayload: TransferFormModel = {
178
184
... formModel .value ,
@@ -198,46 +204,42 @@ export default defineComponent({
198
204
}
199
205
200
206
async function updateFeeList() {
201
- const bitcoinAdapter = ProtocolAdapterFactory .getAdapter (PROTOCOL_BITCOIN );
202
- const byteSize = (await bitcoinAdapter .constructAndSignTx (
203
- // TODO: changed to 0 because balance.value can differs
204
- // from totalAmount from constructAndSignTx (balance is not being updated fast enough)
205
- // consider returning an actual amount in future
206
- 0 ,
207
- formModel .value .address ! || activeAccount .value .address ,
208
- {
209
- fee: 0 ,
210
- ... activeAccount .value ,
211
- },
212
- )).virtualSize ();
213
- const { nodeUrl } = activeNetwork .value .protocols .bitcoin ;
214
-
215
- const feeRate = (await fetchJson (` ${nodeUrl }/fee-estimates ` ))[' 5' ];
216
- const feeStepFactor = new BigNumber (0.5 );
217
- const mediumFee = new BigNumber (Math .ceil (feeRate * byteSize ));
218
-
219
- feeList .value = [
220
- {
221
- fee: new BigNumber (toBitcoin (Math .ceil (mediumFee .minus (
222
- mediumFee .times (feeStepFactor ),
223
- ).toNumber ()))),
224
- time: 3540 ,
225
- },
226
- {
227
- fee: new BigNumber (toBitcoin (
207
+ try {
208
+ const byteSize = (await bitcoinAdapter .constructAndSignTx (
209
+ // TODO: changed to 0 because balance.value can differs
210
+ // from totalAmount from constructAndSignTx (balance is not being updated fast enough)
211
+ // consider returning an actual amount in future
212
+ 0 ,
213
+ formModel .value .address || activeAccount .value .address ,
214
+ {
215
+ fee: 0 ,
216
+ ... activeAccount .value ,
217
+ },
218
+ )).virtualSize ();
219
+ const { nodeUrl } = activeNetwork .value .protocols .bitcoin ;
220
+
221
+ const feeRate = (await fetchJson (` ${nodeUrl }/fee-estimates ` ))[' 5' ];
222
+ const feeStepFactor = new BigNumber (0.5 );
223
+ const newFeeMedium = new BigNumber (Math .ceil (feeRate * byteSize ));
224
+
225
+ feeSlow .value = new BigNumber (
226
+ toBitcoin (Math .ceil (newFeeMedium .minus (newFeeMedium .times (feeStepFactor )).toNumber ())),
227
+ );
228
+
229
+ feeMedium .value = new BigNumber (
230
+ toBitcoin (
228
231
// Double the fee for the testnet to match relay fee.
229
232
// TODO: Revisit this along with fee calculation
230
- mediumFee .toNumber () * (activeNetwork .value .type === NETWORK_TYPE_TESTNET ? 2.0 : 1.0 ),
231
- )),
232
- time: 600 ,
233
- },
234
- {
235
- fee: new BigNumber (toBitcoin (Math .ceil (mediumFee .plus (
236
- mediumFee .times (feeStepFactor ),
237
- ).toNumber ()))),
238
- time: 25 ,
239
- },
240
- ];
233
+ newFeeMedium .toNumber () * (activeNetwork .value .type === NETWORK_TYPE_TESTNET ? 2 : 1 ),
234
+ ),
235
+ );
236
+
237
+ feeHigh .value = new BigNumber (
238
+ toBitcoin (Math .ceil (newFeeMedium .plus (newFeeMedium .times (feeStepFactor )).toNumber ())),
239
+ );
240
+ } catch (error : any ) {
241
+ Logger .write (error );
242
+ }
241
243
}
242
244
243
245
let polling: NodeJS .Timer | null = null ;
@@ -280,16 +282,16 @@ export default defineComponent({
280
282
isUrlTippingEnabled ,
281
283
activeNetwork ,
282
284
fee ,
285
+ feeList ,
286
+ feeSelectedIndex ,
283
287
numericFee ,
284
288
activeAccount ,
285
- feeList ,
286
289
errors ,
287
290
balance ,
288
291
max ,
289
292
clearPayload ,
290
293
openScanQrModal ,
291
294
handleAssetChange ,
292
- setFee ,
293
295
EditIcon ,
294
296
DeleteIcon ,
295
297
PlusCircleIcon ,
0 commit comments