@keplr-wallet/hooks 0.12.0-alpha.0 → 0.12.0-alpha.3
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/LICENSE +8 -2
- package/build/ibc/amount.d.ts +4 -5
- package/build/ibc/amount.js +8 -10
- package/build/ibc/amount.js.map +1 -1
- package/build/ibc/channel.js +2 -2
- package/build/ibc/channel.js.map +1 -1
- package/build/ibc/index.d.ts +0 -1
- package/build/ibc/index.js +5 -2
- package/build/ibc/index.js.map +1 -1
- package/build/ibc/reciepient.d.ts +8 -2
- package/build/ibc/reciepient.js +5 -4
- package/build/ibc/reciepient.js.map +1 -1
- package/build/ibc/send-ibc-transfer.d.ts +12 -11
- package/build/ibc/send-ibc-transfer.js +11 -12
- package/build/ibc/send-ibc-transfer.js.map +1 -1
- package/build/index.d.ts +0 -3
- package/build/index.js +5 -4
- package/build/index.js.map +1 -1
- package/build/sign-doc/amount.d.ts +13 -36
- package/build/sign-doc/amount.js +59 -122
- package/build/sign-doc/amount.js.map +1 -1
- package/build/sign-doc/helper.d.ts +12 -0
- package/build/sign-doc/helper.js +111 -0
- package/build/sign-doc/helper.js.map +1 -0
- package/build/sign-doc/index.d.ts +1 -12
- package/build/sign-doc/index.js +6 -91
- package/build/sign-doc/index.js.map +1 -1
- package/build/tx/amount.d.ts +21 -24
- package/build/tx/amount.js +126 -127
- package/build/tx/amount.js.map +1 -1
- package/build/tx/chain.d.ts +2 -7
- package/build/tx/chain.js +1 -1
- package/build/tx/chain.js.map +1 -1
- package/build/tx/errors.d.ts +5 -5
- package/build/tx/errors.js +15 -15
- package/build/tx/errors.js.map +1 -1
- package/build/tx/fee.d.ts +32 -28
- package/build/tx/fee.js +288 -208
- package/build/tx/fee.js.map +1 -1
- package/build/tx/gas-simulator.d.ts +16 -8
- package/build/tx/gas-simulator.js +128 -48
- package/build/tx/gas-simulator.js.map +1 -1
- package/build/tx/gas.d.ts +7 -7
- package/build/tx/gas.js +45 -49
- package/build/tx/gas.js.map +1 -1
- package/build/tx/index.d.ts +2 -4
- package/build/tx/index.js +7 -5
- package/build/tx/index.js.map +1 -1
- package/build/tx/internal.d.ts +4 -1
- package/build/tx/memo.d.ts +5 -4
- package/build/tx/memo.js +2088 -10
- package/build/tx/memo.js.map +1 -1
- package/build/tx/recipient.d.ts +35 -12
- package/build/tx/recipient.js +179 -74
- package/build/tx/recipient.js.map +1 -1
- package/build/tx/send-tx.d.ts +10 -3
- package/build/tx/send-tx.js +8 -9
- package/build/tx/send-tx.js.map +1 -1
- package/build/tx/send-types.d.ts +1 -1
- package/build/tx/sender.d.ts +12 -0
- package/build/tx/sender.js +47 -0
- package/build/tx/sender.js.map +1 -0
- package/build/tx/types.d.ts +52 -52
- package/build/tx/types.js.map +1 -1
- package/build/tx/validate.d.ts +12 -0
- package/build/tx/validate.js +33 -0
- package/build/tx/validate.js.map +1 -0
- package/package.json +18 -22
- package/src/ibc/amount.ts +8 -11
- package/src/ibc/index.ts +0 -1
- package/src/ibc/reciepient.ts +11 -4
- package/src/ibc/send-ibc-transfer.ts +24 -23
- package/src/index.ts +0 -3
- package/src/sign-doc/amount.ts +93 -167
- package/src/sign-doc/helper.ts +131 -0
- package/src/sign-doc/index.ts +1 -110
- package/src/tx/amount.ts +141 -133
- package/src/tx/chain.ts +2 -7
- package/src/tx/errors.ts +12 -12
- package/src/tx/fee.ts +378 -260
- package/src/tx/gas-simulator.ts +128 -41
- package/src/tx/gas.ts +42 -46
- package/src/tx/index.ts +2 -4
- package/src/tx/internal.ts +6 -0
- package/src/tx/memo.ts +2089 -8
- package/src/tx/recipient.ts +217 -89
- package/src/tx/send-tx.ts +26 -17
- package/src/tx/sender.ts +53 -0
- package/src/tx/types.ts +76 -54
- package/src/tx/validate.ts +52 -0
- package/build/address-book/index.d.ts +0 -40
- package/build/address-book/index.js +0 -141
- package/build/address-book/index.js.map +0 -1
- package/build/ibc/gas.d.ts +0 -26
- package/build/ibc/gas.js +0 -38
- package/build/ibc/gas.js.map +0 -1
- package/build/interaction/index.d.ts +0 -6
- package/build/interaction/index.js +0 -63
- package/build/interaction/index.js.map +0 -1
- package/build/register/index.d.ts +0 -49
- package/build/register/index.js +0 -201
- package/build/register/index.js.map +0 -1
- package/build/tx/delegate-tx.d.ts +0 -45
- package/build/tx/delegate-tx.js +0 -70
- package/build/tx/delegate-tx.js.map +0 -1
- package/build/tx/redelegate-tx.d.ts +0 -42
- package/build/tx/redelegate-tx.js +0 -57
- package/build/tx/redelegate-tx.js.map +0 -1
- package/build/tx/send-gas.d.ts +0 -12
- package/build/tx/send-gas.js +0 -81
- package/build/tx/send-gas.js.map +0 -1
- package/build/tx/staked-amount.d.ts +0 -30
- package/build/tx/staked-amount.js +0 -205
- package/build/tx/staked-amount.js.map +0 -1
- package/build/tx/undelegate-tx.d.ts +0 -40
- package/build/tx/undelegate-tx.js +0 -55
- package/build/tx/undelegate-tx.js.map +0 -1
- package/src/address-book/index.ts +0 -163
- package/src/ibc/gas.ts +0 -52
- package/src/interaction/index.ts +0 -61
- package/src/register/index.tsx +0 -230
- package/src/tx/delegate-tx.ts +0 -137
- package/src/tx/redelegate-tx.ts +0 -109
- package/src/tx/send-gas.ts +0 -92
- package/src/tx/staked-amount.ts +0 -231
- package/src/tx/undelegate-tx.ts +0 -107
package/build/sign-doc/amount.js
CHANGED
|
@@ -11,92 +11,58 @@ const tx_1 = require("../tx");
|
|
|
11
11
|
const mobx_1 = require("mobx");
|
|
12
12
|
const unit_1 = require("@keplr-wallet/unit");
|
|
13
13
|
const react_1 = require("react");
|
|
14
|
-
const mobx_utils_1 = require("mobx-utils");
|
|
15
14
|
const cosmos_1 = require("@keplr-wallet/cosmos");
|
|
16
15
|
// This config helps the fee config to calculate that the fee is enough to send with considering
|
|
17
16
|
// the amount in the sign doc.
|
|
18
17
|
// This sets the amount as the sum of the messages in the sign doc if the message is known and can be parsed.
|
|
19
18
|
class SignDocAmountConfig extends tx_1.TxChainSetter {
|
|
20
|
-
constructor(chainGetter,
|
|
19
|
+
constructor(chainGetter, initialChainId, senderConfig) {
|
|
21
20
|
super(chainGetter, initialChainId);
|
|
22
|
-
this.
|
|
21
|
+
this.senderConfig = senderConfig;
|
|
23
22
|
this.signDocHelper = undefined;
|
|
24
23
|
this._disableBalanceCheck = false;
|
|
25
|
-
|
|
26
|
-
var _a;
|
|
27
|
-
if (this.disableBalanceCheck ||
|
|
28
|
-
!((_a = this.signDocHelper) === null || _a === void 0 ? void 0 : _a.signDocWrapper) ||
|
|
29
|
-
this.chainInfo.feeCurrencies.length === 0) {
|
|
30
|
-
return {
|
|
31
|
-
amount: "0",
|
|
32
|
-
denom: this.sendCurrency.coinMinimalDenom,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
if (this.signDocHelper.signDocWrapper.mode === "amino") {
|
|
36
|
-
return this.computeAmountInAminoMsgs(this.signDocHelper.signDocWrapper.aminoSignDoc.msgs);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
return this.computeAmountInProtoMsgs(this.signDocHelper.signDocWrapper.protoSignDoc.txMsgs);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
this._sender = sender;
|
|
43
|
-
mobx_1.makeObservable(this);
|
|
24
|
+
(0, mobx_1.makeObservable)(this);
|
|
44
25
|
}
|
|
45
26
|
setSignDocHelper(signDocHelper) {
|
|
46
27
|
this.signDocHelper = signDocHelper;
|
|
47
28
|
}
|
|
48
29
|
get amount() {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
30
|
+
var _a;
|
|
31
|
+
if (this.disableBalanceCheck ||
|
|
32
|
+
!((_a = this.signDocHelper) === null || _a === void 0 ? void 0 : _a.signDocWrapper) ||
|
|
33
|
+
this.chainInfo.feeCurrencies.length === 0) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
if (this.signDocHelper.signDocWrapper.mode === "amino") {
|
|
37
|
+
return this.computeAmountInAminoMsgs(this.signDocHelper.signDocWrapper.aminoSignDoc.msgs);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return this.computeAmountInProtoMsgs(this.signDocHelper.signDocWrapper.protoSignDoc.txMsgs);
|
|
56
41
|
}
|
|
57
|
-
return chainInfo.currencies[0];
|
|
58
|
-
}
|
|
59
|
-
get sendableCurrencies() {
|
|
60
|
-
return [this.sendCurrency];
|
|
61
|
-
}
|
|
62
|
-
setSender(sender) {
|
|
63
|
-
this._sender = sender;
|
|
64
|
-
}
|
|
65
|
-
get sender() {
|
|
66
|
-
return this._sender;
|
|
67
42
|
}
|
|
68
43
|
computeAmountInAminoMsgs(msgs) {
|
|
69
|
-
const amount =
|
|
70
|
-
const account = this.accountStore.getAccount(this.chainId);
|
|
44
|
+
const amount = [];
|
|
71
45
|
for (const msg of msgs) {
|
|
72
46
|
try {
|
|
47
|
+
// TODO: msg.type이 다른 체인들이 몇개 있다. 이런 얘들에 대해서 좀 더 편리하게 처리해줄 방법을 찾아본다.
|
|
48
|
+
// 이 기능이 사용자의 자산을 잃게 만들리는 없기 때문에 나중에 처리해준다.
|
|
73
49
|
switch (msg.type) {
|
|
74
|
-
case
|
|
50
|
+
case "cosmos-sdk/MsgSend":
|
|
75
51
|
if (msg.value.from_address &&
|
|
76
|
-
msg.value.from_address
|
|
77
|
-
|
|
78
|
-
amount
|
|
79
|
-
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
if (msg.value.amount && Array.isArray(msg.value.amount)) {
|
|
83
|
-
for (const amountInMsg of msg.value.amount) {
|
|
84
|
-
if (amountInMsg.denom === amount.denom) {
|
|
85
|
-
amount.amount = amount.amount.add(new unit_1.Int(amountInMsg.amount));
|
|
52
|
+
msg.value.from_address === this.senderConfig.sender) {
|
|
53
|
+
if (msg.value.amount && Array.isArray(msg.value.amount)) {
|
|
54
|
+
for (const amountInMsg of msg.value.amount) {
|
|
55
|
+
amount.push(new unit_1.CoinPretty(this.chainInfo.forceFindCurrency(amountInMsg.denom), amountInMsg.amount));
|
|
86
56
|
}
|
|
87
57
|
}
|
|
88
58
|
}
|
|
89
59
|
break;
|
|
90
|
-
case
|
|
60
|
+
case "cosmos-sdk/MsgDelegate":
|
|
91
61
|
if (msg.value.delegator_address &&
|
|
92
|
-
msg.value.delegator_address
|
|
93
|
-
|
|
94
|
-
amount
|
|
95
|
-
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
if (msg.value.amount && msg.value.amount.denom === amount.denom) {
|
|
99
|
-
amount.amount = amount.amount.add(new unit_1.Int(msg.value.amount.amount));
|
|
62
|
+
msg.value.delegator_address === this.senderConfig.sender) {
|
|
63
|
+
if (msg.value.amount && msg.value.amount.denom) {
|
|
64
|
+
amount.push(new unit_1.CoinPretty(this.chainInfo.forceFindCurrency(msg.value.amount.denom), msg.value.amount));
|
|
65
|
+
}
|
|
100
66
|
}
|
|
101
67
|
break;
|
|
102
68
|
}
|
|
@@ -105,29 +71,20 @@ class SignDocAmountConfig extends tx_1.TxChainSetter {
|
|
|
105
71
|
console.log(`Error on the parsing the msg: ${e.message || e.toString()}`);
|
|
106
72
|
}
|
|
107
73
|
}
|
|
108
|
-
return
|
|
109
|
-
amount: amount.amount.toString(),
|
|
110
|
-
denom: amount.denom,
|
|
111
|
-
};
|
|
74
|
+
return this.mergeDuplicatedAmount(amount);
|
|
112
75
|
}
|
|
113
76
|
computeAmountInProtoMsgs(msgs) {
|
|
114
|
-
|
|
115
|
-
const amount = new unit_1.Coin(this.sendCurrency.coinMinimalDenom, new unit_1.Int(0));
|
|
77
|
+
const amount = [];
|
|
116
78
|
for (const msg of msgs) {
|
|
117
79
|
try {
|
|
118
80
|
if (!(msg instanceof cosmos_1.UnknownMessage) && "unpacked" in msg) {
|
|
119
81
|
switch (msg.typeUrl) {
|
|
120
82
|
case "/cosmos.bank.v1beta1.MsgSend": {
|
|
121
83
|
const sendMsg = msg.unpacked;
|
|
122
|
-
if (sendMsg.fromAddress &&
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
for (const amountInMsg of sendMsg.amount) {
|
|
129
|
-
if (amountInMsg.denom === amount.denom && amountInMsg.amount) {
|
|
130
|
-
amount.amount = amount.amount.add(new unit_1.Int(amountInMsg.amount));
|
|
84
|
+
if (sendMsg.fromAddress &&
|
|
85
|
+
sendMsg.fromAddress === this.senderConfig.sender) {
|
|
86
|
+
for (const amountInMsg of sendMsg.amount) {
|
|
87
|
+
amount.push(new unit_1.CoinPretty(this.chainInfo.forceFindCurrency(amountInMsg.denom), amountInMsg.amount));
|
|
131
88
|
}
|
|
132
89
|
}
|
|
133
90
|
break;
|
|
@@ -135,15 +92,10 @@ class SignDocAmountConfig extends tx_1.TxChainSetter {
|
|
|
135
92
|
case "/cosmos.staking.v1beta1.MsgDelegate": {
|
|
136
93
|
const delegateMsg = msg.unpacked;
|
|
137
94
|
if (delegateMsg.delegatorAddress &&
|
|
138
|
-
delegateMsg.delegatorAddress
|
|
139
|
-
|
|
140
|
-
amount
|
|
141
|
-
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
if (((_a = delegateMsg.amount) === null || _a === void 0 ? void 0 : _a.denom) === amount.denom &&
|
|
145
|
-
delegateMsg.amount.amount) {
|
|
146
|
-
amount.amount = amount.amount.add(new unit_1.Int(delegateMsg.amount.amount));
|
|
95
|
+
delegateMsg.delegatorAddress === this.senderConfig.sender) {
|
|
96
|
+
if (delegateMsg.amount) {
|
|
97
|
+
amount.push(new unit_1.CoinPretty(this.chainInfo.forceFindCurrency(delegateMsg.amount.denom), delegateMsg.amount.amount));
|
|
98
|
+
}
|
|
147
99
|
}
|
|
148
100
|
break;
|
|
149
101
|
}
|
|
@@ -154,36 +106,25 @@ class SignDocAmountConfig extends tx_1.TxChainSetter {
|
|
|
154
106
|
console.log(`Error on the parsing the msg: ${e.message || e.toString()}`);
|
|
155
107
|
}
|
|
156
108
|
}
|
|
157
|
-
return
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
return false;
|
|
174
|
-
}
|
|
175
|
-
get fraction() {
|
|
176
|
-
// noop
|
|
177
|
-
return undefined;
|
|
178
|
-
}
|
|
179
|
-
setFraction(_) {
|
|
180
|
-
// noop
|
|
181
|
-
}
|
|
182
|
-
setAmount() {
|
|
183
|
-
// noop
|
|
109
|
+
return this.mergeDuplicatedAmount(amount);
|
|
110
|
+
}
|
|
111
|
+
mergeDuplicatedAmount(amount) {
|
|
112
|
+
const mergedMap = new Map();
|
|
113
|
+
for (const amt of amount) {
|
|
114
|
+
let merged = mergedMap.get(amt.currency.coinMinimalDenom);
|
|
115
|
+
if (!merged) {
|
|
116
|
+
merged = amt;
|
|
117
|
+
mergedMap.set(amt.currency.coinMinimalDenom, merged);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
merged = merged.add(amt);
|
|
121
|
+
mergedMap.set(amt.currency.coinMinimalDenom, merged);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return Array.from(mergedMap.values());
|
|
184
125
|
}
|
|
185
|
-
|
|
186
|
-
|
|
126
|
+
get uiProperties() {
|
|
127
|
+
return {};
|
|
187
128
|
}
|
|
188
129
|
setDisableBalanceCheck(bool) {
|
|
189
130
|
this._disableBalanceCheck = bool;
|
|
@@ -195,9 +136,6 @@ class SignDocAmountConfig extends tx_1.TxChainSetter {
|
|
|
195
136
|
__decorate([
|
|
196
137
|
mobx_1.observable.ref
|
|
197
138
|
], SignDocAmountConfig.prototype, "signDocHelper", void 0);
|
|
198
|
-
__decorate([
|
|
199
|
-
mobx_1.observable
|
|
200
|
-
], SignDocAmountConfig.prototype, "_sender", void 0);
|
|
201
139
|
__decorate([
|
|
202
140
|
mobx_1.observable
|
|
203
141
|
], SignDocAmountConfig.prototype, "_disableBalanceCheck", void 0);
|
|
@@ -208,16 +146,15 @@ __decorate([
|
|
|
208
146
|
mobx_1.computed
|
|
209
147
|
], SignDocAmountConfig.prototype, "amount", null);
|
|
210
148
|
__decorate([
|
|
211
|
-
mobx_1.
|
|
212
|
-
], SignDocAmountConfig.prototype, "
|
|
149
|
+
mobx_1.computed
|
|
150
|
+
], SignDocAmountConfig.prototype, "uiProperties", null);
|
|
213
151
|
__decorate([
|
|
214
152
|
mobx_1.action
|
|
215
153
|
], SignDocAmountConfig.prototype, "setDisableBalanceCheck", null);
|
|
216
154
|
exports.SignDocAmountConfig = SignDocAmountConfig;
|
|
217
|
-
const useSignDocAmountConfig = (chainGetter,
|
|
218
|
-
const [config] = react_1.useState(() => new SignDocAmountConfig(chainGetter,
|
|
155
|
+
const useSignDocAmountConfig = (chainGetter, chainId, senderConfig) => {
|
|
156
|
+
const [config] = (0, react_1.useState)(() => new SignDocAmountConfig(chainGetter, chainId, senderConfig));
|
|
219
157
|
config.setChain(chainId);
|
|
220
|
-
config.setSender(sender);
|
|
221
158
|
return config;
|
|
222
159
|
};
|
|
223
160
|
exports.useSignDocAmountConfig = useSignDocAmountConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amount.js","sourceRoot":"","sources":["../../src/sign-doc/amount.ts"],"names":[],"mappings":";;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"amount.js","sourceRoot":"","sources":["../../src/sign-doc/amount.ts"],"names":[],"mappings":";;;;;;;;;AAAA,8BAKe;AAEf,+BAAoE;AACpE,6CAAgD;AAEhD,iCAAiC;AAEjC,iDAAuE;AAIvE,gGAAgG;AAChG,8BAA8B;AAC9B,6GAA6G;AAC7G,MAAa,mBACX,SAAQ,kBAAa;IASrB,YACE,WAAwB,EACxB,cAAsB,EACH,YAA2B;QAE9C,KAAK,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QAFhB,iBAA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
+
protected readonly feeConfig: IFeeConfig;
|
|
5
|
+
protected readonly memoConfig: IMemoConfig;
|
|
6
|
+
protected _signDocWrapper?: SignDocWrapper;
|
|
7
|
+
constructor(feeConfig: IFeeConfig, memoConfig: IMemoConfig);
|
|
8
|
+
get signDocWrapper(): SignDocWrapper | undefined;
|
|
9
|
+
get signDocJson(): any;
|
|
10
|
+
setSignDocWrapper(signDoc: SignDocWrapper | undefined): void;
|
|
11
|
+
}
|
|
12
|
+
export declare const useSignDocHelper: (feeConfig: IFeeConfig, memoConfig: IMemoConfig) => SignDocHelper;
|
|
@@ -0,0 +1,111 @@
|
|
|
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.useSignDocHelper = exports.SignDocHelper = void 0;
|
|
10
|
+
const mobx_1 = require("mobx");
|
|
11
|
+
const react_1 = require("react");
|
|
12
|
+
const cosmos_1 = require("@keplr-wallet/cosmos");
|
|
13
|
+
const tx_1 = require("@keplr-wallet/proto-types/cosmos/tx/v1beta1/tx");
|
|
14
|
+
const common_1 = require("@keplr-wallet/common");
|
|
15
|
+
class SignDocHelper {
|
|
16
|
+
constructor(feeConfig, memoConfig) {
|
|
17
|
+
this.feeConfig = feeConfig;
|
|
18
|
+
this.memoConfig = memoConfig;
|
|
19
|
+
this._signDocWrapper = undefined;
|
|
20
|
+
(0, mobx_1.makeObservable)(this);
|
|
21
|
+
}
|
|
22
|
+
get signDocWrapper() {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
if (!this._signDocWrapper) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
// If the sign doc is for ADR-36,
|
|
28
|
+
// The fee and memo should be empty.
|
|
29
|
+
// Ignore the fee and memo config, and just return itself.
|
|
30
|
+
if (this._signDocWrapper.isADR36SignDoc) {
|
|
31
|
+
return this._signDocWrapper;
|
|
32
|
+
}
|
|
33
|
+
const stdFee = this.feeConfig.toStdFee();
|
|
34
|
+
if (this._signDocWrapper.mode === "amino") {
|
|
35
|
+
const aminoSignDoc = this._signDocWrapper.aminoSignDoc;
|
|
36
|
+
const signDoc = Object.assign(Object.assign({}, aminoSignDoc), {
|
|
37
|
+
// XXX: Set fee payer/granter if the requested sign doc has fee payer/granter.
|
|
38
|
+
// Currently, there is no support for fee delegation within keplr,
|
|
39
|
+
// but this handling is essential for external services that set fee payer/granter.
|
|
40
|
+
fee: (() => {
|
|
41
|
+
const fee = Object.assign({}, stdFee);
|
|
42
|
+
if (aminoSignDoc.fee.feePayer) {
|
|
43
|
+
// XXX: This part is not standard. This is only used for ethermint EIP-712 signing.
|
|
44
|
+
fee.feePayer = aminoSignDoc.fee.feePayer;
|
|
45
|
+
}
|
|
46
|
+
if (aminoSignDoc.fee.granter) {
|
|
47
|
+
fee.granter = aminoSignDoc.fee.granter;
|
|
48
|
+
}
|
|
49
|
+
if (aminoSignDoc.fee.payer) {
|
|
50
|
+
fee.payer = aminoSignDoc.fee.payer;
|
|
51
|
+
}
|
|
52
|
+
return fee;
|
|
53
|
+
})(), memo: (0, common_1.escapeHTML)(this.memoConfig.memo) });
|
|
54
|
+
return cosmos_1.SignDocWrapper.fromAminoSignDoc(signDoc);
|
|
55
|
+
}
|
|
56
|
+
const protoSignDoc = this._signDocWrapper.protoSignDoc;
|
|
57
|
+
const fee = tx_1.Fee.fromPartial({
|
|
58
|
+
gasLimit: stdFee.gas,
|
|
59
|
+
amount: stdFee.amount.map((fee) => {
|
|
60
|
+
return {
|
|
61
|
+
amount: fee.amount,
|
|
62
|
+
denom: fee.denom,
|
|
63
|
+
};
|
|
64
|
+
}),
|
|
65
|
+
granter: (_a = protoSignDoc.authInfo.fee) === null || _a === void 0 ? void 0 : _a.granter,
|
|
66
|
+
payer: (_b = protoSignDoc.authInfo.fee) === null || _b === void 0 ? void 0 : _b.payer,
|
|
67
|
+
});
|
|
68
|
+
const newSignDoc = Object.assign(Object.assign({}, protoSignDoc.signDoc), {
|
|
69
|
+
bodyBytes: tx_1.TxBody.encode(Object.assign(Object.assign({}, protoSignDoc.txBody), {
|
|
70
|
+
memo: this.memoConfig.memo,
|
|
71
|
+
})).finish(),
|
|
72
|
+
authInfoBytes: tx_1.AuthInfo.encode(Object.assign(Object.assign({}, protoSignDoc.authInfo), {
|
|
73
|
+
fee,
|
|
74
|
+
})).finish(),
|
|
75
|
+
});
|
|
76
|
+
return cosmos_1.SignDocWrapper.fromDirectSignDoc(newSignDoc);
|
|
77
|
+
}
|
|
78
|
+
get signDocJson() {
|
|
79
|
+
if (!this.signDocWrapper) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
if (this.signDocWrapper.mode === "amino") {
|
|
83
|
+
return this.signDocWrapper.aminoSignDoc;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return this.signDocWrapper.protoSignDoc.toJSON();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
setSignDocWrapper(signDoc) {
|
|
90
|
+
this._signDocWrapper = signDoc;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
__decorate([
|
|
94
|
+
mobx_1.observable.ref
|
|
95
|
+
], SignDocHelper.prototype, "_signDocWrapper", void 0);
|
|
96
|
+
__decorate([
|
|
97
|
+
mobx_1.computed
|
|
98
|
+
], SignDocHelper.prototype, "signDocWrapper", null);
|
|
99
|
+
__decorate([
|
|
100
|
+
mobx_1.computed
|
|
101
|
+
], SignDocHelper.prototype, "signDocJson", null);
|
|
102
|
+
__decorate([
|
|
103
|
+
mobx_1.action
|
|
104
|
+
], SignDocHelper.prototype, "setSignDocWrapper", null);
|
|
105
|
+
exports.SignDocHelper = SignDocHelper;
|
|
106
|
+
const useSignDocHelper = (feeConfig, memoConfig) => {
|
|
107
|
+
const [helper] = (0, react_1.useState)(() => new SignDocHelper(feeConfig, memoConfig));
|
|
108
|
+
return helper;
|
|
109
|
+
};
|
|
110
|
+
exports.useSignDocHelper = useSignDocHelper;
|
|
111
|
+
//# sourceMappingURL=helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../src/sign-doc/helper.ts"],"names":[],"mappings":";;;;;;;;;AAAA,+BAAoE;AACpE,iCAAiC;AAEjC,iDAAsD;AACtD,uEAKwD;AACxD,iDAAkD;AAIlD,MAAa,aAAa;IAIxB,YACqB,SAAqB,EACrB,UAAuB;QADvB,cAAS,GAAT,SAAS,CAAY;QACrB,eAAU,GAAV,UAAU,CAAa;QAJlC,oBAAe,GAAoB,SAAS,CAAC;QAMrD,IAAA,qBAAc,EAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IAGD,IAAI,cAAc;;QAChB,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;YACzB,OAAO,SAAS,CAAC;SAClB;QAED,iCAAiC;QACjC,oCAAoC;QACpC,0DAA0D;QAC1D,IAAI,IAAI,CAAC,eAAe,CAAC,cAAc,EAAE;YACvC,OAAO,IAAI,CAAC,eAAe,CAAC;SAC7B;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;QAEzC,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,KAAK,OAAO,EAAE;YACzC,MAAM,YAAY,GAAG,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC;YAEvD,MAAM,OAAO,mCACR,YAAY;gBACf,8EAA8E;gBAC9E,uEAAuE;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cosmos";
|
|
3
1
|
export * from "./amount";
|
|
4
|
-
export
|
|
5
|
-
protected readonly feeConfig: IFeeConfig;
|
|
6
|
-
protected readonly memoConfig: IMemoConfig;
|
|
7
|
-
protected _signDocWrapper?: SignDocWrapper;
|
|
8
|
-
constructor(feeConfig: IFeeConfig, memoConfig: IMemoConfig);
|
|
9
|
-
get signDocWrapper(): SignDocWrapper | undefined;
|
|
10
|
-
get signDocJson(): any;
|
|
11
|
-
setSignDocWrapper(signDoc: SignDocWrapper | undefined): void;
|
|
12
|
-
}
|
|
13
|
-
export declare const useSignDocHelper: (feeConfig: IFeeConfig, memoConfig: IMemoConfig) => SignDocHelper;
|
|
2
|
+
export * from "./helper";
|
package/build/sign-doc/index.js
CHANGED
|
@@ -1,104 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
8
12
|
}));
|
|
9
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
10
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
11
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
12
|
-
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;
|
|
13
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
14
|
-
};
|
|
15
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
17
15
|
};
|
|
18
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.useSignDocHelper = exports.SignDocHelper = void 0;
|
|
20
|
-
const mobx_1 = require("mobx");
|
|
21
|
-
const react_1 = require("react");
|
|
22
|
-
const cosmos_1 = require("@keplr-wallet/cosmos");
|
|
23
|
-
const tx_1 = require("@keplr-wallet/proto-types/cosmos/tx/v1beta1/tx");
|
|
24
|
-
const common_1 = require("@keplr-wallet/common");
|
|
25
17
|
__exportStar(require("./amount"), exports);
|
|
26
|
-
|
|
27
|
-
constructor(feeConfig, memoConfig) {
|
|
28
|
-
this.feeConfig = feeConfig;
|
|
29
|
-
this.memoConfig = memoConfig;
|
|
30
|
-
this._signDocWrapper = undefined;
|
|
31
|
-
mobx_1.makeObservable(this);
|
|
32
|
-
}
|
|
33
|
-
get signDocWrapper() {
|
|
34
|
-
var _a, _b;
|
|
35
|
-
if (!this._signDocWrapper) {
|
|
36
|
-
return undefined;
|
|
37
|
-
}
|
|
38
|
-
// If the sign doc is for ADR-36,
|
|
39
|
-
// The fee and memo should be empty.
|
|
40
|
-
// Ignore the fee and memo config, and just return itself.
|
|
41
|
-
if (this._signDocWrapper.isADR36SignDoc) {
|
|
42
|
-
return this._signDocWrapper;
|
|
43
|
-
}
|
|
44
|
-
const stdFee = this.feeConfig.toStdFee();
|
|
45
|
-
if (this._signDocWrapper.mode === "amino") {
|
|
46
|
-
const signDoc = Object.assign(Object.assign({}, this._signDocWrapper.aminoSignDoc), { fee: stdFee, memo: common_1.escapeHTML(this.memoConfig.memo) });
|
|
47
|
-
return cosmos_1.SignDocWrapper.fromAminoSignDoc(signDoc);
|
|
48
|
-
}
|
|
49
|
-
const protoSignDoc = this._signDocWrapper.protoSignDoc;
|
|
50
|
-
const fee = tx_1.Fee.fromPartial({
|
|
51
|
-
gasLimit: stdFee.gas,
|
|
52
|
-
amount: stdFee.amount.map((fee) => {
|
|
53
|
-
return {
|
|
54
|
-
amount: fee.amount,
|
|
55
|
-
denom: fee.denom,
|
|
56
|
-
};
|
|
57
|
-
}),
|
|
58
|
-
granter: (_a = protoSignDoc.authInfo.fee) === null || _a === void 0 ? void 0 : _a.granter,
|
|
59
|
-
payer: (_b = protoSignDoc.authInfo.fee) === null || _b === void 0 ? void 0 : _b.payer,
|
|
60
|
-
});
|
|
61
|
-
const newSignDoc = Object.assign(Object.assign({}, protoSignDoc.signDoc), {
|
|
62
|
-
bodyBytes: tx_1.TxBody.encode(Object.assign(Object.assign({}, protoSignDoc.txBody), {
|
|
63
|
-
memo: this.memoConfig.memo,
|
|
64
|
-
})).finish(),
|
|
65
|
-
authInfoBytes: tx_1.AuthInfo.encode(Object.assign(Object.assign({}, protoSignDoc.authInfo), {
|
|
66
|
-
fee,
|
|
67
|
-
})).finish(),
|
|
68
|
-
});
|
|
69
|
-
return cosmos_1.SignDocWrapper.fromDirectSignDoc(newSignDoc);
|
|
70
|
-
}
|
|
71
|
-
get signDocJson() {
|
|
72
|
-
if (!this.signDocWrapper) {
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
if (this.signDocWrapper.mode === "amino") {
|
|
76
|
-
return this.signDocWrapper.aminoSignDoc;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
return this.signDocWrapper.protoSignDoc.toJSON();
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
setSignDocWrapper(signDoc) {
|
|
83
|
-
this._signDocWrapper = signDoc;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
__decorate([
|
|
87
|
-
mobx_1.observable.ref
|
|
88
|
-
], SignDocHelper.prototype, "_signDocWrapper", void 0);
|
|
89
|
-
__decorate([
|
|
90
|
-
mobx_1.computed
|
|
91
|
-
], SignDocHelper.prototype, "signDocWrapper", null);
|
|
92
|
-
__decorate([
|
|
93
|
-
mobx_1.computed
|
|
94
|
-
], SignDocHelper.prototype, "signDocJson", null);
|
|
95
|
-
__decorate([
|
|
96
|
-
mobx_1.action
|
|
97
|
-
], SignDocHelper.prototype, "setSignDocWrapper", null);
|
|
98
|
-
exports.SignDocHelper = SignDocHelper;
|
|
99
|
-
const useSignDocHelper = (feeConfig, memoConfig) => {
|
|
100
|
-
const [helper] = react_1.useState(() => new SignDocHelper(feeConfig, memoConfig));
|
|
101
|
-
return helper;
|
|
102
|
-
};
|
|
103
|
-
exports.useSignDocHelper = useSignDocHelper;
|
|
18
|
+
__exportStar(require("./helper"), exports);
|
|
104
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sign-doc/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sign-doc/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB"}
|
package/build/tx/amount.d.ts
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
|
-
import { IAmountConfig, IFeeConfig } from "./types";
|
|
1
|
+
import { IAmountConfig, IFeeConfig, ISenderConfig, UIProperties } from "./types";
|
|
2
2
|
import { TxChainSetter } from "./chain";
|
|
3
|
-
import { ChainGetter
|
|
3
|
+
import { ChainGetter } from "@keplr-wallet/stores";
|
|
4
4
|
import { AppCurrency } from "@keplr-wallet/types";
|
|
5
|
+
import { CoinPretty } from "@keplr-wallet/unit";
|
|
5
6
|
import { QueriesStore } from "./internal";
|
|
6
7
|
export declare class AmountConfig extends TxChainSetter implements IAmountConfig {
|
|
7
8
|
protected readonly queriesStore: QueriesStore;
|
|
8
|
-
protected
|
|
9
|
-
protected
|
|
10
|
-
protected
|
|
11
|
-
protected
|
|
12
|
-
protected
|
|
13
|
-
constructor(chainGetter: ChainGetter, queriesStore: QueriesStore, initialChainId: string,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
get
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
get
|
|
25
|
-
getAmountPrimitive(): CoinPrimitive;
|
|
26
|
-
get sendCurrency(): AppCurrency;
|
|
27
|
-
get sendableCurrencies(): AppCurrency[];
|
|
28
|
-
get error(): Error | undefined;
|
|
9
|
+
protected readonly senderConfig: ISenderConfig;
|
|
10
|
+
protected _currency?: AppCurrency;
|
|
11
|
+
protected _value: string;
|
|
12
|
+
protected _fraction: number;
|
|
13
|
+
protected _feeConfig: IFeeConfig | undefined;
|
|
14
|
+
constructor(chainGetter: ChainGetter, queriesStore: QueriesStore, initialChainId: string, senderConfig: ISenderConfig);
|
|
15
|
+
get feeConfig(): IFeeConfig | undefined;
|
|
16
|
+
setFeeConfig(feeConfig: IFeeConfig | undefined): void;
|
|
17
|
+
get value(): string;
|
|
18
|
+
setValue(value: string): void;
|
|
19
|
+
get amount(): CoinPretty[];
|
|
20
|
+
get currency(): AppCurrency;
|
|
21
|
+
setCurrency(currency: AppCurrency | undefined): void;
|
|
22
|
+
get fraction(): number;
|
|
23
|
+
setFraction(fraction: number): void;
|
|
24
|
+
get selectableCurrencies(): AppCurrency[];
|
|
25
|
+
get uiProperties(): UIProperties;
|
|
29
26
|
}
|
|
30
|
-
export declare const useAmountConfig: (chainGetter: ChainGetter, queriesStore: QueriesStore, chainId: string,
|
|
27
|
+
export declare const useAmountConfig: (chainGetter: ChainGetter, queriesStore: QueriesStore, chainId: string, senderConfig: ISenderConfig) => AmountConfig;
|