@@ -6,10 +6,11 @@ import {TX_TYPE} from './tx-types.js';
6
6
* @param txType
7
7
* @param {string|Buffer } [payload]
8
8
* @param {string } [coinSymbol]
9
+ * @param {number } [coinSymbolLength]
9
10
* @param {number } [multisendCount]
10
11
* @return {boolean|number }
11
12
*/
12
- export function getFeeValue ( txType , { payload, coinSymbol, multisendCount} = { } ) {
13
+ export function getFeeValue ( txType , { payload, coinSymbol, coinSymbolLength , multisendCount} = { } ) {
13
14
// txType to string
14
15
if ( ! isHexString ( txType ) ) {
15
16
txType = `0x${ padToEven ( txType . toString ( 16 ) ) . toUpperCase ( ) } ` ;
@@ -34,27 +35,40 @@ export function getFeeValue(txType, {payload, coinSymbol, multisendCount} = {})
34
35
const COIN_UNIT_PART = 1 / COIN_UNIT ; // negate js math quirks, ex.: 18 * 0.001 = 0.018000000000000002
35
36
// multisend fee = base fee + extra fee based on count
36
37
const multisendExtraCountFee = txType === TX_TYPE . MULTISEND ? ( multisendCount - 1 ) * MULTISEND_FEE_DELTA : 0 ;
37
- // coin symbol extra fee, value in base coin (not in units )
38
- const coinSymbolFee = txType === TX_TYPE . CREATE_COIN ? getCoinSymbolFee ( coinSymbol ) : 0 ;
39
- return ( baseUnits + payloadLength * 2 + multisendExtraCountFee ) / COIN_UNIT_PART + coinSymbolFee ;
38
+ // coin symbol extra fee, value in units (not in base coin )
39
+ const coinSymbolFee = txType === TX_TYPE . CREATE_COIN ? getCoinSymbolFee ( coinSymbol , coinSymbolLength ) : 0 ;
40
+ return ( baseUnits + payloadLength * 2 + multisendExtraCountFee + coinSymbolFee ) / COIN_UNIT_PART ;
40
41
}
41
42
42
43
//
43
44
/**
44
45
* @param {string } ticker
46
+ * @param {number } [length]
45
47
* @return {number } - value in base coin (not in units)
46
48
*/
47
- export function getCoinSymbolFee ( ticker ) {
48
- return COIN_SYMBOL_FEES [ ticker && ticker . length ] || 100 ;
49
+ export function getCoinSymbolFee ( ticker , length ) {
50
+ if ( ! length ) {
51
+ length = ticker ?. length ;
52
+ }
53
+ if ( ! isValidLength ( length ) ) {
54
+ length = 7 ;
55
+ }
56
+ return COIN_SYMBOL_FEES [ length ] ;
57
+
58
+ // eslint-disable-next-line unicorn/consistent-function-scoping, no-shadow
59
+ function isValidLength ( length ) {
60
+ return length >= 3 && length <= 7 ;
61
+ }
49
62
}
50
63
51
- // value in base coin (not in units )
64
+ // value in units (not in base coin )
52
65
// @See https://github.com/MinterTeam/minter-go-node/blob/master/core/transaction/create_coin.go#L93
53
66
export const COIN_SYMBOL_FEES = {
54
- 3 : 1000000 ,
55
- 4 : 100000 ,
56
- 5 : 10000 ,
57
- 6 : 1000 ,
67
+ 3 : 1_000_000_000 ,
68
+ 4 : 100_000_000 ,
69
+ 5 : 10_000_000 ,
70
+ 6 : 1_000_000 ,
71
+ 7 : 100_000 ,
58
72
} ;
59
73
60
74
export const MULTISEND_FEE_DELTA = 5 ;
0 commit comments