@keplr-wallet/hooks-starknet 0.12.133-rc.0
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/.eslintignore +2 -0
- package/.prettierignore +2 -0
- package/LICENSE +209 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +18 -0
- package/build/index.js.map +1 -0
- package/build/tx/amount.d.ts +27 -0
- package/build/tx/amount.js +230 -0
- package/build/tx/amount.js.map +1 -0
- package/build/tx/chain.d.ts +11 -0
- package/build/tx/chain.js +37 -0
- package/build/tx/chain.js.map +1 -0
- package/build/tx/errors.d.ts +48 -0
- package/build/tx/errors.js +132 -0
- package/build/tx/errors.js.map +1 -0
- package/build/tx/fee.d.ts +30 -0
- package/build/tx/fee.js +167 -0
- package/build/tx/fee.js.map +1 -0
- package/build/tx/gas-simulator.d.ts +72 -0
- package/build/tx/gas-simulator.js +491 -0
- package/build/tx/gas-simulator.js.map +1 -0
- package/build/tx/gas.d.ts +14 -0
- package/build/tx/gas.js +116 -0
- package/build/tx/gas.js.map +1 -0
- package/build/tx/index.d.ts +12 -0
- package/build/tx/index.js +29 -0
- package/build/tx/index.js.map +1 -0
- package/build/tx/noop-amount.d.ts +20 -0
- package/build/tx/noop-amount.js +90 -0
- package/build/tx/noop-amount.js.map +1 -0
- package/build/tx/recipient.d.ts +12 -0
- package/build/tx/recipient.js +80 -0
- package/build/tx/recipient.js.map +1 -0
- package/build/tx/send-tx.d.ts +9 -0
- package/build/tx/send-tx.js +22 -0
- package/build/tx/send-tx.js.map +1 -0
- package/build/tx/sender.d.ts +14 -0
- package/build/tx/sender.js +88 -0
- package/build/tx/sender.js.map +1 -0
- package/build/tx/types.d.ts +63 -0
- package/build/tx/types.js +3 -0
- package/build/tx/types.js.map +1 -0
- package/build/tx/validate.d.ts +11 -0
- package/build/tx/validate.js +52 -0
- package/build/tx/validate.js.map +1 -0
- package/jest.config.js +5 -0
- package/package.json +43 -0
- package/src/index.ts +1 -0
- package/src/tx/amount.ts +275 -0
- package/src/tx/chain.ts +32 -0
- package/src/tx/errors.ts +127 -0
- package/src/tx/fee.ts +209 -0
- package/src/tx/gas-simulator.ts +571 -0
- package/src/tx/gas.ts +131 -0
- package/src/tx/index.ts +12 -0
- package/src/tx/noop-amount.ts +92 -0
- package/src/tx/recipient.ts +82 -0
- package/src/tx/send-tx.ts +53 -0
- package/src/tx/sender.ts +104 -0
- package/src/tx/types.ts +97 -0
- package/src/tx/validate.ts +70 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemoSuspectMnemonicInclusion = exports.InvalidHexError = exports.NotSupportedCurrencyError = exports.UnknownCurrencyError = exports.InsufficientFeeError = exports.NotLoadedFeeError = exports.InsufficientAmountError = exports.NegativeAmountError = exports.ZeroAmountError = exports.InvalidNumberAmountError = exports.EmptyAmountError = exports.ICNSFailedToFetchError = exports.ICNSIsFetchingError = exports.InvalidBech32Error = exports.EmptyAddressError = exports.AccountNotDeployed = void 0;
|
|
4
|
+
class AccountNotDeployed extends Error {
|
|
5
|
+
constructor(m) {
|
|
6
|
+
super(m);
|
|
7
|
+
// Set the prototype explicitly.
|
|
8
|
+
Object.setPrototypeOf(this, AccountNotDeployed.prototype);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.AccountNotDeployed = AccountNotDeployed;
|
|
12
|
+
class EmptyAddressError extends Error {
|
|
13
|
+
constructor(m) {
|
|
14
|
+
super(m);
|
|
15
|
+
// Set the prototype explicitly.
|
|
16
|
+
Object.setPrototypeOf(this, EmptyAddressError.prototype);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.EmptyAddressError = EmptyAddressError;
|
|
20
|
+
class InvalidBech32Error extends Error {
|
|
21
|
+
constructor(m) {
|
|
22
|
+
super(m);
|
|
23
|
+
// Set the prototype explicitly.
|
|
24
|
+
Object.setPrototypeOf(this, InvalidBech32Error.prototype);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.InvalidBech32Error = InvalidBech32Error;
|
|
28
|
+
class ICNSIsFetchingError extends Error {
|
|
29
|
+
constructor(m) {
|
|
30
|
+
super(m);
|
|
31
|
+
// Set the prototype explicitly.
|
|
32
|
+
Object.setPrototypeOf(this, ICNSIsFetchingError.prototype);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.ICNSIsFetchingError = ICNSIsFetchingError;
|
|
36
|
+
class ICNSFailedToFetchError extends Error {
|
|
37
|
+
constructor(m) {
|
|
38
|
+
super(m);
|
|
39
|
+
// Set the prototype explicitly.
|
|
40
|
+
Object.setPrototypeOf(this, ICNSFailedToFetchError.prototype);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.ICNSFailedToFetchError = ICNSFailedToFetchError;
|
|
44
|
+
class EmptyAmountError extends Error {
|
|
45
|
+
constructor(m) {
|
|
46
|
+
super(m);
|
|
47
|
+
// Set the prototype explicitly.
|
|
48
|
+
Object.setPrototypeOf(this, EmptyAmountError.prototype);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.EmptyAmountError = EmptyAmountError;
|
|
52
|
+
class InvalidNumberAmountError extends Error {
|
|
53
|
+
constructor(m) {
|
|
54
|
+
super(m);
|
|
55
|
+
// Set the prototype explicitly.
|
|
56
|
+
Object.setPrototypeOf(this, InvalidNumberAmountError.prototype);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.InvalidNumberAmountError = InvalidNumberAmountError;
|
|
60
|
+
class ZeroAmountError extends Error {
|
|
61
|
+
constructor(m) {
|
|
62
|
+
super(m);
|
|
63
|
+
// Set the prototype explicitly.
|
|
64
|
+
Object.setPrototypeOf(this, ZeroAmountError.prototype);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.ZeroAmountError = ZeroAmountError;
|
|
68
|
+
class NegativeAmountError extends Error {
|
|
69
|
+
constructor(m) {
|
|
70
|
+
super(m);
|
|
71
|
+
// Set the prototype explicitly.
|
|
72
|
+
Object.setPrototypeOf(this, NegativeAmountError.prototype);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.NegativeAmountError = NegativeAmountError;
|
|
76
|
+
class InsufficientAmountError extends Error {
|
|
77
|
+
constructor(m) {
|
|
78
|
+
super(m);
|
|
79
|
+
// Set the prototype explicitly.
|
|
80
|
+
Object.setPrototypeOf(this, InsufficientAmountError.prototype);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.InsufficientAmountError = InsufficientAmountError;
|
|
84
|
+
class NotLoadedFeeError extends Error {
|
|
85
|
+
constructor(m) {
|
|
86
|
+
super(m);
|
|
87
|
+
// Set the prototype explicitly.
|
|
88
|
+
Object.setPrototypeOf(this, NotLoadedFeeError.prototype);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.NotLoadedFeeError = NotLoadedFeeError;
|
|
92
|
+
class InsufficientFeeError extends Error {
|
|
93
|
+
constructor(m) {
|
|
94
|
+
super(m);
|
|
95
|
+
// Set the prototype explicitly.
|
|
96
|
+
Object.setPrototypeOf(this, InsufficientFeeError.prototype);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.InsufficientFeeError = InsufficientFeeError;
|
|
100
|
+
class UnknownCurrencyError extends Error {
|
|
101
|
+
constructor(m) {
|
|
102
|
+
super(m);
|
|
103
|
+
// Set the prototype explicitly.
|
|
104
|
+
Object.setPrototypeOf(this, UnknownCurrencyError.prototype);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.UnknownCurrencyError = UnknownCurrencyError;
|
|
108
|
+
class NotSupportedCurrencyError extends Error {
|
|
109
|
+
constructor(m) {
|
|
110
|
+
super(m);
|
|
111
|
+
// Set the prototype explicitly.
|
|
112
|
+
Object.setPrototypeOf(this, UnknownCurrencyError.prototype);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.NotSupportedCurrencyError = NotSupportedCurrencyError;
|
|
116
|
+
class InvalidHexError extends Error {
|
|
117
|
+
constructor(m) {
|
|
118
|
+
super(m);
|
|
119
|
+
// Set the prototype explicitly.
|
|
120
|
+
Object.setPrototypeOf(this, InvalidHexError.prototype);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.InvalidHexError = InvalidHexError;
|
|
124
|
+
class MemoSuspectMnemonicInclusion extends Error {
|
|
125
|
+
constructor(m) {
|
|
126
|
+
super(m);
|
|
127
|
+
// Set the prototype explicitly.
|
|
128
|
+
Object.setPrototypeOf(this, MemoSuspectMnemonicInclusion.prototype);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.MemoSuspectMnemonicInclusion = MemoSuspectMnemonicInclusion;
|
|
132
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/tx/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,CAAS;QACnB,KAAK,CAAC,CAAC,CAAC,CAAC;QACT,gCAAgC;QAChC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAC5D,CAAC;CACF;AAND,gDAMC;AAED,MAAa,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,CAAS;QACnB,KAAK,CAAC,CAAC,CAAC,CAAC;QACT,gCAAgC;QAChC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAC3D,CAAC;CACF;AAND,8CAMC;AAED,MAAa,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,CAAS;QACnB,KAAK,CAAC,CAAC,CAAC,CAAC;QACT,gCAAgC;QAChC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAC5D,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0CAMC;AAED,MAAa,4BAA6B,SAAQ,KAAK;IACrD,YAAY,CAAS;QACnB,KAAK,CAAC,CAAC,CAAC,CAAC;QACT,gCAAgC;QAChC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,4BAA4B,CAAC,SAAS,CAAC,CAAC;IACtE,CAAC;CACF;AAND,oEAMC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { IAmountConfig, IFeeConfig, IGasConfig, ISenderConfig, UIProperties } from "./types";
|
|
2
|
+
import { TxChainSetter } from "./chain";
|
|
3
|
+
import { ChainGetter } from "@keplr-wallet/stores";
|
|
4
|
+
import { StarknetQueriesStore } from "@keplr-wallet/stores-starknet";
|
|
5
|
+
import { CoinPretty } from "@keplr-wallet/unit";
|
|
6
|
+
export declare class FeeConfig extends TxChainSetter implements IFeeConfig {
|
|
7
|
+
protected readonly starknetQueriesStore: StarknetQueriesStore;
|
|
8
|
+
protected readonly senderConfig: ISenderConfig;
|
|
9
|
+
protected readonly amountConfig: IAmountConfig;
|
|
10
|
+
protected readonly gasConfig: IGasConfig;
|
|
11
|
+
protected _gasPrice: CoinPretty | undefined;
|
|
12
|
+
protected _maxGasPrice: CoinPretty | undefined;
|
|
13
|
+
protected _type: "ETH" | "STRK";
|
|
14
|
+
protected _disableBalanceCheck: boolean;
|
|
15
|
+
constructor(chainGetter: ChainGetter, starknetQueriesStore: StarknetQueriesStore, initialChainId: string, senderConfig: ISenderConfig, amountConfig: IAmountConfig, gasConfig: IGasConfig);
|
|
16
|
+
setDisableBalanceCheck(bool: boolean): void;
|
|
17
|
+
get disableBalanceCheck(): boolean;
|
|
18
|
+
get uiProperties(): UIProperties;
|
|
19
|
+
get gasPrice(): CoinPretty | undefined;
|
|
20
|
+
get maxGasPrice(): CoinPretty | undefined;
|
|
21
|
+
get type(): "ETH" | "STRK";
|
|
22
|
+
setGasPrice(gasPrice: {
|
|
23
|
+
gasPrice: CoinPretty;
|
|
24
|
+
maxGasPrice: CoinPretty;
|
|
25
|
+
} | undefined): void;
|
|
26
|
+
setType(type: "ETH" | "STRK"): void;
|
|
27
|
+
get fee(): CoinPretty | undefined;
|
|
28
|
+
get maxFee(): CoinPretty | undefined;
|
|
29
|
+
}
|
|
30
|
+
export declare const useFeeConfig: (chainGetter: ChainGetter, queriesStore: StarknetQueriesStore, chainId: string, senderConfig: ISenderConfig, amountConfig: IAmountConfig, gasConfig: IGasConfig, initialFn?: ((config: FeeConfig) => void) | undefined) => FeeConfig;
|
package/build/tx/fee.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.useFeeConfig = exports.FeeConfig = void 0;
|
|
10
|
+
const chain_1 = require("./chain");
|
|
11
|
+
const mobx_1 = require("mobx");
|
|
12
|
+
const react_1 = require("react");
|
|
13
|
+
const unit_1 = require("@keplr-wallet/unit");
|
|
14
|
+
const errors_1 = require("./errors");
|
|
15
|
+
class FeeConfig extends chain_1.TxChainSetter {
|
|
16
|
+
constructor(chainGetter, starknetQueriesStore, initialChainId, senderConfig, amountConfig, gasConfig) {
|
|
17
|
+
super(chainGetter, initialChainId);
|
|
18
|
+
this.starknetQueriesStore = starknetQueriesStore;
|
|
19
|
+
this.senderConfig = senderConfig;
|
|
20
|
+
this.amountConfig = amountConfig;
|
|
21
|
+
this.gasConfig = gasConfig;
|
|
22
|
+
this._gasPrice = undefined;
|
|
23
|
+
this._maxGasPrice = undefined;
|
|
24
|
+
this._type = "STRK";
|
|
25
|
+
this._disableBalanceCheck = false;
|
|
26
|
+
(0, mobx_1.makeObservable)(this);
|
|
27
|
+
}
|
|
28
|
+
setDisableBalanceCheck(bool) {
|
|
29
|
+
this._disableBalanceCheck = bool;
|
|
30
|
+
}
|
|
31
|
+
get disableBalanceCheck() {
|
|
32
|
+
return this._disableBalanceCheck;
|
|
33
|
+
}
|
|
34
|
+
get uiProperties() {
|
|
35
|
+
if (this.disableBalanceCheck) {
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
if (!this._gasPrice) {
|
|
39
|
+
return {
|
|
40
|
+
error: new Error("Fee is not set"),
|
|
41
|
+
loadingState: "loading-block",
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (!this._maxGasPrice) {
|
|
45
|
+
return {
|
|
46
|
+
error: new Error("Fee is not set"),
|
|
47
|
+
loadingState: "loading-block",
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (!this.fee) {
|
|
51
|
+
return {
|
|
52
|
+
error: new Error("Fee is not set"),
|
|
53
|
+
loadingState: "loading-block",
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (!this.maxFee) {
|
|
57
|
+
return {
|
|
58
|
+
error: new Error("Fee is not set"),
|
|
59
|
+
loadingState: "loading-block",
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const maxFee = this.maxFee;
|
|
63
|
+
const bal = this.starknetQueriesStore
|
|
64
|
+
.get(this.chainId)
|
|
65
|
+
.queryStarknetERC20Balance.getBalance(this.chainId, this.chainGetter, this.senderConfig.value, maxFee.currency.coinMinimalDenom);
|
|
66
|
+
if (!bal) {
|
|
67
|
+
return {
|
|
68
|
+
warning: new Error(`Can't parse the balance for ${maxFee.currency.coinMinimalDenom}`),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (bal.error) {
|
|
72
|
+
return {
|
|
73
|
+
warning: new Error("Failed to fetch balance"),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (!bal.response) {
|
|
77
|
+
return {
|
|
78
|
+
loadingState: "loading-block",
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (new unit_1.Int(bal.balance.toCoin().amount).lt(new unit_1.Int(maxFee.toCoin().amount))) {
|
|
82
|
+
return {
|
|
83
|
+
error: new errors_1.InsufficientFeeError("Insufficient fee"),
|
|
84
|
+
loadingState: bal.isFetching ? "loading" : undefined,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return {};
|
|
88
|
+
}
|
|
89
|
+
get gasPrice() {
|
|
90
|
+
return this._gasPrice;
|
|
91
|
+
}
|
|
92
|
+
get maxGasPrice() {
|
|
93
|
+
return this._maxGasPrice;
|
|
94
|
+
}
|
|
95
|
+
get type() {
|
|
96
|
+
return this._type;
|
|
97
|
+
}
|
|
98
|
+
setGasPrice(gasPrice) {
|
|
99
|
+
this._gasPrice = gasPrice === null || gasPrice === void 0 ? void 0 : gasPrice.gasPrice;
|
|
100
|
+
this._maxGasPrice = gasPrice === null || gasPrice === void 0 ? void 0 : gasPrice.maxGasPrice;
|
|
101
|
+
}
|
|
102
|
+
setType(type) {
|
|
103
|
+
if (this._type !== type) {
|
|
104
|
+
this._type = type;
|
|
105
|
+
this._gasPrice = undefined;
|
|
106
|
+
this._maxGasPrice = undefined;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
get fee() {
|
|
110
|
+
if (!this._gasPrice) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const gasDec = new unit_1.Dec(this.gasConfig.gas);
|
|
114
|
+
return this._gasPrice.mul(gasDec);
|
|
115
|
+
}
|
|
116
|
+
get maxFee() {
|
|
117
|
+
if (!this._maxGasPrice) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const gasDec = new unit_1.Dec(this.gasConfig.gas);
|
|
121
|
+
return this._maxGasPrice.mul(gasDec);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
__decorate([
|
|
125
|
+
mobx_1.observable.ref
|
|
126
|
+
], FeeConfig.prototype, "_gasPrice", void 0);
|
|
127
|
+
__decorate([
|
|
128
|
+
mobx_1.observable.ref
|
|
129
|
+
], FeeConfig.prototype, "_maxGasPrice", void 0);
|
|
130
|
+
__decorate([
|
|
131
|
+
mobx_1.observable
|
|
132
|
+
], FeeConfig.prototype, "_type", void 0);
|
|
133
|
+
__decorate([
|
|
134
|
+
mobx_1.observable
|
|
135
|
+
], FeeConfig.prototype, "_disableBalanceCheck", void 0);
|
|
136
|
+
__decorate([
|
|
137
|
+
mobx_1.action
|
|
138
|
+
], FeeConfig.prototype, "setDisableBalanceCheck", null);
|
|
139
|
+
__decorate([
|
|
140
|
+
mobx_1.computed
|
|
141
|
+
], FeeConfig.prototype, "uiProperties", null);
|
|
142
|
+
__decorate([
|
|
143
|
+
mobx_1.action
|
|
144
|
+
], FeeConfig.prototype, "setGasPrice", null);
|
|
145
|
+
__decorate([
|
|
146
|
+
mobx_1.action
|
|
147
|
+
], FeeConfig.prototype, "setType", null);
|
|
148
|
+
__decorate([
|
|
149
|
+
mobx_1.computed
|
|
150
|
+
], FeeConfig.prototype, "fee", null);
|
|
151
|
+
__decorate([
|
|
152
|
+
mobx_1.computed
|
|
153
|
+
], FeeConfig.prototype, "maxFee", null);
|
|
154
|
+
exports.FeeConfig = FeeConfig;
|
|
155
|
+
const useFeeConfig = (chainGetter, queriesStore, chainId, senderConfig, amountConfig, gasConfig, initialFn) => {
|
|
156
|
+
const [config] = (0, react_1.useState)(() => {
|
|
157
|
+
const config = new FeeConfig(chainGetter, queriesStore, chainId, senderConfig, amountConfig, gasConfig);
|
|
158
|
+
if (initialFn) {
|
|
159
|
+
initialFn(config);
|
|
160
|
+
}
|
|
161
|
+
return config;
|
|
162
|
+
});
|
|
163
|
+
config.setChain(chainId);
|
|
164
|
+
return config;
|
|
165
|
+
};
|
|
166
|
+
exports.useFeeConfig = useFeeConfig;
|
|
167
|
+
//# sourceMappingURL=fee.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fee.js","sourceRoot":"","sources":["../../src/tx/fee.ts"],"names":[],"mappings":";;;;;;;;;AAOA,mCAAwC;AAExC,+BAAoE;AACpE,iCAAiC;AAEjC,6CAA0D;AAC1D,qCAAgD;AAEhD,MAAa,SAAU,SAAQ,qBAAa;IAW1C,YACE,WAAwB,EACL,oBAA0C,EAC7D,cAAsB,EACH,YAA2B,EAC3B,YAA2B,EAC3B,SAAqB;QAExC,KAAK,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QANhB,yBAAoB,GAApB,oBAAoB,CAAsB;QAE1C,iBAAY,GAAZ,YAAY,CAAe;QAC3B,iBAAY,GAAZ,YAAY,CAAe;QAC3B,cAAS,GAAT,SAAS,CAAY;QAfhC,cAAS,GAA2B,SAAS,CAAC;QAE9C,iBAAY,GAA2B,SAAS,CAAC;QAEjD,UAAK,GAAmB,MAAM,CAAC;QAG/B,yBAAoB,GAAY,KAAK,CAAC;QAY9C,IAAA,qBAAc,EAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IAGD,sBAAsB,CAAC,IAAa;QAClC,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;IACnC,CAAC;IAED,IAAI,mBAAmB;QACrB,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACnC,CAAC;IAGD,IAAI,YAAY;QACd,IAAI,IAAI,CAAC,mBAAmB,EAAE;YAC5B,OAAO,EAAE,CAAC;SACX;QAED,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACnB,OAAO;gBACL,KAAK,EAAE,IAAI,KAAK,CAAC,gBAAgB,CAAC;gBAClC,YAAY,EAAE,eAAe;aAC9B,CAAC;SACH;QAED,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;YACtB,OAAO;gBACL,KAAK,EAAE,IAAI,KAAK,CA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IACvC,CAAC;CACF;AAjKW;IADT,iBAAU,CAAC,GAAG;4CACyC;AAE9C;IADT,iBAAU,CAAC,GAAG;+CAC4C;AAEjD;IADT,iBAAU;wCAC8B;AAG/B;IADT,iBAAU;uDACqC;AAgBhD;IADC,aAAM;uDAGN;AAOD;IADC,eAAQ;6CA2ER;AAeD;IADC,aAAM;4CAWN;AAGD;IADC,aAAM;wCAON;AAGD;IADC,eAAQ;oCAQR;AAGD;IADC,eAAQ;uCAQR;AAlKH,8BAmKC;AAEM,MAAM,YAAY,GAAG,CAC1B,WAAwB,EACxB,YAAkC,EAClC,OAAe,EACf,YAA2B,EAC3B,YAA2B,EAC3B,SAAqB,EACrB,SAAuC,EACvC,EAAE;IACF,MAAM,CAAC,MAAM,CAAC,GAAG,IAAA,gBAAQ,EAAC,GAAG,EAAE;QAC7B,MAAM,MAAM,GAAG,IAAI,SAAS,CAC1B,WAAW,EACX,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,SAAS,CACV,CAAC;QAEF,IAAI,SAAS,EAAE;YACb,SAAS,CAAC,MAAM,CAAC,CAAC;SACnB;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAEzB,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AA5BW,QAAA,YAAY,gBA4BvB"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { IFeeConfig, IGasConfig, IGasSimulator, UIProperties } from "./types";
|
|
2
|
+
import { IReactionDisposer } from "mobx";
|
|
3
|
+
import { KVStore } from "@keplr-wallet/common";
|
|
4
|
+
import { TxChainSetter } from "./chain";
|
|
5
|
+
import { ChainGetter, MakeTxResponse } from "@keplr-wallet/stores";
|
|
6
|
+
import { Coin, StdFee } from "@keplr-wallet/types";
|
|
7
|
+
type TxSimulate = Pick<MakeTxResponse, "simulate">;
|
|
8
|
+
export type SimulateGasFn = () => TxSimulate;
|
|
9
|
+
declare class GasSimulatorState {
|
|
10
|
+
protected _outdatedCosmosSdk: boolean;
|
|
11
|
+
protected _initialGasEstimated: number | null;
|
|
12
|
+
protected _isInitialized: boolean;
|
|
13
|
+
protected _recentGasEstimated: number | undefined;
|
|
14
|
+
protected _tx: TxSimulate | undefined;
|
|
15
|
+
protected _stdFee: StdFee | undefined;
|
|
16
|
+
protected _error: Error | undefined;
|
|
17
|
+
constructor();
|
|
18
|
+
get outdatedCosmosSdk(): boolean;
|
|
19
|
+
setIsInitialized(value: boolean): void;
|
|
20
|
+
get isInitialized(): boolean;
|
|
21
|
+
setOutdatedCosmosSdk(value: boolean): void;
|
|
22
|
+
get initialGasEstimated(): number | null;
|
|
23
|
+
setInitialGasEstimated(value: number): void;
|
|
24
|
+
get recentGasEstimated(): number | undefined;
|
|
25
|
+
setRecentGasEstimated(value: number): void;
|
|
26
|
+
get tx(): TxSimulate | undefined;
|
|
27
|
+
refreshTx(tx: TxSimulate | undefined): void;
|
|
28
|
+
get stdFee(): StdFee | undefined;
|
|
29
|
+
refreshStdFee(fee: StdFee | undefined): void;
|
|
30
|
+
get error(): Error | undefined;
|
|
31
|
+
setError(error: Error | undefined): void;
|
|
32
|
+
static isZeroFee(amount: readonly Coin[] | undefined): boolean;
|
|
33
|
+
}
|
|
34
|
+
export declare class GasSimulator extends TxChainSetter implements IGasSimulator {
|
|
35
|
+
protected kvStore: KVStore;
|
|
36
|
+
protected readonly gasConfig: IGasConfig;
|
|
37
|
+
protected readonly feeConfig: IFeeConfig;
|
|
38
|
+
protected readonly initialKey: string;
|
|
39
|
+
protected simulateGasFn: SimulateGasFn;
|
|
40
|
+
protected _key: string;
|
|
41
|
+
protected _gasAdjustmentValue: string;
|
|
42
|
+
protected _enabled: boolean;
|
|
43
|
+
protected _forceDisabled: boolean;
|
|
44
|
+
protected _forceDisableReason: Error | undefined;
|
|
45
|
+
protected _isSimulating: boolean;
|
|
46
|
+
protected _stateMap: Map<string, GasSimulatorState>;
|
|
47
|
+
protected _disposers: IReactionDisposer[];
|
|
48
|
+
constructor(kvStore: KVStore, chainGetter: ChainGetter, initialChainId: string, gasConfig: IGasConfig, feeConfig: IFeeConfig, initialKey: string, simulateGasFn: SimulateGasFn);
|
|
49
|
+
setKVStore(kvStore: KVStore): void;
|
|
50
|
+
get key(): string;
|
|
51
|
+
setKey(value: string): void;
|
|
52
|
+
get isSimulating(): boolean;
|
|
53
|
+
setSimulateGasFn(simulateGasFn: SimulateGasFn): void;
|
|
54
|
+
get enabled(): boolean;
|
|
55
|
+
setEnabled(value: boolean): void;
|
|
56
|
+
get forceDisabled(): boolean;
|
|
57
|
+
get forceDisableReason(): Error | undefined;
|
|
58
|
+
forceDisable(valueOrReason: boolean | Error): void;
|
|
59
|
+
get outdatedCosmosSdk(): boolean;
|
|
60
|
+
get error(): Error | undefined;
|
|
61
|
+
get gasEstimated(): number | undefined;
|
|
62
|
+
get gasAdjustment(): number;
|
|
63
|
+
get gasAdjustmentValue(): string;
|
|
64
|
+
setGasAdjustmentValue(gasAdjustment: string | number): void;
|
|
65
|
+
protected init(): void;
|
|
66
|
+
dispose(): void;
|
|
67
|
+
get uiProperties(): UIProperties;
|
|
68
|
+
protected getState(key: string): GasSimulatorState;
|
|
69
|
+
protected get storeKey(): string;
|
|
70
|
+
}
|
|
71
|
+
export declare const useGasSimulator: (kvStore: KVStore, chainGetter: ChainGetter, chainId: string, gasConfig: IGasConfig, feeConfig: IFeeConfig, key: string, simulateGasFn: SimulateGasFn, initialDisabled?: boolean) => GasSimulator;
|
|
72
|
+
export {};
|