@ape.swap/bonds-sdk 1.0.600 → 1.0.602
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.
|
@@ -60,50 +60,57 @@ var BondModal = function (_a) {
|
|
|
60
60
|
var account = _a.account, isActive = _a.isActive, isOpen = _a.isOpen, accountChainId = _a.accountChainId, onClose = _a.onClose, bondAddress = _a.bondAddress;
|
|
61
61
|
if (!isOpen)
|
|
62
62
|
return null;
|
|
63
|
-
var _b = useWriteContract(), hash = _b.data, isPending = _b.isPending, writeContract = _b.writeContract;
|
|
63
|
+
var _b = useWriteContract(), hash = _b.data, isPending = _b.isPending, writeContract = _b.writeContract, writeContractAsync = _b.writeContractAsync;
|
|
64
64
|
var _c = useWaitForTransactionReceipt({
|
|
65
65
|
hash: hash,
|
|
66
66
|
}), isConfirming = _c.isLoading, isConfirmed = _c.isSuccess;
|
|
67
|
-
//const { account, isActive } = useWeb3React();
|
|
68
67
|
var _d = useState([]), bondData = _d[0], setBondData = _d[1];
|
|
69
68
|
//This is a temp solution, but we will force approval each time, and then once set we will set status here and allow
|
|
70
69
|
//user to buy
|
|
71
70
|
//Check with Fede if this needs to be temp, if we force approval everytime, isn't this fine?
|
|
72
71
|
var handleBuy = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
73
|
-
var billAddress, decimals, maxPrice, amount;
|
|
72
|
+
var billAddress, decimals, maxPrice, amount, tx, error_1;
|
|
74
73
|
return __generator(this, function (_a) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
74
|
+
switch (_a.label) {
|
|
75
|
+
case 0:
|
|
76
|
+
billAddress = bondData[0].billAddress;
|
|
77
|
+
decimals = 18;
|
|
78
|
+
_a.label = 1;
|
|
79
|
+
case 1:
|
|
80
|
+
_a.trys.push([1, 3, , 4]);
|
|
81
|
+
console.log('HANDLEBUY CLICKED');
|
|
82
|
+
maxPrice = new BigNumber(bondData[0].trueBillPrice).times(102).div(100);
|
|
83
|
+
amount = convertToTokenValue(inputValue, decimals);
|
|
84
|
+
console.log('BillAddress:', billAddress);
|
|
85
|
+
console.log('Amount:', amount);
|
|
86
|
+
console.log('MaxPrice:', maxPrice);
|
|
87
|
+
return [4 /*yield*/, writeContractAsync({
|
|
88
|
+
address: billAddress,
|
|
89
|
+
abi: BOND_ABI,
|
|
90
|
+
functionName: 'deposit',
|
|
91
|
+
args: [amount, maxPrice.toFixed(0), account],
|
|
92
|
+
})];
|
|
93
|
+
case 2:
|
|
94
|
+
tx = _a.sent();
|
|
95
|
+
console.log('BuyTransaction:', hash);
|
|
96
|
+
if (tx) {
|
|
97
|
+
setBuyTx(tx);
|
|
98
|
+
console.log('setBuyTx:', hash);
|
|
99
|
+
}
|
|
100
|
+
return [3 /*break*/, 4];
|
|
101
|
+
case 3:
|
|
102
|
+
error_1 = _a.sent();
|
|
103
|
+
console.error('Buy error', error_1);
|
|
104
|
+
alert('Buy Failed');
|
|
105
|
+
return [3 /*break*/, 4];
|
|
106
|
+
case 4: return [2 /*return*/];
|
|
99
107
|
}
|
|
100
|
-
return [2 /*return*/];
|
|
101
108
|
});
|
|
102
109
|
}); };
|
|
103
110
|
var _e = useState(null), buyTx = _e[0], setBuyTx = _e[1];
|
|
104
111
|
//You approve the token, not the contract (this code will have to be updated for zap)
|
|
105
112
|
var handleApprove = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
106
|
-
var tokenAddress, decimals, amount,
|
|
113
|
+
var tokenAddress, decimals, amount, tx, error_2;
|
|
107
114
|
return __generator(this, function (_a) {
|
|
108
115
|
switch (_a.label) {
|
|
109
116
|
case 0:
|
|
@@ -113,25 +120,24 @@ var BondModal = function (_a) {
|
|
|
113
120
|
case 1:
|
|
114
121
|
_a.trys.push([1, 3, , 4]);
|
|
115
122
|
amount = convertToTokenValue(inputValue, decimals);
|
|
116
|
-
|
|
123
|
+
console.log('Amount:', amount);
|
|
124
|
+
return [4 /*yield*/, writeContractAsync({
|
|
117
125
|
address: tokenAddress,
|
|
118
126
|
abi: ERC_20_ABI,
|
|
119
127
|
functionName: 'approve',
|
|
120
128
|
args: [account, amount]
|
|
121
129
|
})];
|
|
122
130
|
case 2:
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
setApproveTx(hash_1);
|
|
129
|
-
console.log('setApproveTx:', hash_1);
|
|
131
|
+
tx = _a.sent();
|
|
132
|
+
console.log('ApproveTransaction:', tx);
|
|
133
|
+
if (tx) {
|
|
134
|
+
setApproveTx(tx);
|
|
135
|
+
console.log('setApproveTx:', tx);
|
|
130
136
|
}
|
|
131
137
|
return [3 /*break*/, 4];
|
|
132
138
|
case 3:
|
|
133
|
-
|
|
134
|
-
console.error('Approval failed:',
|
|
139
|
+
error_2 = _a.sent();
|
|
140
|
+
console.error('Approval failed:', error_2);
|
|
135
141
|
alert('Approval Failed');
|
|
136
142
|
return [3 /*break*/, 4];
|
|
137
143
|
case 4: return [2 /*return*/];
|
|
@@ -176,36 +182,46 @@ var BondModal = function (_a) {
|
|
|
176
182
|
setInputValue(event.target.value);
|
|
177
183
|
};
|
|
178
184
|
var _h = useState(null), tokenBalance = _h[0], setTokenBalance = _h[1];
|
|
185
|
+
var _j = useState(null), tokenDecimals = _j[0], setTokenDecimals = _j[1];
|
|
179
186
|
useEffect(function () {
|
|
180
187
|
if (isActive && account && bondData.length > 0) {
|
|
181
|
-
getTokenBalance(bondData[0].chainId, bondData[0].principalToken, account).then(function (
|
|
182
|
-
|
|
188
|
+
getTokenBalance(bondData[0].chainId, bondData[0].principalToken, account).then(function (_a) {
|
|
189
|
+
var balanceInEther = _a.balanceInEther, decimals = _a.decimals;
|
|
190
|
+
setTokenBalance(balanceInEther);
|
|
191
|
+
setTokenDecimals(decimals);
|
|
192
|
+
}).catch(function (error) {
|
|
193
|
+
console.error('Error fetching token balance', error);
|
|
183
194
|
});
|
|
184
195
|
}
|
|
185
196
|
}, [isActive, account, bondData]);
|
|
186
197
|
var getTokenBalance = function (chainId, tokenAddress, walletAddress) { return __awaiter(void 0, void 0, void 0, function () {
|
|
187
|
-
var urls, provider, contract, balance, balanceInEther,
|
|
198
|
+
var urls, provider, contract, decimals, balance, balanceInEther, error_3;
|
|
188
199
|
return __generator(this, function (_a) {
|
|
189
200
|
switch (_a.label) {
|
|
190
201
|
case 0:
|
|
191
|
-
_a.trys.push([0,
|
|
202
|
+
_a.trys.push([0, 3, , 4]);
|
|
192
203
|
urls = PUBLIC_RPC_URLS;
|
|
193
204
|
provider = new ethers.providers.JsonRpcProvider(urls[chainId][0]);
|
|
194
205
|
if (!provider) {
|
|
195
206
|
throw new Error("No provider found for chainId: ".concat(chainId));
|
|
196
207
|
}
|
|
197
208
|
contract = new ethers.Contract(tokenAddress, ERC_20_ABI, provider);
|
|
198
|
-
return [4 /*yield*/, contract.
|
|
209
|
+
return [4 /*yield*/, contract.decimals()];
|
|
199
210
|
case 1:
|
|
211
|
+
decimals = _a.sent();
|
|
212
|
+
console.log('Decimals:', decimals);
|
|
213
|
+
console.log(decimals);
|
|
214
|
+
return [4 /*yield*/, contract.balanceOf(walletAddress)];
|
|
215
|
+
case 2:
|
|
200
216
|
balance = _a.sent();
|
|
201
|
-
balanceInEther = ethers.utils.formatUnits(balance,
|
|
217
|
+
balanceInEther = ethers.utils.formatUnits(balance, decimals);
|
|
202
218
|
console.log("Token Balance: ".concat(balanceInEther));
|
|
203
|
-
return [2 /*return*/, balanceInEther];
|
|
204
|
-
case
|
|
205
|
-
|
|
206
|
-
console.error('Error fetching token balance',
|
|
207
|
-
return [2 /*return*/, '
|
|
208
|
-
case
|
|
219
|
+
return [2 /*return*/, { balanceInEther: balanceInEther, decimals: decimals }];
|
|
220
|
+
case 3:
|
|
221
|
+
error_3 = _a.sent();
|
|
222
|
+
console.error('Error fetching token balance', error_3);
|
|
223
|
+
return [2 /*return*/, { balanceInEther: '0', decimals: 0 }]; // Return a default object
|
|
224
|
+
case 4: return [2 /*return*/];
|
|
209
225
|
}
|
|
210
226
|
});
|
|
211
227
|
}); };
|