@ape.swap/bonds-sdk 1.0.568 → 1.0.570
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.
|
@@ -58,7 +58,7 @@ import '../../../scss/BondModal.scss';
|
|
|
58
58
|
import { useWaitForTransactionReceipt, useWriteContract } from "wagmi";
|
|
59
59
|
import { PUBLIC_RPC_URLS } from "../../../config/constants/networks";
|
|
60
60
|
var BondModal = function (_a) {
|
|
61
|
-
var account = _a.account,
|
|
61
|
+
var account = _a.account, isActive = _a.isActive, isOpen = _a.isOpen, onClose = _a.onClose, bondAddress = _a.bondAddress;
|
|
62
62
|
if (!isOpen)
|
|
63
63
|
return null;
|
|
64
64
|
var _b = useWriteContract(), hash = _b.data, isPending = _b.isPending, writeContract = _b.writeContract;
|
|
@@ -71,76 +71,60 @@ var BondModal = function (_a) {
|
|
|
71
71
|
//user to buy
|
|
72
72
|
//Check with Fede if this needs to be temp, if we force approval everytime, isn't this fine?
|
|
73
73
|
var handleBuy = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
74
|
-
var billAddress, decimals, maxPrice, amount
|
|
74
|
+
var billAddress, decimals, maxPrice, amount;
|
|
75
75
|
return __generator(this, function (_a) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
setBuyTx(hash);
|
|
98
|
-
}
|
|
99
|
-
return [3 /*break*/, 4];
|
|
100
|
-
case 3:
|
|
101
|
-
error_1 = _a.sent();
|
|
102
|
-
console.error('Buy error', error_1);
|
|
103
|
-
alert('Buy Failed');
|
|
104
|
-
return [3 /*break*/, 4];
|
|
105
|
-
case 4: return [2 /*return*/];
|
|
76
|
+
billAddress = bondData[0].billAddress;
|
|
77
|
+
decimals = 18;
|
|
78
|
+
try {
|
|
79
|
+
maxPrice = new BigNumber(bondData[0].trueBillPrice).times(102).div(100);
|
|
80
|
+
amount = convertToTokenValue(inputValue, decimals);
|
|
81
|
+
// @ts-ignore
|
|
82
|
+
writeContract({
|
|
83
|
+
address: billAddress,
|
|
84
|
+
abi: BOND_ABI,
|
|
85
|
+
functionName: 'deposit',
|
|
86
|
+
args: [amount, maxPrice, account],
|
|
87
|
+
});
|
|
88
|
+
console.log('BuyTransaction:', hash);
|
|
89
|
+
if (hash) {
|
|
90
|
+
setBuyTx(hash);
|
|
91
|
+
console.log('setBuyTx:', hash);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
console.error('Buy error', error);
|
|
96
|
+
alert('Buy Failed');
|
|
106
97
|
}
|
|
98
|
+
return [2 /*return*/];
|
|
107
99
|
});
|
|
108
100
|
}); };
|
|
109
101
|
var _e = useState(null), buyTx = _e[0], setBuyTx = _e[1];
|
|
110
102
|
//You approve the token, not the contract (this code will have to be updated for zap)
|
|
111
103
|
var handleApprove = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
112
|
-
var tokenAddress, decimals, amount
|
|
104
|
+
var tokenAddress, decimals, amount;
|
|
113
105
|
return __generator(this, function (_a) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
console.log('setApproveTx:', hash);
|
|
135
|
-
}
|
|
136
|
-
return [3 /*break*/, 4];
|
|
137
|
-
case 3:
|
|
138
|
-
error_2 = _a.sent();
|
|
139
|
-
console.error('Approval failed:', error_2);
|
|
140
|
-
alert('Approval Failed');
|
|
141
|
-
return [3 /*break*/, 4];
|
|
142
|
-
case 4: return [2 /*return*/];
|
|
106
|
+
tokenAddress = bondData[0].principalToken;
|
|
107
|
+
decimals = 18;
|
|
108
|
+
try {
|
|
109
|
+
amount = convertToTokenValue(inputValue, decimals);
|
|
110
|
+
console.log('Amount:', amount);
|
|
111
|
+
writeContract({
|
|
112
|
+
address: tokenAddress,
|
|
113
|
+
abi: ERC_20_ABI,
|
|
114
|
+
functionName: 'approve',
|
|
115
|
+
args: [account, amount]
|
|
116
|
+
});
|
|
117
|
+
console.log('ApproveTransaction:', hash);
|
|
118
|
+
if (hash) {
|
|
119
|
+
setApproveTx(hash);
|
|
120
|
+
console.log('setApproveTx:', hash);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
console.error('Approval failed:', error);
|
|
125
|
+
alert('Approval Failed');
|
|
143
126
|
}
|
|
127
|
+
return [2 /*return*/];
|
|
144
128
|
});
|
|
145
129
|
}); };
|
|
146
130
|
var _f = useState(null), approveTx = _f[0], setApproveTx = _f[1];
|
|
@@ -195,7 +179,7 @@ var BondModal = function (_a) {
|
|
|
195
179
|
}
|
|
196
180
|
}, [isActive, account, bondData]);
|
|
197
181
|
var getTokenBalance = function (chainId, tokenAddress, walletAddress) { return __awaiter(void 0, void 0, void 0, function () {
|
|
198
|
-
var urls, provider, contract, balance, balanceInEther,
|
|
182
|
+
var urls, provider, contract, balance, balanceInEther, error_1;
|
|
199
183
|
return __generator(this, function (_a) {
|
|
200
184
|
switch (_a.label) {
|
|
201
185
|
case 0:
|
|
@@ -213,8 +197,8 @@ var BondModal = function (_a) {
|
|
|
213
197
|
console.log("Token Balance: ".concat(balanceInEther));
|
|
214
198
|
return [2 /*return*/, balanceInEther];
|
|
215
199
|
case 2:
|
|
216
|
-
|
|
217
|
-
console.error('Error fetching token balance',
|
|
200
|
+
error_1 = _a.sent();
|
|
201
|
+
console.error('Error fetching token balance', error_1);
|
|
218
202
|
return [2 /*return*/, 'Error fetching token balance'];
|
|
219
203
|
case 3: return [2 /*return*/];
|
|
220
204
|
}
|