@keplr-wallet/hooks-evm 0.13.15-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.
Files changed (72) hide show
  1. package/.eslintrc.json +14 -0
  2. package/build/index.d.ts +1 -0
  3. package/build/index.js +18 -0
  4. package/build/index.js.map +1 -0
  5. package/build/tx/amount.d.ts +27 -0
  6. package/build/tx/amount.js +238 -0
  7. package/build/tx/amount.js.map +1 -0
  8. package/build/tx/chain.d.ts +10 -0
  9. package/build/tx/chain.js +37 -0
  10. package/build/tx/chain.js.map +1 -0
  11. package/build/tx/errors.d.ts +30 -0
  12. package/build/tx/errors.js +84 -0
  13. package/build/tx/errors.js.map +1 -0
  14. package/build/tx/evm-fee-utils.d.ts +28 -0
  15. package/build/tx/evm-fee-utils.js +133 -0
  16. package/build/tx/evm-fee-utils.js.map +1 -0
  17. package/build/tx/fee.d.ts +61 -0
  18. package/build/tx/fee.js +523 -0
  19. package/build/tx/fee.js.map +1 -0
  20. package/build/tx/gas-simulator.d.ts +89 -0
  21. package/build/tx/gas-simulator.js +465 -0
  22. package/build/tx/gas-simulator.js.map +1 -0
  23. package/build/tx/gas.d.ts +12 -0
  24. package/build/tx/gas.js +84 -0
  25. package/build/tx/gas.js.map +1 -0
  26. package/build/tx/index.d.ts +13 -0
  27. package/build/tx/index.js +30 -0
  28. package/build/tx/index.js.map +1 -0
  29. package/build/tx/internal.d.ts +3 -0
  30. package/build/tx/internal.js +3 -0
  31. package/build/tx/internal.js.map +1 -0
  32. package/build/tx/name-service-ens.d.ts +40 -0
  33. package/build/tx/name-service-ens.js +189 -0
  34. package/build/tx/name-service-ens.js.map +1 -0
  35. package/build/tx/name-service.d.ts +20 -0
  36. package/build/tx/name-service.js +20 -0
  37. package/build/tx/name-service.js.map +1 -0
  38. package/build/tx/recipient.d.ts +35 -0
  39. package/build/tx/recipient.js +131 -0
  40. package/build/tx/recipient.js.map +1 -0
  41. package/build/tx/send-tx.d.ts +13 -0
  42. package/build/tx/send-tx.js +24 -0
  43. package/build/tx/send-tx.js.map +1 -0
  44. package/build/tx/sender.d.ts +12 -0
  45. package/build/tx/sender.js +73 -0
  46. package/build/tx/sender.js.map +1 -0
  47. package/build/tx/types.d.ts +102 -0
  48. package/build/tx/types.js +3 -0
  49. package/build/tx/types.js.map +1 -0
  50. package/build/tx/validate.d.ts +11 -0
  51. package/build/tx/validate.js +37 -0
  52. package/build/tx/validate.js.map +1 -0
  53. package/package.json +40 -0
  54. package/src/index.ts +1 -0
  55. package/src/tx/amount.ts +273 -0
  56. package/src/tx/chain.ts +31 -0
  57. package/src/tx/errors.ts +79 -0
  58. package/src/tx/evm-fee-utils.ts +217 -0
  59. package/src/tx/fee.ts +622 -0
  60. package/src/tx/gas-simulator.ts +567 -0
  61. package/src/tx/gas.ts +93 -0
  62. package/src/tx/index.ts +13 -0
  63. package/src/tx/internal.ts +4 -0
  64. package/src/tx/name-service-ens.ts +207 -0
  65. package/src/tx/name-service.ts +39 -0
  66. package/src/tx/recipient.ts +166 -0
  67. package/src/tx/send-tx.ts +55 -0
  68. package/src/tx/sender.ts +82 -0
  69. package/src/tx/types.ts +153 -0
  70. package/src/tx/validate.ts +55 -0
  71. package/tsconfig.check.json +90 -0
  72. package/tsconfig.json +12 -0
@@ -0,0 +1,13 @@
1
+ export * from "./errors";
2
+ export * from "./types";
3
+ export * from "./evm-fee-utils";
4
+ export * from "./fee";
5
+ export * from "./gas";
6
+ export * from "./recipient";
7
+ export * from "./amount";
8
+ export * from "./sender";
9
+ export * from "./send-tx";
10
+ export * from "./chain";
11
+ export * from "./gas-simulator";
12
+ export * from "./validate";
13
+ export * from "./name-service";
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./errors"), exports);
18
+ __exportStar(require("./types"), exports);
19
+ __exportStar(require("./evm-fee-utils"), exports);
20
+ __exportStar(require("./fee"), exports);
21
+ __exportStar(require("./gas"), exports);
22
+ __exportStar(require("./recipient"), exports);
23
+ __exportStar(require("./amount"), exports);
24
+ __exportStar(require("./sender"), exports);
25
+ __exportStar(require("./send-tx"), exports);
26
+ __exportStar(require("./chain"), exports);
27
+ __exportStar(require("./gas-simulator"), exports);
28
+ __exportStar(require("./validate"), exports);
29
+ __exportStar(require("./name-service"), exports);
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tx/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,0CAAwB;AACxB,kDAAgC;AAChC,wCAAsB;AACtB,wCAAsB;AACtB,8CAA4B;AAC5B,2CAAyB;AACzB,2CAAyB;AACzB,4CAA0B;AAC1B,0CAAwB;AACxB,kDAAgC;AAChC,6CAA2B;AAC3B,iDAA+B"}
@@ -0,0 +1,3 @@
1
+ import { IQueriesStore } from "@keplr-wallet/stores";
2
+ import { EthereumQueries } from "@keplr-wallet/stores-eth";
3
+ export type QueriesStore = IQueriesStore<EthereumQueries>;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../src/tx/internal.ts"],"names":[],"mappings":""}
@@ -0,0 +1,40 @@
1
+ import { ChainGetter } from "@keplr-wallet/stores";
2
+ import { FetchDebounce, NameService } from "./name-service";
3
+ import { ITxChainSetter } from "./types";
4
+ export declare class ENSNameService implements NameService {
5
+ protected readonly base: ITxChainSetter;
6
+ protected readonly chainGetter: ChainGetter;
7
+ readonly type = "ens";
8
+ protected _isEnabled: boolean;
9
+ protected _isFetching: boolean;
10
+ protected _value: string;
11
+ protected _result: {
12
+ address: string;
13
+ fullName: string;
14
+ domain: string;
15
+ suffix: string;
16
+ } | undefined;
17
+ protected _ens: {
18
+ chainId: string;
19
+ } | undefined;
20
+ protected debounce: FetchDebounce;
21
+ constructor(base: ITxChainSetter, chainGetter: ChainGetter, ens?: {
22
+ chainId: string;
23
+ } | undefined);
24
+ setENS(ens: {
25
+ chainId: string;
26
+ }): void;
27
+ setIsEnabled(isEnabled: boolean): void;
28
+ get isEnabled(): boolean;
29
+ setValue(value: string): void;
30
+ get value(): string;
31
+ get result(): {
32
+ address: string;
33
+ fullName: string;
34
+ domain: string;
35
+ suffix: string;
36
+ } | undefined;
37
+ get isFetching(): boolean;
38
+ protected fetch(): Promise<void>;
39
+ protected fetchInternal(): Promise<void>;
40
+ }
@@ -0,0 +1,189 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ENSNameService = void 0;
19
+ const mobx_1 = require("mobx");
20
+ const name_service_1 = require("./name-service");
21
+ const providers_1 = require("@ethersproject/providers");
22
+ class ENSNameService {
23
+ constructor(base, chainGetter, ens = undefined) {
24
+ this.base = base;
25
+ this.chainGetter = chainGetter;
26
+ this.type = "ens";
27
+ this._isEnabled = true;
28
+ this._isFetching = false;
29
+ this._value = "";
30
+ this._result = undefined;
31
+ // Deep equal check is required to avoid infinite re-render.
32
+ this._ens = undefined;
33
+ this.debounce = new name_service_1.FetchDebounce();
34
+ this._ens = ens;
35
+ (0, mobx_1.makeObservable)(this);
36
+ (0, mobx_1.autorun)(() => {
37
+ noop(this.base.modularChainInfo, this._ens, this.isEnabled, this.value);
38
+ this.fetch();
39
+ });
40
+ }
41
+ setENS(ens) {
42
+ this._ens = ens;
43
+ }
44
+ setIsEnabled(isEnabled) {
45
+ this._isEnabled = isEnabled;
46
+ }
47
+ get isEnabled() {
48
+ if (!this._ens) {
49
+ return false;
50
+ }
51
+ const u = this.base.modularChainInfo.unwrapped;
52
+ if (u.type !== "evm" && u.type !== "ethermint") {
53
+ return false;
54
+ }
55
+ return this._isEnabled;
56
+ }
57
+ setValue(value) {
58
+ this._value = value;
59
+ }
60
+ get value() {
61
+ let v = this._value;
62
+ if (this.isEnabled) {
63
+ const suffix = "eth";
64
+ const i = v.lastIndexOf(".");
65
+ if (i >= 0) {
66
+ const tld = v.slice(i + 1);
67
+ if (suffix.startsWith(tld)) {
68
+ v = v.slice(0, i);
69
+ }
70
+ }
71
+ }
72
+ return v;
73
+ }
74
+ get result() {
75
+ if (!this.isEnabled) {
76
+ return undefined;
77
+ }
78
+ if (!this._result) {
79
+ return undefined;
80
+ }
81
+ if (this._result.domain !== this.value) {
82
+ return undefined;
83
+ }
84
+ return this._result;
85
+ }
86
+ get isFetching() {
87
+ return this._isFetching;
88
+ }
89
+ fetch() {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ if (!this.isEnabled ||
92
+ this.value.trim().length === 0 ||
93
+ !this._ens ||
94
+ this.value.length > 20) {
95
+ (0, mobx_1.runInAction)(() => {
96
+ this._result = undefined;
97
+ this._isFetching = false;
98
+ });
99
+ return;
100
+ }
101
+ this.debounce.run(() => this.fetchInternal());
102
+ });
103
+ }
104
+ fetchInternal() {
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ const prevValue = this.value;
107
+ try {
108
+ if (!this._ens) {
109
+ throw new Error("ENS is not set");
110
+ }
111
+ (0, mobx_1.runInAction)(() => {
112
+ this._isFetching = true;
113
+ });
114
+ if (!this.chainGetter.hasModularChain(this._ens.chainId)) {
115
+ throw new Error(`Can't find chain: ${this._ens.chainId}`);
116
+ }
117
+ const ensU = this.chainGetter.getModularChain(this._ens.chainId).unwrapped;
118
+ if (ensU.type !== "evm" && ensU.type !== "ethermint") {
119
+ throw new Error("ENS chain must be an EVM chain");
120
+ }
121
+ const suffix = "eth";
122
+ const domain = this.value;
123
+ const username = domain + "." + suffix;
124
+ const resolver = yield new providers_1.JsonRpcProvider(ensU.evm.rpc).getResolver(username);
125
+ if (!resolver) {
126
+ throw new Error("Can't find resolver");
127
+ }
128
+ const res = yield resolver.getAddress(60);
129
+ if (this.value === prevValue) {
130
+ if (res) {
131
+ (0, mobx_1.runInAction)(() => {
132
+ this._result = {
133
+ address: res,
134
+ fullName: username,
135
+ domain,
136
+ suffix,
137
+ };
138
+ this._isFetching = false;
139
+ });
140
+ }
141
+ else {
142
+ (0, mobx_1.runInAction)(() => {
143
+ this._result = undefined;
144
+ this._isFetching = false;
145
+ });
146
+ }
147
+ }
148
+ }
149
+ catch (e) {
150
+ console.log(e);
151
+ if (this.value === prevValue) {
152
+ (0, mobx_1.runInAction)(() => {
153
+ this._result = undefined;
154
+ this._isFetching = false;
155
+ });
156
+ }
157
+ }
158
+ });
159
+ }
160
+ }
161
+ __decorate([
162
+ mobx_1.observable
163
+ ], ENSNameService.prototype, "_isEnabled", void 0);
164
+ __decorate([
165
+ mobx_1.observable
166
+ ], ENSNameService.prototype, "_isFetching", void 0);
167
+ __decorate([
168
+ mobx_1.observable
169
+ ], ENSNameService.prototype, "_value", void 0);
170
+ __decorate([
171
+ mobx_1.observable.ref
172
+ ], ENSNameService.prototype, "_result", void 0);
173
+ __decorate([
174
+ mobx_1.observable.struct
175
+ ], ENSNameService.prototype, "_ens", void 0);
176
+ __decorate([
177
+ mobx_1.action
178
+ ], ENSNameService.prototype, "setENS", null);
179
+ __decorate([
180
+ mobx_1.action
181
+ ], ENSNameService.prototype, "setIsEnabled", null);
182
+ __decorate([
183
+ mobx_1.action
184
+ ], ENSNameService.prototype, "setValue", null);
185
+ exports.ENSNameService = ENSNameService;
186
+ const noop = (..._args) => {
187
+ // noop
188
+ };
189
+ //# sourceMappingURL=name-service-ens.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"name-service-ens.js","sourceRoot":"","sources":["../../src/tx/name-service-ens.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,+BAAgF;AAEhF,iDAA4D;AAC5D,wDAA2D;AAG3D,MAAa,cAAc;IAgCzB,YACqB,IAAoB,EACpB,WAAwB,EAC3C,MAIgB,SAAS;QANN,SAAI,GAAJ,IAAI,CAAgB;QACpB,gBAAW,GAAX,WAAW,CAAa;QAjCpC,SAAI,GAAG,KAAK,CAAC;QAGZ,eAAU,GAAY,IAAI,CAAC;QAG3B,gBAAW,GAAY,KAAK,CAAC;QAG7B,WAAM,GAAW,EAAE,CAAC;QAGpB,YAAO,GAOD,SAAS,CAAC;QAE1B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;gCAClB,MAAM;gCACN,MAAM;6BACP,CAAC;4BACF,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;wBAC3B,CAAC,CAAC,CAAC;qBACJ;yBAAM;wBACL,IAAA,kBAAW,EAAC,GAAG,EAAE;4BACf,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;4BACzB,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;wBAC3B,CAAC,CAAC,CAAC;qBACJ;iBACF;aACF;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;gBACf,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE;oBAC5B,IAAA,kBAAW,EAAC,GAAG,EAAE;wBACf,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;wBACzB,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;oBAC3B,CAAC,CAAC,CAAC;iBACJ;aACF;QACH,CAAC;KAAA;CACF;AAhMW;IADT,iBAAU;kDAC0B;AAG3B;IADT,iBAAU;mDAC4B;AAG7B;IADT,iBAAU;8CACmB;AAGpB;IADT,iBAAU,CAAC,GAAG;+CAQW;AAIhB;IADT,iBAAU,CAAC,MAAM;4CAKQ;AAwB1B;IADC,aAAM;4CAGN;AAGD;IADC,aAAM;kDAGN;AAgBD;IADC,aAAM;8CAGN;AA7EH,wCAoMC;AAED,MAAM,IAAI,GAAG,CAAC,GAAG,KAAY,EAAE,EAAE;IAC/B,OAAO;AACT,CAAC,CAAC"}
@@ -0,0 +1,20 @@
1
+ /// <reference types="node" />
2
+ export interface NameService {
3
+ type: string;
4
+ setIsEnabled: (isEnabled: boolean) => void;
5
+ isEnabled: boolean;
6
+ result: {
7
+ address: string;
8
+ fullName: string;
9
+ domain: string;
10
+ suffix: string;
11
+ } | undefined;
12
+ isFetching: boolean;
13
+ setValue: (value: string) => void;
14
+ value: string;
15
+ }
16
+ export declare class FetchDebounce {
17
+ readonly debounceMs = 50;
18
+ protected timeout: NodeJS.Timeout | undefined;
19
+ run(fn: () => Promise<void>): void;
20
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FetchDebounce = void 0;
4
+ class FetchDebounce {
5
+ constructor() {
6
+ this.debounceMs = 50;
7
+ this.timeout = undefined;
8
+ }
9
+ run(fn) {
10
+ if (this.timeout) {
11
+ clearTimeout(this.timeout);
12
+ }
13
+ this.timeout = setTimeout(() => {
14
+ this.timeout = undefined;
15
+ fn();
16
+ }, this.debounceMs);
17
+ }
18
+ }
19
+ exports.FetchDebounce = FetchDebounce;
20
+ //# sourceMappingURL=name-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"name-service.js","sourceRoot":"","sources":["../../src/tx/name-service.ts"],"names":[],"mappings":";;;AAwBA,MAAa,aAAa;IAA1B;QACW,eAAU,GAAG,EAAE,CAAC;QAEf,YAAO,GAA+B,SAAS,CAAC;IAW5D,CAAC;IATC,GAAG,CAAC,EAAuB;QACzB,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SAC5B;QACD,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YAC7B,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;YACzB,EAAE,EAAE,CAAC;QACP,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACtB,CAAC;CACF;AAdD,sCAcC"}
@@ -0,0 +1,35 @@
1
+ import { IRecipientConfig, UIProperties, IRecipientConfigWithNameServices } from "./types";
2
+ import { TxChainSetter } from "./chain";
3
+ import { ChainGetter } from "@keplr-wallet/stores";
4
+ import { NameService } from "./name-service";
5
+ export declare class RecipientConfig extends TxChainSetter implements IRecipientConfig, IRecipientConfigWithNameServices {
6
+ protected _value: string;
7
+ protected _preferredNameService: string | undefined;
8
+ protected nameServices: NameService[];
9
+ constructor(chainGetter: ChainGetter, initialChainId: string, ens?: {
10
+ chainId: string;
11
+ });
12
+ get preferredNameService(): string | undefined;
13
+ setPreferredNameService(nameService: string | undefined): void;
14
+ getNameService(type: string): NameService | undefined;
15
+ getNameServices(): NameService[];
16
+ get nameServiceResult(): {
17
+ type: string;
18
+ address: string;
19
+ fullName: string;
20
+ domain: string;
21
+ suffix: string;
22
+ }[];
23
+ setENS(ens: {
24
+ chainId: string;
25
+ }): void;
26
+ get recipient(): string;
27
+ get uiProperties(): UIProperties;
28
+ get value(): string;
29
+ setValue(value: string): void;
30
+ }
31
+ export declare const useRecipientConfig: (chainGetter: ChainGetter, chainId: string, options?: {
32
+ ens?: {
33
+ chainId: string;
34
+ } | undefined;
35
+ } | undefined) => RecipientConfig;
@@ -0,0 +1,131 @@
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.useRecipientConfig = exports.RecipientConfig = void 0;
10
+ const chain_1 = require("./chain");
11
+ const stores_eth_1 = require("@keplr-wallet/stores-eth");
12
+ const mobx_1 = require("mobx");
13
+ const errors_1 = require("./errors");
14
+ const react_1 = require("react");
15
+ const name_service_ens_1 = require("./name-service-ens");
16
+ class RecipientConfig extends chain_1.TxChainSetter {
17
+ constructor(chainGetter, initialChainId, ens) {
18
+ super(chainGetter, initialChainId);
19
+ this._value = "";
20
+ this._preferredNameService = undefined;
21
+ this.nameServices = [];
22
+ if (ens) {
23
+ this.nameServices.push(new name_service_ens_1.ENSNameService(this, chainGetter, ens));
24
+ }
25
+ (0, mobx_1.makeObservable)(this);
26
+ }
27
+ get preferredNameService() {
28
+ return this._preferredNameService;
29
+ }
30
+ setPreferredNameService(nameService) {
31
+ this._preferredNameService = nameService;
32
+ }
33
+ getNameService(type) {
34
+ return this.nameServices.find((nameService) => nameService.type === type);
35
+ }
36
+ getNameServices() {
37
+ return this.nameServices;
38
+ }
39
+ get nameServiceResult() {
40
+ const result = [];
41
+ for (const nameService of this.nameServices) {
42
+ if (this.preferredNameService &&
43
+ nameService.type !== this.preferredNameService) {
44
+ continue;
45
+ }
46
+ const r = nameService.result;
47
+ if (r) {
48
+ result.push(Object.assign(Object.assign({}, r), { type: nameService.type }));
49
+ }
50
+ }
51
+ return result;
52
+ }
53
+ setENS(ens) {
54
+ const found = this.nameServices.find((nameService) => nameService.type === "ens");
55
+ if (found) {
56
+ found.setENS(ens);
57
+ }
58
+ else {
59
+ this.nameServices.push(new name_service_ens_1.ENSNameService(this, this.chainGetter, ens));
60
+ }
61
+ }
62
+ get recipient() {
63
+ if (this.nameServiceResult.length > 0) {
64
+ const r = this.nameServiceResult[0];
65
+ return r.address;
66
+ }
67
+ return this.value.trim();
68
+ }
69
+ get uiProperties() {
70
+ let rawRecipient = this.value.trim();
71
+ if (!rawRecipient) {
72
+ return {
73
+ error: new errors_1.EmptyAddressError("Address is empty"),
74
+ };
75
+ }
76
+ if (this.nameServiceResult.length > 0) {
77
+ const r = this.nameServiceResult[0];
78
+ rawRecipient = r.address;
79
+ }
80
+ if (!stores_eth_1.EthereumAccountBase.isEthereumHexAddressWithChecksum(rawRecipient)) {
81
+ return {
82
+ error: new errors_1.InvalidHexError("Invalid hex address"),
83
+ };
84
+ }
85
+ return {};
86
+ }
87
+ get value() {
88
+ return this._value;
89
+ }
90
+ setValue(value) {
91
+ this._value = value;
92
+ for (const nameService of this.nameServices) {
93
+ nameService.setValue(value);
94
+ }
95
+ }
96
+ }
97
+ __decorate([
98
+ mobx_1.observable
99
+ ], RecipientConfig.prototype, "_value", void 0);
100
+ __decorate([
101
+ mobx_1.observable
102
+ ], RecipientConfig.prototype, "_preferredNameService", void 0);
103
+ __decorate([
104
+ mobx_1.observable.ref
105
+ ], RecipientConfig.prototype, "nameServices", void 0);
106
+ __decorate([
107
+ mobx_1.action
108
+ ], RecipientConfig.prototype, "setPreferredNameService", null);
109
+ __decorate([
110
+ mobx_1.computed
111
+ ], RecipientConfig.prototype, "nameServiceResult", null);
112
+ __decorate([
113
+ mobx_1.action
114
+ ], RecipientConfig.prototype, "setENS", null);
115
+ __decorate([
116
+ mobx_1.computed
117
+ ], RecipientConfig.prototype, "uiProperties", null);
118
+ __decorate([
119
+ mobx_1.action
120
+ ], RecipientConfig.prototype, "setValue", null);
121
+ exports.RecipientConfig = RecipientConfig;
122
+ const useRecipientConfig = (chainGetter, chainId, options) => {
123
+ const [config] = (0, react_1.useState)(() => new RecipientConfig(chainGetter, chainId, options === null || options === void 0 ? void 0 : options.ens));
124
+ config.setChain(chainId);
125
+ if (options === null || options === void 0 ? void 0 : options.ens) {
126
+ config.setENS(options.ens);
127
+ }
128
+ return config;
129
+ };
130
+ exports.useRecipientConfig = useRecipientConfig;
131
+ //# sourceMappingURL=recipient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recipient.js","sourceRoot":"","sources":["../../src/tx/recipient.ts"],"names":[],"mappings":";;;;;;;;;AAKA,mCAAwC;AAExC,yDAA+D;AAC/D,+BAAoE;AACpE,qCAA8D;AAC9D,iCAAiC;AAEjC,yDAAoD;AAEpD,MAAa,eACX,SAAQ,qBAAa;IAYrB,YACE,WAAwB,EACxB,cAAsB,EACtB,GAAyB;QAEzB,KAAK,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QAb3B,WAAM,GAAW,EAAE,CAAC;QAGpB,0BAAqB,GAAuB,SAAS,CAAC;QAGtD,iBAAY,GAAkB,EAAE,CAAC;QASzC,IAAI,GAAG,EAAE;YACP,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,iCAAc,CAAC,I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N;AAWD;IADC,eAAQ;wDAgCR;AAGD;IADC,aAAM;6CAUN;AAYD;IADC,eAAQ;mDAsBR;AAOD;IADC,aAAM;+CAON;AAtIH,0CAuIC;AAEM,MAAM,kBAAkB,GAAG,CAChC,WAAwB,EACxB,OAAe,EACf,OAAuC,EACvC,EAAE;IACF,MAAM,CAAC,MAAM,CAAC,GAAG,IAAA,gBAAQ,EACvB,GAAG,EAAE,CAAC,IAAI,eAAe,CAAC,WAAW,EAAE,OAAO,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,CAAC,CAC9D,CAAC;IACF,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACzB,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,EAAE;QAChB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;KAC5B;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAdW,QAAA,kBAAkB,sBAc7B"}
@@ -0,0 +1,13 @@
1
+ import { ChainGetter } from "@keplr-wallet/stores";
2
+ import { QueriesStore } from "./internal";
3
+ export declare const useSendTxConfig: (chainGetter: ChainGetter, queriesStore: QueriesStore, chainId: string, sender: string, initialGas: number, options?: {
4
+ ens?: {
5
+ chainId: string;
6
+ } | undefined;
7
+ } | undefined) => {
8
+ senderConfig: import("./sender").SenderConfig;
9
+ amountConfig: import("./amount").AmountConfig;
10
+ gasConfig: import("./gas").GasConfig;
11
+ feeConfig: import("./fee").FeeConfig;
12
+ recipientConfig: import("./recipient").RecipientConfig;
13
+ };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSendTxConfig = void 0;
4
+ const index_1 = require("./index");
5
+ const amount_1 = require("./amount");
6
+ const useSendTxConfig = (chainGetter, queriesStore, chainId, sender, initialGas, options) => {
7
+ const senderConfig = (0, index_1.useSenderConfig)(chainGetter, chainId, sender);
8
+ const amountConfig = (0, amount_1.useAmountConfig)(chainGetter, queriesStore, chainId, senderConfig);
9
+ const gasConfig = (0, index_1.useGasConfig)(chainGetter, chainId, initialGas);
10
+ const feeConfig = (0, index_1.useFeeConfig)(chainGetter, queriesStore, chainId, senderConfig, amountConfig, gasConfig);
11
+ amountConfig.setFeeConfig(feeConfig);
12
+ const recipientConfig = (0, index_1.useRecipientConfig)(chainGetter, chainId, {
13
+ ens: options === null || options === void 0 ? void 0 : options.ens,
14
+ });
15
+ return {
16
+ senderConfig,
17
+ amountConfig,
18
+ gasConfig,
19
+ feeConfig,
20
+ recipientConfig,
21
+ };
22
+ };
23
+ exports.useSendTxConfig = useSendTxConfig;
24
+ //# sourceMappingURL=send-tx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send-tx.js","sourceRoot":"","sources":["../../src/tx/send-tx.ts"],"names":[],"mappings":";;;AACA,mCAKiB;AACjB,qCAA2C;AAGpC,MAAM,eAAe,GAAG,CAC7B,WAAwB,EACxB,YAA0B,EAC1B,OAAe,EACf,MAAc,EACd,UAAkB,EAClB,OAIC,EACD,EAAE;IACF,MAAM,YAAY,GAAG,IAAA,uBAAe,EAAC,WAAW,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAEnE,MAAM,YAAY,GAAG,IAAA,wBAAe,EAClC,WAAW,EACX,YAAY,EACZ,OAAO,EACP,YAAY,CACb,CAAC;IAEF,MAAM,SAAS,GAAG,IAAA,oBAAY,EAAC,WAAW,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;IACjE,MAAM,SAAS,GAAG,IAAA,oBAAY,EAC5B,WAAW,EACX,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,SAAS,CACV,CAAC;IAEF,YAAY,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IAErC,MAAM,eAAe,GAAG,IAAA,0BAAkB,EAAC,WAAW,EAAE,OAAO,EAAE;QAC/D,GAAG,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG;KAClB,CAAC,CAAC;IAEH,OAAO;QACL,YAAY;QACZ,YAAY;QACZ,SAAS;QACT,SAAS;QACT,eAAe;KAChB,CAAC;AACJ,CAAC,CAAC;AA5CW,QAAA,eAAe,mBA4C1B"}
@@ -0,0 +1,12 @@
1
+ import { ISenderConfig, UIProperties } from "./types";
2
+ import { TxChainSetter } from "./chain";
3
+ import { ChainGetter } from "@keplr-wallet/stores";
4
+ export declare class SenderConfig extends TxChainSetter implements ISenderConfig {
5
+ protected _value: string;
6
+ constructor(chainGetter: ChainGetter, initialChainId: string, initialSender: string);
7
+ get sender(): string;
8
+ get value(): string;
9
+ setValue(value: string): void;
10
+ get uiProperties(): UIProperties;
11
+ }
12
+ export declare const useSenderConfig: (chainGetter: ChainGetter, chainId: string, sender: string) => SenderConfig;
@@ -0,0 +1,73 @@
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.useSenderConfig = exports.SenderConfig = void 0;
10
+ const chain_1 = require("./chain");
11
+ const mobx_1 = require("mobx");
12
+ const react_1 = require("react");
13
+ const errors_1 = require("./errors");
14
+ const buffer_1 = require("buffer");
15
+ class SenderConfig extends chain_1.TxChainSetter {
16
+ constructor(chainGetter, initialChainId, initialSender) {
17
+ super(chainGetter, initialChainId);
18
+ this._value = "";
19
+ this._value = initialSender;
20
+ (0, mobx_1.makeObservable)(this);
21
+ }
22
+ get sender() {
23
+ return this._value;
24
+ }
25
+ get value() {
26
+ return this._value;
27
+ }
28
+ setValue(value) {
29
+ this._value = value;
30
+ }
31
+ get uiProperties() {
32
+ if (!this.value) {
33
+ return {
34
+ error: new errors_1.EmptyAddressError("Address is empty"),
35
+ };
36
+ }
37
+ if (!this.value.startsWith("0x")) {
38
+ return {
39
+ error: new errors_1.InvalidHexError("Invalid hex address for chain"),
40
+ };
41
+ }
42
+ {
43
+ const hex = this.value.replace("0x", "");
44
+ const buf = buffer_1.Buffer.from(hex, "hex");
45
+ if (buf.length !== 20) {
46
+ return {
47
+ error: new errors_1.InvalidHexError("Invalid hex address for chain"),
48
+ };
49
+ }
50
+ if (hex.toLowerCase() !== buf.toString("hex").toLowerCase()) {
51
+ return {
52
+ error: new errors_1.InvalidHexError("Invalid hex address for chain"),
53
+ };
54
+ }
55
+ }
56
+ return {};
57
+ }
58
+ }
59
+ __decorate([
60
+ mobx_1.observable
61
+ ], SenderConfig.prototype, "_value", void 0);
62
+ __decorate([
63
+ mobx_1.action
64
+ ], SenderConfig.prototype, "setValue", null);
65
+ exports.SenderConfig = SenderConfig;
66
+ const useSenderConfig = (chainGetter, chainId, sender) => {
67
+ const [config] = (0, react_1.useState)(() => new SenderConfig(chainGetter, chainId, sender));
68
+ config.setChain(chainId);
69
+ config.setValue(sender);
70
+ return config;
71
+ };
72
+ exports.useSenderConfig = useSenderConfig;
73
+ //# sourceMappingURL=sender.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sender.js","sourceRoot":"","sources":["../../src/tx/sender.ts"],"names":[],"mappings":";;;;;;;;;AACA,mCAAwC;AACxC,+BAA0D;AAE1D,iCAAiC;AACjC,qCAA8D;AAC9D,mCAAgC;AAEhC,MAAa,YAAa,SAAQ,qBAAa;IAI7C,YACE,WAAwB,EACxB,cAAsB,EACtB,aAAqB;QAErB,KAAK,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QAP3B,WAAM,GAAW,EAAE,CAAC;QAS5B,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC;Q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