@keplr-wallet/hooks 0.9.18 → 0.10.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.
Files changed (77) hide show
  1. package/build/ibc/amount.d.ts +4 -4
  2. package/build/ibc/amount.js +5 -5
  3. package/build/ibc/amount.js.map +1 -1
  4. package/build/ibc/channel.d.ts +1 -1
  5. package/build/ibc/channel.js +4 -1
  6. package/build/ibc/channel.js.map +1 -1
  7. package/build/ibc/gas.d.ts +22 -5
  8. package/build/ibc/gas.js +8 -14
  9. package/build/ibc/gas.js.map +1 -1
  10. package/build/ibc/send-ibc-transfer.d.ts +10 -5
  11. package/build/ibc/send-ibc-transfer.js +6 -6
  12. package/build/ibc/send-ibc-transfer.js.map +1 -1
  13. package/build/ibc/types.d.ts +1 -1
  14. package/build/sign-doc/amount.d.ts +10 -6
  15. package/build/sign-doc/amount.js +8 -17
  16. package/build/sign-doc/amount.js.map +1 -1
  17. package/build/tx/amount.d.ts +5 -7
  18. package/build/tx/amount.js +14 -19
  19. package/build/tx/amount.js.map +1 -1
  20. package/build/tx/delegate-tx.d.ts +35 -6
  21. package/build/tx/delegate-tx.js +39 -9
  22. package/build/tx/delegate-tx.js.map +1 -1
  23. package/build/tx/errors.d.ts +3 -0
  24. package/build/tx/errors.js +9 -1
  25. package/build/tx/errors.js.map +1 -1
  26. package/build/tx/fee.d.ts +5 -7
  27. package/build/tx/fee.js +13 -19
  28. package/build/tx/fee.js.map +1 -1
  29. package/build/tx/gas.d.ts +1 -1
  30. package/build/tx/gas.js +7 -1
  31. package/build/tx/gas.js.map +1 -1
  32. package/build/tx/memo.d.ts +1 -1
  33. package/build/tx/memo.js +1 -1
  34. package/build/tx/memo.js.map +1 -1
  35. package/build/tx/recipient.d.ts +1 -1
  36. package/build/tx/recipient.js +4 -1
  37. package/build/tx/recipient.js.map +1 -1
  38. package/build/tx/redelegate-tx.d.ts +36 -4
  39. package/build/tx/redelegate-tx.js +38 -6
  40. package/build/tx/redelegate-tx.js.map +1 -1
  41. package/build/tx/send-gas.d.ts +6 -7
  42. package/build/tx/send-gas.js +41 -15
  43. package/build/tx/send-gas.js.map +1 -1
  44. package/build/tx/send-tx.d.ts +3 -5
  45. package/build/tx/send-tx.js +4 -4
  46. package/build/tx/send-tx.js.map +1 -1
  47. package/build/tx/send-types.d.ts +24 -0
  48. package/build/tx/send-types.js +3 -0
  49. package/build/tx/send-types.js.map +1 -0
  50. package/build/tx/staked-amount.d.ts +11 -6
  51. package/build/tx/staked-amount.js +14 -19
  52. package/build/tx/staked-amount.js.map +1 -1
  53. package/build/tx/types.d.ts +5 -5
  54. package/build/tx/undelegate-tx.d.ts +36 -4
  55. package/build/tx/undelegate-tx.js +38 -6
  56. package/build/tx/undelegate-tx.js.map +1 -1
  57. package/package.json +11 -11
  58. package/src/ibc/amount.ts +7 -15
  59. package/src/ibc/channel.ts +3 -2
  60. package/src/ibc/gas.ts +22 -19
  61. package/src/ibc/send-ibc-transfer.ts +20 -10
  62. package/src/ibc/types.ts +1 -1
  63. package/src/sign-doc/amount.ts +15 -16
  64. package/src/tx/amount.ts +18 -22
  65. package/src/tx/delegate-tx.ts +72 -15
  66. package/src/tx/errors.ts +8 -0
  67. package/src/tx/fee.ts +15 -20
  68. package/src/tx/gas.ts +4 -2
  69. package/src/tx/memo.ts +1 -1
  70. package/src/tx/recipient.ts +2 -1
  71. package/src/tx/redelegate-tx.ts +71 -10
  72. package/src/tx/send-gas.ts +48 -28
  73. package/src/tx/send-tx.ts +9 -16
  74. package/src/tx/send-types.ts +25 -0
  75. package/src/tx/staked-amount.ts +17 -19
  76. package/src/tx/types.ts +5 -5
  77. package/src/tx/undelegate-tx.ts +71 -10
@@ -3,6 +3,7 @@ import {
3
3
  ChainGetter,
4
4
  CoinPrimitive,
5
5
  CosmosMsgOpts,
6
+ IAccountStore,
6
7
  } from "@keplr-wallet/stores";
7
8
  import { AppCurrency } from "@keplr-wallet/types";
8
9
  import { action, computed, makeObservable, observable } from "mobx";
@@ -13,15 +14,18 @@ import { computedFn } from "mobx-utils";
13
14
  import { Msg } from "@cosmjs/launchpad";
14
15
  import { cosmos } from "@keplr-wallet/cosmos";
15
16
 
17
+ export type AccountStore = IAccountStore<{
18
+ cosmos: {
19
+ readonly msgOpts: CosmosMsgOpts;
20
+ };
21
+ }>;
22
+
16
23
  // This config helps the fee config to calculate that the fee is enough to send with considering
17
24
  // the amount in the sign doc.
18
25
  // This sets the amount as the sum of the messages in the sign doc if the message is known and can be parsed.
19
26
  export class SignDocAmountConfig
20
27
  extends TxChainSetter
21
28
  implements IAmountConfig {
22
- @observable.ref
23
- protected msgOpts: CosmosMsgOpts;
24
-
25
29
  @observable.ref
26
30
  protected signDocHelper?: SignDocHelper = undefined;
27
31
 
@@ -33,23 +37,17 @@ export class SignDocAmountConfig
33
37
 
34
38
  constructor(
35
39
  chainGetter: ChainGetter,
40
+ protected readonly accountStore: AccountStore,
36
41
  initialChainId: string,
37
- msgOpts: CosmosMsgOpts,
38
42
  sender: string
39
43
  ) {
40
44
  super(chainGetter, initialChainId);
41
45
 
42
- this.msgOpts = msgOpts;
43
46
  this._sender = sender;
44
47
 
45
48
  makeObservable(this);
46
49
  }
47
50
 
48
- @action
49
- setMsgOpts(opts: CosmosMsgOpts) {
50
- this.msgOpts = opts;
51
- }
52
-
53
51
  @action
54
52
  setSignDocHelper(signDocHelper: SignDocHelper) {
55
53
  this.signDocHelper = signDocHelper;
@@ -115,10 +113,12 @@ export class SignDocAmountConfig
115
113
  protected computeAmountInAminoMsgs(msgs: readonly Msg[]) {
116
114
  const amount = new Coin(this.sendCurrency.coinMinimalDenom, new Int(0));
117
115
 
116
+ const account = this.accountStore.getAccount(this.chainId);
117
+
118
118
  for (const msg of msgs) {
119
119
  try {
120
120
  switch (msg.type) {
121
- case this.msgOpts.send.native.type:
121
+ case account.cosmos.msgOpts.send.native.type:
122
122
  if (
123
123
  msg.value.from_address &&
124
124
  msg.value.from_address !== this.sender
@@ -138,7 +138,7 @@ export class SignDocAmountConfig
138
138
  }
139
139
  }
140
140
  break;
141
- case this.msgOpts.delegate.type:
141
+ case account.cosmos.msgOpts.delegate.type:
142
142
  if (
143
143
  msg.value.delegator_address &&
144
144
  msg.value.delegator_address !== this.sender
@@ -222,7 +222,7 @@ export class SignDocAmountConfig
222
222
  };
223
223
  }
224
224
 
225
- getError(): Error | undefined {
225
+ get error(): Error | undefined {
226
226
  return undefined;
227
227
  }
228
228
 
@@ -267,15 +267,14 @@ export class SignDocAmountConfig
267
267
 
268
268
  export const useSignDocAmountConfig = (
269
269
  chainGetter: ChainGetter,
270
+ accountStore: AccountStore,
270
271
  chainId: string,
271
- msgOpts: CosmosMsgOpts,
272
272
  sender: string
273
273
  ) => {
274
274
  const [config] = useState(
275
- () => new SignDocAmountConfig(chainGetter, chainId, msgOpts, sender)
275
+ () => new SignDocAmountConfig(chainGetter, accountStore, chainId, sender)
276
276
  );
277
277
  config.setChain(chainId);
278
- config.setMsgOpts(msgOpts);
279
278
  config.setSender(sender);
280
279
 
281
280
  return config;
package/src/tx/amount.ts CHANGED
@@ -1,8 +1,11 @@
1
1
  import { IAmountConfig, IFeeConfig } from "./types";
2
2
  import { TxChainSetter } from "./chain";
3
- import { ChainGetter, CoinPrimitive } from "@keplr-wallet/stores";
3
+ import {
4
+ ChainGetter,
5
+ CoinPrimitive,
6
+ IQueriesStore,
7
+ } from "@keplr-wallet/stores";
4
8
  import { action, computed, makeObservable, observable } from "mobx";
5
- import { ObservableQueryBalances } from "@keplr-wallet/stores/build/query/balances";
6
9
  import { AppCurrency } from "@keplr-wallet/types";
7
10
  import {
8
11
  EmptyAmountError,
@@ -18,9 +21,6 @@ export class AmountConfig extends TxChainSetter implements IAmountConfig {
18
21
  @observable.ref
19
22
  protected feeConfig?: IFeeConfig;
20
23
 
21
- @observable.ref
22
- protected queryBalances: ObservableQueryBalances;
23
-
24
24
  @observable
25
25
  protected _sender: string;
26
26
 
@@ -35,16 +35,15 @@ export class AmountConfig extends TxChainSetter implements IAmountConfig {
35
35
 
36
36
  constructor(
37
37
  chainGetter: ChainGetter,
38
+ protected readonly queriesStore: IQueriesStore,
38
39
  initialChainId: string,
39
40
  sender: string,
40
- feeConfig: IFeeConfig | undefined,
41
- queryBalances: ObservableQueryBalances
41
+ feeConfig: IFeeConfig | undefined
42
42
  ) {
43
43
  super(chainGetter, initialChainId);
44
44
 
45
45
  this._sender = sender;
46
46
  this.feeConfig = feeConfig;
47
- this.queryBalances = queryBalances;
48
47
  this._amount = "";
49
48
 
50
49
  makeObservable(this);
@@ -55,11 +54,6 @@ export class AmountConfig extends TxChainSetter implements IAmountConfig {
55
54
  this.feeConfig = feeConfig;
56
55
  }
57
56
 
58
- @action
59
- setQueryBalances(queryBalances: ObservableQueryBalances) {
60
- this.queryBalances = queryBalances;
61
- }
62
-
63
57
  @action
64
58
  setSender(sender: string) {
65
59
  this._sender = sender;
@@ -112,8 +106,9 @@ export class AmountConfig extends TxChainSetter implements IAmountConfig {
112
106
  @computed
113
107
  get amount(): string {
114
108
  if (this.fraction != null) {
115
- const balance = this.queryBalances
116
- .getQueryBech32Address(this.sender)
109
+ const balance = this.queriesStore
110
+ .get(this.chainId)
111
+ .queryBalances.getQueryBech32Address(this.sender)
117
112
  .getBalanceFromCurrency(this.sendCurrency);
118
113
 
119
114
  const result = this.feeConfig?.fee
@@ -187,7 +182,8 @@ export class AmountConfig extends TxChainSetter implements IAmountConfig {
187
182
  return this.chainInfo.currencies;
188
183
  }
189
184
 
190
- getError(): Error | undefined {
185
+ @computed
186
+ get error(): Error | undefined {
191
187
  const sendCurrency = this.sendCurrency;
192
188
  if (!sendCurrency) {
193
189
  return new Error("Currency to send not set");
@@ -211,8 +207,9 @@ export class AmountConfig extends TxChainSetter implements IAmountConfig {
211
207
  return new NegativeAmountError("Amount is negative");
212
208
  }
213
209
 
214
- const balance = this.queryBalances
215
- .getQueryBech32Address(this.sender)
210
+ const balance = this.queriesStore
211
+ .get(this.chainId)
212
+ .queryBalances.getQueryBech32Address(this.sender)
216
213
  .getBalanceFromCurrency(this.sendCurrency);
217
214
  const balanceDec = balance.toDec();
218
215
  if (dec.gt(balanceDec)) {
@@ -225,16 +222,15 @@ export class AmountConfig extends TxChainSetter implements IAmountConfig {
225
222
 
226
223
  export const useAmountConfig = (
227
224
  chainGetter: ChainGetter,
225
+ queriesStore: IQueriesStore,
228
226
  chainId: string,
229
- sender: string,
230
- queryBalances: ObservableQueryBalances
227
+ sender: string
231
228
  ) => {
232
229
  const [txConfig] = useState(
233
230
  () =>
234
- new AmountConfig(chainGetter, chainId, sender, undefined, queryBalances)
231
+ new AmountConfig(chainGetter, queriesStore, chainId, sender, undefined)
235
232
  );
236
233
  txConfig.setChain(chainId);
237
- txConfig.setQueryBalances(queryBalances);
238
234
  txConfig.setSender(sender);
239
235
 
240
236
  return txConfig;
@@ -1,14 +1,19 @@
1
- import { ChainGetter } from "@keplr-wallet/stores";
2
- import { ObservableQueryBalances } from "@keplr-wallet/stores/build/query/balances";
1
+ import {
2
+ ChainGetter,
3
+ IAccountStore,
4
+ IQueriesStore,
5
+ MsgOpt,
6
+ } from "@keplr-wallet/stores";
3
7
  import {
4
8
  AmountConfig,
9
+ GasConfig,
5
10
  useFeeConfig,
6
- useGasConfig,
7
11
  useMemoConfig,
8
12
  useRecipientConfig,
9
13
  } from "./index";
10
14
  import { AppCurrency } from "@keplr-wallet/types";
11
15
  import { useState } from "react";
16
+ import { makeObservable, override } from "mobx";
12
17
 
13
18
  export class DelegateAmountConfig extends AmountConfig {
14
19
  get sendableCurrencies(): AppCurrency[] {
@@ -16,52 +21,104 @@ export class DelegateAmountConfig extends AmountConfig {
16
21
  }
17
22
  }
18
23
 
24
+ export class DelegateGasConfig extends GasConfig {
25
+ constructor(
26
+ chainGetter: ChainGetter,
27
+ protected readonly accountStore: IAccountStore<{
28
+ cosmos: {
29
+ readonly msgOpts: {
30
+ readonly delegate: MsgOpt;
31
+ };
32
+ };
33
+ }>,
34
+ initialChainId: string
35
+ ) {
36
+ super(chainGetter, initialChainId);
37
+
38
+ makeObservable(this);
39
+ }
40
+
41
+ @override
42
+ get gas(): number {
43
+ // If gas not set manually, assume that the tx is for MsgTransfer.
44
+ if (this._gasRaw == null) {
45
+ return this.accountStore.getAccount(this.chainId).cosmos.msgOpts.delegate
46
+ .gas;
47
+ }
48
+
49
+ return super.gas;
50
+ }
51
+ }
52
+
19
53
  export const useDelegateAmountConfig = (
20
54
  chainGetter: ChainGetter,
55
+ queriesStore: IQueriesStore,
21
56
  chainId: string,
22
- sender: string,
23
- queryBalances: ObservableQueryBalances
57
+ sender: string
24
58
  ) => {
25
59
  const [txConfig] = useState(
26
60
  () =>
27
61
  new DelegateAmountConfig(
28
62
  chainGetter,
63
+ queriesStore,
29
64
  chainId,
30
65
  sender,
31
- undefined,
32
- queryBalances
66
+ undefined
33
67
  )
34
68
  );
35
69
  txConfig.setChain(chainId);
36
- txConfig.setQueryBalances(queryBalances);
37
70
  txConfig.setSender(sender);
38
71
 
39
72
  return txConfig;
40
73
  };
41
74
 
75
+ export const useDelegateGasConfig = (
76
+ chainGetter: ChainGetter,
77
+ accountStore: IAccountStore<{
78
+ cosmos: {
79
+ readonly msgOpts: {
80
+ readonly delegate: MsgOpt;
81
+ };
82
+ };
83
+ }>,
84
+ chainId: string
85
+ ) => {
86
+ const [gasConfig] = useState(
87
+ () => new DelegateGasConfig(chainGetter, accountStore, chainId)
88
+ );
89
+ gasConfig.setChain(chainId);
90
+
91
+ return gasConfig;
92
+ };
93
+
42
94
  export const useDelegateTxConfig = (
43
95
  chainGetter: ChainGetter,
96
+ queriesStore: IQueriesStore,
97
+ accountStore: IAccountStore<{
98
+ cosmos: {
99
+ readonly msgOpts: {
100
+ readonly delegate: MsgOpt;
101
+ };
102
+ };
103
+ }>,
44
104
  chainId: string,
45
- gas: number,
46
105
  sender: string,
47
- queryBalances: ObservableQueryBalances,
48
106
  ensEndpoint?: string
49
107
  ) => {
50
108
  const amountConfig = useDelegateAmountConfig(
51
109
  chainGetter,
110
+ queriesStore,
52
111
  chainId,
53
- sender,
54
- queryBalances
112
+ sender
55
113
  );
56
114
 
57
115
  const memoConfig = useMemoConfig(chainGetter, chainId);
58
- const gasConfig = useGasConfig(chainGetter, chainId, gas);
59
- gasConfig.setGas(gas);
116
+ const gasConfig = useDelegateGasConfig(chainGetter, accountStore, chainId);
60
117
  const feeConfig = useFeeConfig(
61
118
  chainGetter,
119
+ queriesStore,
62
120
  chainId,
63
121
  sender,
64
- queryBalances,
65
122
  amountConfig,
66
123
  gasConfig
67
124
  );
package/src/tx/errors.ts CHANGED
@@ -93,3 +93,11 @@ export class InsufficientFeeError extends Error {
93
93
  Object.setPrototypeOf(this, InsufficientFeeError.prototype);
94
94
  }
95
95
  }
96
+
97
+ export class UnknownCurrencyError extends Error {
98
+ constructor(m: string) {
99
+ super(m);
100
+ // Set the prototype explicitly.
101
+ Object.setPrototypeOf(this, UnknownCurrencyError.prototype);
102
+ }
103
+ }
package/src/tx/fee.ts CHANGED
@@ -6,20 +6,20 @@ import {
6
6
  IGasConfig,
7
7
  } from "./types";
8
8
  import { TxChainSetter } from "./chain";
9
- import { ChainGetter, CoinPrimitive } from "@keplr-wallet/stores";
9
+ import {
10
+ ChainGetter,
11
+ CoinPrimitive,
12
+ IQueriesStore,
13
+ } from "@keplr-wallet/stores";
10
14
  import { action, computed, makeObservable, observable } from "mobx";
11
15
  import { Coin, CoinPretty, Dec, DecUtils, Int } from "@keplr-wallet/unit";
12
16
  import { Currency } from "@keplr-wallet/types";
13
17
  import { computedFn } from "mobx-utils";
14
18
  import { StdFee } from "@cosmjs/launchpad";
15
19
  import { useState } from "react";
16
- import { ObservableQueryBalances } from "@keplr-wallet/stores/build/query/balances";
17
20
  import { InsufficientFeeError, NotLoadedFeeError } from "./errors";
18
21
 
19
22
  export class FeeConfig extends TxChainSetter implements IFeeConfig {
20
- @observable.ref
21
- protected queryBalances: ObservableQueryBalances;
22
-
23
23
  @observable
24
24
  protected _sender: string;
25
25
 
@@ -44,9 +44,9 @@ export class FeeConfig extends TxChainSetter implements IFeeConfig {
44
44
 
45
45
  constructor(
46
46
  chainGetter: ChainGetter,
47
+ protected readonly queriesStore: IQueriesStore,
47
48
  initialChainId: string,
48
49
  sender: string,
49
- queryBalances: ObservableQueryBalances,
50
50
  protected readonly amountConfig: IAmountConfig,
51
51
  protected readonly gasConfig: IGasConfig,
52
52
  additionAmountToNeedFee: boolean = true
@@ -54,7 +54,6 @@ export class FeeConfig extends TxChainSetter implements IFeeConfig {
54
54
  super(chainGetter, initialChainId);
55
55
 
56
56
  this._sender = sender;
57
- this.queryBalances = queryBalances;
58
57
  this.additionAmountToNeedFee = additionAmountToNeedFee;
59
58
 
60
59
  makeObservable(this);
@@ -65,11 +64,6 @@ export class FeeConfig extends TxChainSetter implements IFeeConfig {
65
64
  this.additionAmountToNeedFee = additionAmountToNeedFee;
66
65
  }
67
66
 
68
- @action
69
- setQueryBalances(queryBalances: ObservableQueryBalances) {
70
- this.queryBalances = queryBalances;
71
- }
72
-
73
67
  @action
74
68
  setSender(sender: string) {
75
69
  this._sender = sender;
@@ -182,9 +176,10 @@ export class FeeConfig extends TxChainSetter implements IFeeConfig {
182
176
  ).maxDecimals(feeCurrency.coinDecimals);
183
177
  });
184
178
 
185
- getError(): Error | undefined {
186
- if (this.gasConfig.getError()) {
187
- return this.gasConfig.getError();
179
+ @computed
180
+ get error(): Error | undefined {
181
+ if (this.gasConfig.error) {
182
+ return this.gasConfig.error;
188
183
  }
189
184
 
190
185
  if (this.disableBalanceCheck) {
@@ -209,8 +204,9 @@ export class FeeConfig extends TxChainSetter implements IFeeConfig {
209
204
  }
210
205
 
211
206
  if (need.amount.gt(new Int(0))) {
212
- const bal = this.queryBalances
213
- .getQueryBech32Address(this._sender)
207
+ const bal = this.queriesStore
208
+ .get(this.chainId)
209
+ .queryBalances.getQueryBech32Address(this._sender)
214
210
  .balances.find((bal) => {
215
211
  return bal.currency.coinMinimalDenom === need.denom;
216
212
  });
@@ -247,9 +243,9 @@ export class FeeConfig extends TxChainSetter implements IFeeConfig {
247
243
 
248
244
  export const useFeeConfig = (
249
245
  chainGetter: ChainGetter,
246
+ queriesStore: IQueriesStore,
250
247
  chainId: string,
251
248
  sender: string,
252
- queryBalances: ObservableQueryBalances,
253
249
  amountConfig: IAmountConfig,
254
250
  gasConfig: IGasConfig,
255
251
  additionAmountToNeedFee: boolean = true
@@ -258,16 +254,15 @@ export const useFeeConfig = (
258
254
  () =>
259
255
  new FeeConfig(
260
256
  chainGetter,
257
+ queriesStore,
261
258
  chainId,
262
259
  sender,
263
- queryBalances,
264
260
  amountConfig,
265
261
  gasConfig,
266
262
  additionAmountToNeedFee
267
263
  )
268
264
  );
269
265
  config.setChain(chainId);
270
- config.setQueryBalances(queryBalances);
271
266
  config.setSender(sender);
272
267
  config.setAdditionAmountToNeedFee(additionAmountToNeedFee);
273
268
 
package/src/tx/gas.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { IGasConfig } from "./types";
2
2
  import { TxChainSetter } from "./chain";
3
3
  import { ChainGetter } from "@keplr-wallet/stores";
4
- import { action, makeObservable, observable } from "mobx";
4
+ import { action, computed, makeObservable, observable } from "mobx";
5
5
  import { useState } from "react";
6
6
 
7
7
  export class GasConfig extends TxChainSetter implements IGasConfig {
@@ -33,6 +33,7 @@ export class GasConfig extends TxChainSetter implements IGasConfig {
33
33
  return this._gasRaw;
34
34
  }
35
35
 
36
+ @computed
36
37
  get gas(): number {
37
38
  // If the gasRaw is undefined,
38
39
  // it means that the user never input something yet.
@@ -67,7 +68,8 @@ export class GasConfig extends TxChainSetter implements IGasConfig {
67
68
  }
68
69
  }
69
70
 
70
- getError(): Error | undefined {
71
+ @computed
72
+ get error(): Error | undefined {
71
73
  if (this._gasRaw === "") {
72
74
  return new Error("Gas not set");
73
75
  }
package/src/tx/memo.ts CHANGED
@@ -22,7 +22,7 @@ export class MemoConfig extends TxChainSetter implements IMemoConfig {
22
22
  this._memo = memo;
23
23
  }
24
24
 
25
- getError(): Error | undefined {
25
+ get error(): Error | undefined {
26
26
  return undefined;
27
27
  }
28
28
  }
@@ -107,7 +107,8 @@ export class RecipientConfig extends TxChainSetter implements IRecipientConfig {
107
107
  this._ensEndpoint = endpoint;
108
108
  }
109
109
 
110
- getError(): Error | undefined {
110
+ @computed
111
+ get error(): Error | undefined {
111
112
  if (!this.rawRecipient) {
112
113
  return new EmptyAddressError("Address is empty");
113
114
  }
@@ -1,38 +1,99 @@
1
- import { ChainGetter, ObservableQueryDelegations } from "@keplr-wallet/stores";
2
- import { ObservableQueryBalances } from "@keplr-wallet/stores/build/query/balances";
3
1
  import {
2
+ ChainGetter,
3
+ IQueriesStore,
4
+ CosmosQueriesImpl,
5
+ IAccountStore,
6
+ MsgOpt,
7
+ } from "@keplr-wallet/stores";
8
+ import {
9
+ GasConfig,
4
10
  useFeeConfig,
5
- useGasConfig,
6
11
  useMemoConfig,
7
12
  useRecipientConfig,
8
13
  } from "./index";
9
14
  import { useStakedAmountConfig } from "./staked-amount";
15
+ import { makeObservable, override } from "mobx";
16
+ import { useState } from "react";
17
+
18
+ export class RedelegateGasConfig extends GasConfig {
19
+ constructor(
20
+ chainGetter: ChainGetter,
21
+ protected readonly accountStore: IAccountStore<{
22
+ cosmos: {
23
+ readonly msgOpts: {
24
+ readonly redelegate: MsgOpt;
25
+ };
26
+ };
27
+ }>,
28
+ initialChainId: string
29
+ ) {
30
+ super(chainGetter, initialChainId);
31
+
32
+ makeObservable(this);
33
+ }
34
+
35
+ @override
36
+ get gas(): number {
37
+ // If gas not set manually, assume that the tx is for MsgTransfer.
38
+ if (this._gasRaw == null) {
39
+ return this.accountStore.getAccount(this.chainId).cosmos.msgOpts
40
+ .redelegate.gas;
41
+ }
42
+
43
+ return super.gas;
44
+ }
45
+ }
46
+
47
+ export const useRedelegateGasConfig = (
48
+ chainGetter: ChainGetter,
49
+ accountStore: IAccountStore<{
50
+ cosmos: {
51
+ readonly msgOpts: {
52
+ readonly redelegate: MsgOpt;
53
+ };
54
+ };
55
+ }>,
56
+ chainId: string
57
+ ) => {
58
+ const [gasConfig] = useState(
59
+ () => new RedelegateGasConfig(chainGetter, accountStore, chainId)
60
+ );
61
+ gasConfig.setChain(chainId);
62
+
63
+ return gasConfig;
64
+ };
10
65
 
11
66
  export const useRedelegateTxConfig = (
12
67
  chainGetter: ChainGetter,
68
+ queriesStore: IQueriesStore<{
69
+ cosmos: Pick<CosmosQueriesImpl, "queryDelegations">;
70
+ }>,
71
+ accountStore: IAccountStore<{
72
+ cosmos: {
73
+ readonly msgOpts: {
74
+ readonly redelegate: MsgOpt;
75
+ };
76
+ };
77
+ }>,
13
78
  chainId: string,
14
- gas: number,
15
79
  sender: string,
16
- queryBalances: ObservableQueryBalances,
17
- queryDelegations: ObservableQueryDelegations,
18
80
  srcValidatorAddress: string
19
81
  ) => {
20
82
  const amountConfig = useStakedAmountConfig(
21
83
  chainGetter,
84
+ queriesStore,
22
85
  chainId,
23
86
  sender,
24
- queryDelegations,
25
87
  srcValidatorAddress
26
88
  );
27
89
 
28
90
  const memoConfig = useMemoConfig(chainGetter, chainId);
29
- const gasConfig = useGasConfig(chainGetter, chainId, gas);
30
- gasConfig.setGas(gas);
91
+ const gasConfig = useRedelegateGasConfig(chainGetter, accountStore, chainId);
31
92
  const feeConfig = useFeeConfig(
32
93
  chainGetter,
94
+ queriesStore,
33
95
  chainId,
34
96
  sender,
35
- queryBalances,
36
97
  amountConfig,
37
98
  gasConfig,
38
99
  false