@keplr-wallet/hooks-starknet 0.12.240-rc.4 → 0.12.240
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/tx/fee.d.ts +4 -4
- package/build/tx/fee.js +1 -1
- package/build/tx/fee.js.map +1 -1
- package/build/tx/gas-simulator.d.ts +18 -28
- package/build/tx/gas-simulator.js +102 -199
- package/build/tx/gas-simulator.js.map +1 -1
- package/build/tx/gas.d.ts +5 -0
- package/build/tx/gas.js +44 -0
- package/build/tx/gas.js.map +1 -1
- package/build/tx/types.d.ts +22 -6
- package/package.json +15 -15
- package/src/tx/fee.ts +5 -4
- package/src/tx/gas-simulator.ts +114 -220
- package/src/tx/gas.ts +52 -0
- package/src/tx/types.ts +25 -7
package/build/tx/gas.js
CHANGED
@@ -18,6 +18,7 @@ class GasConfig extends chain_1.TxChainSetter {
|
|
18
18
|
We use string because there is no guarantee that only number is input in input component.
|
19
19
|
*/
|
20
20
|
this._value = "";
|
21
|
+
this._gasAdjustmentValue = "1.5";
|
21
22
|
/*
|
22
23
|
There are services that sometimes use invalid tx to sign arbitrary data on the sign page.
|
23
24
|
In this case, there is no obligation to deal with it, but 0 gas is favorably allowed. This option is used for this case.
|
@@ -32,6 +33,9 @@ class GasConfig extends chain_1.TxChainSetter {
|
|
32
33
|
get value() {
|
33
34
|
return this._value;
|
34
35
|
}
|
36
|
+
get gasAdjustmentValue() {
|
37
|
+
return this._gasAdjustmentValue;
|
38
|
+
}
|
35
39
|
setValue(value) {
|
36
40
|
if (typeof value === "number") {
|
37
41
|
this._value = Math.ceil(value).toString();
|
@@ -40,6 +44,37 @@ class GasConfig extends chain_1.TxChainSetter {
|
|
40
44
|
this._value = value;
|
41
45
|
}
|
42
46
|
}
|
47
|
+
setGasAdjustmentValue(gasAdjustment) {
|
48
|
+
if (typeof gasAdjustment === "number") {
|
49
|
+
if (gasAdjustment < 0 || gasAdjustment > 2) {
|
50
|
+
return;
|
51
|
+
}
|
52
|
+
this._gasAdjustmentValue = gasAdjustment.toString();
|
53
|
+
return;
|
54
|
+
}
|
55
|
+
if (gasAdjustment === "") {
|
56
|
+
this._gasAdjustmentValue = "";
|
57
|
+
return;
|
58
|
+
}
|
59
|
+
if (gasAdjustment.startsWith(".")) {
|
60
|
+
this._gasAdjustmentValue = "0" + gasAdjustment;
|
61
|
+
}
|
62
|
+
const num = parseFloat(gasAdjustment);
|
63
|
+
if (Number.isNaN(num) || num < 0 || num > 2) {
|
64
|
+
return;
|
65
|
+
}
|
66
|
+
this._gasAdjustmentValue = gasAdjustment;
|
67
|
+
}
|
68
|
+
get gasAdjustment() {
|
69
|
+
if (this._gasAdjustmentValue === "") {
|
70
|
+
return 0;
|
71
|
+
}
|
72
|
+
const num = parseFloat(this._gasAdjustmentValue);
|
73
|
+
if (Number.isNaN(num) || num < 0) {
|
74
|
+
return 0;
|
75
|
+
}
|
76
|
+
return num;
|
77
|
+
}
|
43
78
|
get gas() {
|
44
79
|
if (this.value.trim() === "") {
|
45
80
|
return 0;
|
@@ -50,6 +85,9 @@ class GasConfig extends chain_1.TxChainSetter {
|
|
50
85
|
}
|
51
86
|
return num;
|
52
87
|
}
|
88
|
+
get maxGas() {
|
89
|
+
return Math.ceil(this.gas * this.gasAdjustment);
|
90
|
+
}
|
53
91
|
get uiProperties() {
|
54
92
|
if (this.value.trim() === "") {
|
55
93
|
return {
|
@@ -87,12 +125,18 @@ class GasConfig extends chain_1.TxChainSetter {
|
|
87
125
|
__decorate([
|
88
126
|
mobx_1.observable
|
89
127
|
], GasConfig.prototype, "_value", void 0);
|
128
|
+
__decorate([
|
129
|
+
mobx_1.observable
|
130
|
+
], GasConfig.prototype, "_gasAdjustmentValue", void 0);
|
90
131
|
__decorate([
|
91
132
|
mobx_1.observable
|
92
133
|
], GasConfig.prototype, "_allowZeroGas", void 0);
|
93
134
|
__decorate([
|
94
135
|
mobx_1.action
|
95
136
|
], GasConfig.prototype, "setValue", null);
|
137
|
+
__decorate([
|
138
|
+
mobx_1.action
|
139
|
+
], GasConfig.prototype, "setGasAdjustmentValue", null);
|
96
140
|
__decorate([
|
97
141
|
mobx_1.computed
|
98
142
|
], GasConfig.prototype, "uiProperties", null);
|
package/build/tx/gas.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"gas.js","sourceRoot":"","sources":["../../src/tx/gas.ts"],"names":[],"mappings":";;;;;;;;;AACA,mCAAwC;AAExC,+BAAoE;AACpE,iCAAiC;AAEjC,MAAa,SAAU,SAAQ,qBAAa;
|
1
|
+
{"version":3,"file":"gas.js","sourceRoot":"","sources":["../../src/tx/gas.ts"],"names":[],"mappings":";;;;;;;;;AACA,mCAAwC;AAExC,+BAAoE;AACpE,iCAAiC;AAEjC,MAAa,SAAU,SAAQ,qBAAa;IAkB1C,YACE,WAAwB,EACxB,cAAsB,EACtB,UAAmB,EACnB,YAAsB;QAEtB,KAAK,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QAvBrC;;;WAGG;QAEO,WAAM,GAAW,EAAE,CAAC;QAGpB,wBAAmB,GAAW,KAAK,CAAC;QAE9C;;;WAGG;QAEO,kBAAa,GAAa,SAAS,CAAC;QAU5C,IAAI,UAAU,EAAE;YACd,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC;SACrC;QACD,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAElC,IAAA,qBAAc,EAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;IAGD,QAAQ,CAAC,KAAsB;QAC7B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC;SAC3C;aAAM;Y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B9C;IADC,aAAM;yCAON;AAGD;IADC,aAAM;sDA0BN;AAiCD;IADC,eAAQ;6CAoCR;AAjJH,8BAkJC;AAEM,MAAM,YAAY,GAAG,CAC1B,WAAwB,EACxB,OAAe,EACf,UAAmB,EACnB,EAAE;IACF,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EACzB,GAAG,EAAE,CAAC,IAAI,SAAS,CAAC,WAAW,EAAE,OAAO,EAAE,UAAU,CAAC,CACtD,CAAC;IACF,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAE3B,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAXW,QAAA,YAAY,gBAWvB;AAEF;;;GAGG;AACI,MAAM,uBAAuB,GAAG,CACrC,WAAwB,EACxB,OAAe,EACf,UAAmB,EACnB,EAAE;IACF,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EACzB,GAAG,EAAE,CAAC,IAAI,SAAS,CAAC,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,CAC5D,CAAC;IACF,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAE3B,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAXW,QAAA,uBAAuB,2BAWlC"}
|
package/build/tx/types.d.ts
CHANGED
@@ -11,10 +11,29 @@ export interface UIProperties {
|
|
11
11
|
readonly warning?: Error;
|
12
12
|
readonly loadingState?: "loading" | "loading-block";
|
13
13
|
}
|
14
|
+
export interface GasEstimate {
|
15
|
+
l1Gas: {
|
16
|
+
consumed: string;
|
17
|
+
price: string;
|
18
|
+
};
|
19
|
+
l1DataGas: {
|
20
|
+
consumed: string;
|
21
|
+
price: string;
|
22
|
+
};
|
23
|
+
l2Gas: {
|
24
|
+
consumed: string;
|
25
|
+
price: string;
|
26
|
+
};
|
27
|
+
}
|
28
|
+
export type FeeType = "STRK";
|
14
29
|
export interface IGasConfig extends ITxChainSetter {
|
15
30
|
value: string;
|
31
|
+
gasAdjustmentValue: string;
|
16
32
|
setValue(value: string | number): void;
|
33
|
+
setGasAdjustmentValue(gasAdjustment: string | number): void;
|
17
34
|
gas: number;
|
35
|
+
maxGas: number;
|
36
|
+
gasAdjustment: number;
|
18
37
|
uiProperties: UIProperties;
|
19
38
|
}
|
20
39
|
export interface ISenderConfig extends ITxChainSetter {
|
@@ -24,8 +43,8 @@ export interface ISenderConfig extends ITxChainSetter {
|
|
24
43
|
uiProperties: UIProperties;
|
25
44
|
}
|
26
45
|
export interface IFeeConfig extends ITxChainSetter {
|
27
|
-
type:
|
28
|
-
setType(type:
|
46
|
+
type: FeeType;
|
47
|
+
setType(type: FeeType): void;
|
29
48
|
gasPrice: CoinPretty | undefined;
|
30
49
|
maxGasPrice: CoinPretty | undefined;
|
31
50
|
setGasPrice(gasPrice: {
|
@@ -70,9 +89,6 @@ export interface IGasSimulator {
|
|
70
89
|
enabled: boolean;
|
71
90
|
setEnabled(value: boolean): void;
|
72
91
|
isSimulating: boolean;
|
73
|
-
|
74
|
-
gasAdjustment: number;
|
75
|
-
gasAdjustmentValue: string;
|
76
|
-
setGasAdjustmentValue(gasAdjustment: string | number): void;
|
92
|
+
gasEstimate: GasEstimate | undefined;
|
77
93
|
uiProperties: UIProperties;
|
78
94
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@keplr-wallet/hooks-starknet",
|
3
|
-
"version": "0.12.240
|
3
|
+
"version": "0.12.240",
|
4
4
|
"main": "build/index.js",
|
5
5
|
"author": "chainapsis",
|
6
6
|
"license": "Apache-2.0",
|
@@ -18,18 +18,18 @@
|
|
18
18
|
"dependencies": {
|
19
19
|
"@ethersproject/address": "^5.7.0",
|
20
20
|
"@ethersproject/providers": "^5.7.0",
|
21
|
-
"@keplr-wallet/background": "0.12.240
|
22
|
-
"@keplr-wallet/common": "0.12.240
|
23
|
-
"@keplr-wallet/cosmos": "0.12.240
|
24
|
-
"@keplr-wallet/crypto": "0.12.240
|
25
|
-
"@keplr-wallet/proto-types": "0.12.240
|
26
|
-
"@keplr-wallet/simple-fetch": "0.12.240
|
27
|
-
"@keplr-wallet/stores": "0.12.240
|
28
|
-
"@keplr-wallet/stores-etc": "0.12.240
|
29
|
-
"@keplr-wallet/stores-eth": "0.12.240
|
30
|
-
"@keplr-wallet/stores-starknet": "0.12.240
|
31
|
-
"@keplr-wallet/types": "0.12.240
|
32
|
-
"@keplr-wallet/unit": "0.12.240
|
21
|
+
"@keplr-wallet/background": "0.12.240",
|
22
|
+
"@keplr-wallet/common": "0.12.240",
|
23
|
+
"@keplr-wallet/cosmos": "0.12.240",
|
24
|
+
"@keplr-wallet/crypto": "0.12.240",
|
25
|
+
"@keplr-wallet/proto-types": "0.12.240",
|
26
|
+
"@keplr-wallet/simple-fetch": "0.12.240",
|
27
|
+
"@keplr-wallet/stores": "0.12.240",
|
28
|
+
"@keplr-wallet/stores-etc": "0.12.240",
|
29
|
+
"@keplr-wallet/stores-eth": "0.12.240",
|
30
|
+
"@keplr-wallet/stores-starknet": "0.12.240",
|
31
|
+
"@keplr-wallet/types": "0.12.240",
|
32
|
+
"@keplr-wallet/unit": "0.12.240",
|
33
33
|
"buffer": "^6.0.3",
|
34
34
|
"long": "^4.0.0",
|
35
35
|
"utility-types": "^3.10.0"
|
@@ -38,7 +38,7 @@
|
|
38
38
|
"mobx": "^6",
|
39
39
|
"mobx-utils": "^6",
|
40
40
|
"react": "^16.8.0 || ^17 || ^18",
|
41
|
-
"starknet": "^
|
41
|
+
"starknet": "^7"
|
42
42
|
},
|
43
|
-
"gitHead": "
|
43
|
+
"gitHead": "056bcec43193f6d249bb8d343c46191b1485106b"
|
44
44
|
}
|
package/src/tx/fee.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import {
|
2
|
+
FeeType,
|
2
3
|
IAmountConfig,
|
3
4
|
IFeeConfig,
|
4
5
|
IGasConfig,
|
@@ -19,7 +20,7 @@ export class FeeConfig extends TxChainSetter implements IFeeConfig {
|
|
19
20
|
@observable.ref
|
20
21
|
protected _maxGasPrice: CoinPretty | undefined = undefined;
|
21
22
|
@observable
|
22
|
-
protected _type:
|
23
|
+
protected _type: FeeType = "STRK";
|
23
24
|
|
24
25
|
@observable
|
25
26
|
protected _disableBalanceCheck: boolean = false;
|
@@ -131,7 +132,7 @@ export class FeeConfig extends TxChainSetter implements IFeeConfig {
|
|
131
132
|
return this._maxGasPrice;
|
132
133
|
}
|
133
134
|
|
134
|
-
get type():
|
135
|
+
get type(): FeeType {
|
135
136
|
return this._type;
|
136
137
|
}
|
137
138
|
|
@@ -149,7 +150,7 @@ export class FeeConfig extends TxChainSetter implements IFeeConfig {
|
|
149
150
|
}
|
150
151
|
|
151
152
|
@action
|
152
|
-
setType(type:
|
153
|
+
setType(type: FeeType): void {
|
153
154
|
if (this._type !== type) {
|
154
155
|
this._type = type;
|
155
156
|
this._gasPrice = undefined;
|
@@ -173,7 +174,7 @@ export class FeeConfig extends TxChainSetter implements IFeeConfig {
|
|
173
174
|
return;
|
174
175
|
}
|
175
176
|
|
176
|
-
const gasDec = new Dec(this.gasConfig.
|
177
|
+
const gasDec = new Dec(this.gasConfig.maxGas);
|
177
178
|
return this._maxGasPrice.mul(gasDec);
|
178
179
|
}
|
179
180
|
}
|