tek-wallet 0.0.513 → 0.0.514
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.
|
@@ -114,40 +114,41 @@ var SendExternalTokenError;
|
|
|
114
114
|
var getEstimateFeeDebounce = (0, createDebounce_1.default)(1000);
|
|
115
115
|
var transactionSlug = type_1.TransactionSlug.Withdrawn;
|
|
116
116
|
var SendExternalToken = (0, react_1.forwardRef)(function (props, ref) {
|
|
117
|
-
var _a;
|
|
117
|
+
var _a, _b, _c;
|
|
118
118
|
var theme = (0, material_1.useTheme)();
|
|
119
119
|
var withdrawTokens = (0, useWithdrawData_1.default)().withdrawTokens;
|
|
120
120
|
var confirmLayoutDrawerRef = (0, react_1.useRef)(null);
|
|
121
|
-
var
|
|
122
|
-
var
|
|
123
|
-
var
|
|
124
|
-
var
|
|
125
|
-
var
|
|
126
|
-
var
|
|
121
|
+
var _d = (0, react_1.useState)(undefined), token = _d[0], setToken = _d[1];
|
|
122
|
+
var _e = (0, react_1.useState)(undefined), error = _e[0], setError = _e[1];
|
|
123
|
+
var _f = (0, react_1.useState)(undefined), amountError = _f[0], setAmountError = _f[1];
|
|
124
|
+
var _g = (0, react_1.useState)(Button_1.BUTTON_STATUS.ENABLED), buttonStatus = _g[0], setButtonStatus = _g[1];
|
|
125
|
+
var _h = (0, react_1.useState)(), estimateFee = _h[0], setEstimateFee = _h[1];
|
|
126
|
+
var _j = (0, react_1.useState)(false), isLoadingEstimateFee = _j[0], setIsLoadingEstimateFee = _j[1];
|
|
127
127
|
var activitiesRef = (0, react_1.useRef)(null);
|
|
128
128
|
var amount = props.sendExternalData.amount;
|
|
129
129
|
var network = props.sendExternalData.network;
|
|
130
130
|
var memo = props.sendExternalData.memo;
|
|
131
131
|
var toAddress = props.sendExternalData.to_address;
|
|
132
132
|
var tokenSlug = props.sendExternalData.currency_slug;
|
|
133
|
-
var validateAmount = (0, react_1.useCallback)(function (
|
|
134
|
-
var
|
|
133
|
+
var validateAmount = (0, react_1.useCallback)(function () {
|
|
134
|
+
var amount = +props.sendExternalData.amount;
|
|
135
|
+
var token = withdrawTokens === null || withdrawTokens === void 0 ? void 0 : withdrawTokens.find(function (token) { var _a; return token.slug === ((_a = props.sendExternalData) === null || _a === void 0 ? void 0 : _a.currency_slug); });
|
|
135
136
|
setToken(token);
|
|
136
137
|
if (!token) {
|
|
137
138
|
setError(SendExternalTokenError.TOKEN_NOT_FOUND);
|
|
138
139
|
return;
|
|
139
140
|
}
|
|
140
|
-
if (
|
|
141
|
+
if (amount > token.max_value) {
|
|
141
142
|
setError(SendExternalTokenError.MAX_AMOUNT);
|
|
142
143
|
setAmountError(token.max_value);
|
|
143
144
|
return;
|
|
144
145
|
}
|
|
145
|
-
if (
|
|
146
|
+
if (amount < token.min_value) {
|
|
146
147
|
setError(SendExternalTokenError.MIN_AMOUNT);
|
|
147
148
|
setAmountError(token.min_value);
|
|
148
149
|
return;
|
|
149
150
|
}
|
|
150
|
-
if (
|
|
151
|
+
if (amount > +token.balance) {
|
|
151
152
|
setError(SendExternalTokenError.NOT_ENOUGH_BALANCE);
|
|
152
153
|
setAmountError(token.balance);
|
|
153
154
|
return;
|
|
@@ -155,7 +156,7 @@ var SendExternalToken = (0, react_1.forwardRef)(function (props, ref) {
|
|
|
155
156
|
setError(undefined);
|
|
156
157
|
setAmountError(undefined);
|
|
157
158
|
return true;
|
|
158
|
-
}, [withdrawTokens]);
|
|
159
|
+
}, [withdrawTokens, (_a = props.sendExternalData) === null || _a === void 0 ? void 0 : _a.currency_slug, (_b = props.sendExternalData) === null || _b === void 0 ? void 0 : _b.amount]);
|
|
159
160
|
var getEstimateFee = (0, react_1.useCallback)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
160
161
|
return __generator(this, function (_a) {
|
|
161
162
|
if (!tokenSlug) {
|
|
@@ -164,12 +165,12 @@ var SendExternalToken = (0, react_1.forwardRef)(function (props, ref) {
|
|
|
164
165
|
}
|
|
165
166
|
setIsLoadingEstimateFee(true);
|
|
166
167
|
getEstimateFeeDebounce(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
167
|
-
var isValidateAmount, response;
|
|
168
|
+
var isValidateAmount, response, fee;
|
|
168
169
|
var _a;
|
|
169
170
|
return __generator(this, function (_b) {
|
|
170
171
|
switch (_b.label) {
|
|
171
172
|
case 0:
|
|
172
|
-
isValidateAmount = validateAmount(
|
|
173
|
+
isValidateAmount = validateAmount();
|
|
173
174
|
if (!isValidateAmount) {
|
|
174
175
|
setIsLoadingEstimateFee(false);
|
|
175
176
|
return [2 /*return*/];
|
|
@@ -182,15 +183,16 @@ var SendExternalToken = (0, react_1.forwardRef)(function (props, ref) {
|
|
|
182
183
|
case 1:
|
|
183
184
|
response = _b.sent();
|
|
184
185
|
setIsLoadingEstimateFee(false);
|
|
185
|
-
|
|
186
|
-
|
|
186
|
+
fee = response === null || response === void 0 ? void 0 : response.data;
|
|
187
|
+
setEstimateFee(fee);
|
|
188
|
+
(_a = props.setEstimateFee) === null || _a === void 0 ? void 0 : _a.call(props, fee);
|
|
187
189
|
return [2 /*return*/];
|
|
188
190
|
}
|
|
189
191
|
});
|
|
190
192
|
}); });
|
|
191
193
|
return [2 /*return*/];
|
|
192
194
|
});
|
|
193
|
-
}); }, [
|
|
195
|
+
}); }, [validateAmount, tokenSlug, amount]);
|
|
194
196
|
var handleSendExternalToken = function (passcode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
195
197
|
var response, err_1;
|
|
196
198
|
var _a, _b;
|
|
@@ -249,7 +251,7 @@ var SendExternalToken = (0, react_1.forwardRef)(function (props, ref) {
|
|
|
249
251
|
}, [getEstimateFee]);
|
|
250
252
|
return ((0, jsx_runtime_1.jsx)(RequireConnect_1.default, { children: (0, jsx_runtime_1.jsxs)(ConfirmLayout_1.default, { ref: confirmLayoutDrawerRef, action: transactionSlug, trigger: props.children, children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.column), { gap: theme.mixins.gaps.g12 }), children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign({}, theme.mixins.paper), children: [(0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Recipient address", value: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
|
|
251
253
|
wordBreak: "break-all",
|
|
252
|
-
}, children: toAddress }) }), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Network", value: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g6, ml: "auto" }), children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { width: 20, src: network === null || network === void 0 ? void 0 : network.icon }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.value), children: network === null || network === void 0 ? void 0 : network.name })] }) }), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Amount", value: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: amount, unit: " ".concat(token === null || token === void 0 ? void 0 : token.name) }) }), !!memo && (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Memo", value: memo }), ((
|
|
254
|
+
}, children: toAddress }) }), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Network", value: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g6, ml: "auto" }), children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { width: 20, src: network === null || network === void 0 ? void 0 : network.icon }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.value), children: network === null || network === void 0 ? void 0 : network.name })] }) }), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Amount", value: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: amount, unit: " ".concat(token === null || token === void 0 ? void 0 : token.name) }) }), !!memo && (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Memo", value: memo }), ((_c = estimateFee === null || estimateFee === void 0 ? void 0 : estimateFee.feeDetail) === null || _c === void 0 ? void 0 : _c.length) && !!amount && ((0, jsx_runtime_1.jsx)(Fees_1.default, { feesData: JSON.stringify(estimateFee), amount: +amount })), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Receive amount estimated", value: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
|
|
253
255
|
fontWeight: theme.typography.fontWeight600,
|
|
254
256
|
fontSize: theme.typography.fontSize16,
|
|
255
257
|
}, children: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: estimateReceive, unit: " ".concat(token === null || token === void 0 ? void 0 : token.name) }) }) }), !!error && ((0, jsx_runtime_1.jsxs)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.validationError), { mt: theme.mixins.gaps.g6 }), children: [error, " ", !!amountError && (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: amountError, unit: " ".concat(token === null || token === void 0 ? void 0 : token.name) })] }))] }), (0, jsx_runtime_1.jsx)(ConfirmByPasscode_1.default, { action: transactionSlug, onConfirmSuccess: handleSendExternalToken, children: (0, jsx_runtime_1.jsx)(Button_1.default.Primary, { status: !!error || isLoadingEstimateFee ? Button_1.BUTTON_STATUS.DISABLED : buttonStatus, sx: { width: "100%" }, children: "Confirm" }) })] }), (0, jsx_runtime_1.jsx)(Activities_1.default, { ref: activitiesRef })] }) }));
|