@ape.swap/bonds-sdk 1.0.574 → 1.0.576
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.
|
@@ -43,7 +43,6 @@ import getTimePeriods from '../../../utils/getTimePeriods';
|
|
|
43
43
|
import axios from 'axios';
|
|
44
44
|
import { BigNumber } from 'bignumber.js';
|
|
45
45
|
import { getFirstNonZeroDigits } from '../../../utils/roundNumber';
|
|
46
|
-
import { useNavigate } from 'react-router-dom';
|
|
47
46
|
import { isNumber } from '../../../utils/numbers';
|
|
48
47
|
import { TooltipBubble, Button, Svg, ListTag } from '../../uikit-sdk';
|
|
49
48
|
import { TooltipText } from '../../../enum/tooltips';
|
|
@@ -76,8 +75,11 @@ var BondModal = function (_a) {
|
|
|
76
75
|
billAddress = bondData[0].billAddress;
|
|
77
76
|
decimals = 18;
|
|
78
77
|
try {
|
|
78
|
+
console.log('HANDLEBUY CLICKED');
|
|
79
79
|
maxPrice = new BigNumber(bondData[0].trueBillPrice).times(102).div(100);
|
|
80
80
|
amount = convertToTokenValue(inputValue, decimals);
|
|
81
|
+
console.log('Amount:', amount);
|
|
82
|
+
console.log('MaxPrice:', maxPrice);
|
|
81
83
|
// @ts-ignore
|
|
82
84
|
writeContract({
|
|
83
85
|
address: billAddress,
|
|
@@ -101,39 +103,30 @@ var BondModal = function (_a) {
|
|
|
101
103
|
var _e = useState(null), buyTx = _e[0], setBuyTx = _e[1];
|
|
102
104
|
//You approve the token, not the contract (this code will have to be updated for zap)
|
|
103
105
|
var handleApprove = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
104
|
-
var tokenAddress, decimals, amount
|
|
106
|
+
var tokenAddress, decimals, amount;
|
|
105
107
|
return __generator(this, function (_a) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
result = _a.sent();
|
|
123
|
-
console.log('Result:', result);
|
|
124
|
-
console.log('ApproveTransaction:', hash);
|
|
125
|
-
if (hash) {
|
|
126
|
-
setApproveTx(hash);
|
|
127
|
-
console.log('setApproveTx:', hash);
|
|
128
|
-
}
|
|
129
|
-
return [3 /*break*/, 4];
|
|
130
|
-
case 3:
|
|
131
|
-
error_1 = _a.sent();
|
|
132
|
-
console.error('Approval failed:', error_1);
|
|
133
|
-
alert('Approval Failed');
|
|
134
|
-
return [3 /*break*/, 4];
|
|
135
|
-
case 4: return [2 /*return*/];
|
|
108
|
+
tokenAddress = bondData[0].principalToken;
|
|
109
|
+
decimals = 18;
|
|
110
|
+
try {
|
|
111
|
+
amount = convertToTokenValue(inputValue, decimals);
|
|
112
|
+
console.log('Amount:', amount);
|
|
113
|
+
writeContract({
|
|
114
|
+
address: tokenAddress,
|
|
115
|
+
abi: ERC_20_ABI,
|
|
116
|
+
functionName: 'approve',
|
|
117
|
+
args: [account, amount]
|
|
118
|
+
});
|
|
119
|
+
console.log('ApproveTransaction:', hash);
|
|
120
|
+
if (hash) {
|
|
121
|
+
setApproveTx(hash);
|
|
122
|
+
console.log('setApproveTx:', hash);
|
|
123
|
+
}
|
|
136
124
|
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
console.error('Approval failed:', error);
|
|
127
|
+
alert('Approval Failed');
|
|
128
|
+
}
|
|
129
|
+
return [2 /*return*/];
|
|
137
130
|
});
|
|
138
131
|
}); };
|
|
139
132
|
var _f = useState(null), approveTx = _f[0], setApproveTx = _f[1];
|
|
@@ -173,13 +166,7 @@ var BondModal = function (_a) {
|
|
|
173
166
|
var handleInputChange = function (event) {
|
|
174
167
|
setInputValue(event.target.value);
|
|
175
168
|
};
|
|
176
|
-
var _h = useState(null),
|
|
177
|
-
var navigate = useNavigate();
|
|
178
|
-
var projectInfo = function (bond) {
|
|
179
|
-
setSelectedBond(bond);
|
|
180
|
-
navigate("/bondsingle/".concat(bond.billAddress));
|
|
181
|
-
};
|
|
182
|
-
var _j = useState(null), tokenBalance = _j[0], setTokenBalance = _j[1];
|
|
169
|
+
var _h = useState(null), tokenBalance = _h[0], setTokenBalance = _h[1];
|
|
183
170
|
useEffect(function () {
|
|
184
171
|
if (isActive && account && bondData.length > 0) {
|
|
185
172
|
getTokenBalance(bondData[0].chainId, bondData[0].principalToken, account).then(function (balance) {
|
|
@@ -188,7 +175,7 @@ var BondModal = function (_a) {
|
|
|
188
175
|
}
|
|
189
176
|
}, [isActive, account, bondData]);
|
|
190
177
|
var getTokenBalance = function (chainId, tokenAddress, walletAddress) { return __awaiter(void 0, void 0, void 0, function () {
|
|
191
|
-
var urls, provider, contract, balance, balanceInEther,
|
|
178
|
+
var urls, provider, contract, balance, balanceInEther, error_1;
|
|
192
179
|
return __generator(this, function (_a) {
|
|
193
180
|
switch (_a.label) {
|
|
194
181
|
case 0:
|
|
@@ -206,8 +193,8 @@ var BondModal = function (_a) {
|
|
|
206
193
|
console.log("Token Balance: ".concat(balanceInEther));
|
|
207
194
|
return [2 /*return*/, balanceInEther];
|
|
208
195
|
case 2:
|
|
209
|
-
|
|
210
|
-
console.error('Error fetching token balance',
|
|
196
|
+
error_1 = _a.sent();
|
|
197
|
+
console.error('Error fetching token balance', error_1);
|
|
211
198
|
return [2 /*return*/, 'Error fetching token balance'];
|
|
212
199
|
case 3: return [2 /*return*/];
|
|
213
200
|
}
|
|
@@ -230,7 +217,7 @@ var BondModal = function (_a) {
|
|
|
230
217
|
? v.currentTarget.value
|
|
231
218
|
: v.currentTarget.value.slice(0, v.currentTarget.value.length - 1);
|
|
232
219
|
} }) }), _jsxs(Flex, { className: "input-container token", children: [_jsx(Flex, { className: "input-container bondicon", children: _jsxs("div", { className: "icon-container-small", children: [_jsx(Svg, { width: 12, height: 12, icon: (_m = NETWORK_ICONS === null || NETWORK_ICONS === void 0 ? void 0 : NETWORK_ICONS[bond.chainId]) !== null && _m !== void 0 ? _m : 'question' }), _jsx(TokenImage, { symbol: (_o = bond.principalTokenName) !== null && _o !== void 0 ? _o : bond.payoutTokenName, size: 30 })] }) }), _jsx(Flex, { className: "title-container tokenname-small", children: bond === null || bond === void 0 ? void 0 : bond.principalTokenName })] })] }), isActive && account && (_jsxs(Flex, { className: "input-container balancerow", children: [_jsxs(Flex, { className: "balancerow text", children: ["Balance: ", tokenBalance] }), _jsx(Flex, { className: "balancerow max", children: _jsx(Button, { onClick: function () { setInputValue(tokenBalance !== null && tokenBalance !== void 0 ? tokenBalance : '0'); }, children: "Max" }) })] }))] }), _jsxs(Flex, { className: "modal-container button-container", children: [_jsx(Flex, { className: "button-container get", children: _jsxs(Button, { onClick: function () { window.open('https://ape.bond/swap', '_blank'); }, children: ["Get ", bond === null || bond === void 0 ? void 0 : bond.principalTokenName] }) }), _jsx(Flex, { className: "button-container buy", children: approveTx != null ?
|
|
233
|
-
_jsxs(Button, { onClick: handleBuy, children: ["Buy ", bond === null || bond === void 0 ? void 0 : bond.showcaseTokenName] })
|
|
220
|
+
_jsxs(Button, { disabled: isPending, onClick: handleBuy, children: ["Buy ", bond === null || bond === void 0 ? void 0 : bond.showcaseTokenName] })
|
|
234
221
|
:
|
|
235
222
|
_jsx(Button, { disabled: isPending, onClick: handleApprove, children: "Approve" }) })] })] })] }) }) }, bond.billAddress));
|
|
236
223
|
}) }));
|