@ape.swap/bonds-sdk 1.0.705 → 1.0.706
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.
|
@@ -54,17 +54,18 @@ import ERC_20_ABI from '../../../config/abi/erc20.json';
|
|
|
54
54
|
import { NETWORK_ICONS } from '../../../config/constants/chains';
|
|
55
55
|
import { formatUSDNumber, getPremiumColor, premium, youGet, youGetUSD, youSpend, youSpendUSD } from './helper';
|
|
56
56
|
import '../../../scss/BondModal.scss';
|
|
57
|
-
import { useWaitForTransactionReceipt, useWriteContract } from "wagmi";
|
|
57
|
+
import { useChainId, useWaitForTransactionReceipt, useWriteContract } from "wagmi";
|
|
58
58
|
import { PUBLIC_RPC_URLS } from "../../../config/constants/networks";
|
|
59
59
|
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 chainId = useChainId();
|
|
63
64
|
var _b = useState([]), bondData = _b[0], setBondData = _b[1];
|
|
64
65
|
var _c = useWriteContract(), hash = _c.data, isPending = _c.isPending, writeContract = _c.writeContract, writeContractAsync = _c.writeContractAsync;
|
|
65
66
|
var _d = useWaitForTransactionReceipt({
|
|
66
67
|
confirmations: 4,
|
|
67
|
-
chainId:
|
|
68
|
+
chainId: chainId !== null && chainId !== void 0 ? chainId : accountChainId,
|
|
68
69
|
hash: hash,
|
|
69
70
|
}), isConfirming = _d.isLoading, isConfirmed = _d.isSuccess;
|
|
70
71
|
var _e = useState(null), approveTx = _e[0], setApproveTx = _e[1];
|
|
@@ -153,9 +154,9 @@ var BondModal = function (_a) {
|
|
|
153
154
|
}, [approveTx, buyTx, isConfirmed]);
|
|
154
155
|
useEffect(function () {
|
|
155
156
|
if (isActive && account && bondData.length > 0) {
|
|
156
|
-
getTokenBalance(
|
|
157
|
-
var
|
|
158
|
-
setTokenBalance(
|
|
157
|
+
getTokenBalance(chainId, bondData[0].lpToken.address[chainId], account).then(function (_a) {
|
|
158
|
+
var balanceInEther = _a.balanceInEther, decimals = _a.decimals;
|
|
159
|
+
setTokenBalance(balanceInEther);
|
|
159
160
|
setTokenDecimals(decimals);
|
|
160
161
|
}).catch(function (error) {
|
|
161
162
|
console.error('Error fetching token balance', error);
|
|
@@ -163,7 +164,7 @@ var BondModal = function (_a) {
|
|
|
163
164
|
}
|
|
164
165
|
}, [isActive, account, bondData]);
|
|
165
166
|
var getTokenBalance = function (chainId, tokenAddress, walletAddress) { return __awaiter(void 0, void 0, void 0, function () {
|
|
166
|
-
var urls, provider, contract, decimals, balance, balanceInEther,
|
|
167
|
+
var urls, provider, contract, decimals, balance, balanceInEther, error_3;
|
|
167
168
|
return __generator(this, function (_a) {
|
|
168
169
|
switch (_a.label) {
|
|
169
170
|
case 0:
|
|
@@ -181,14 +182,14 @@ var BondModal = function (_a) {
|
|
|
181
182
|
case 2:
|
|
182
183
|
balance = _a.sent();
|
|
183
184
|
balanceInEther = ethers.utils.formatUnits(balance, decimals);
|
|
184
|
-
roundedBalanceInEther = Number(balanceInEther).toFixed(4);
|
|
185
185
|
console.log('balanceInEther', balanceInEther);
|
|
186
|
-
console.log('
|
|
187
|
-
|
|
186
|
+
console.log('decimals', decimals);
|
|
187
|
+
console.log('roundedBalance', Number(balanceInEther).toFixed(4).toString());
|
|
188
|
+
return [2 /*return*/, { balanceInEther: balanceInEther, decimals: decimals }];
|
|
188
189
|
case 3:
|
|
189
190
|
error_3 = _a.sent();
|
|
190
191
|
console.error('Error fetching token balance', error_3);
|
|
191
|
-
return [2 /*return*/, {
|
|
192
|
+
return [2 /*return*/, { balanceInEther: '0', decimals: 0 }];
|
|
192
193
|
case 4: return [2 /*return*/];
|
|
193
194
|
}
|
|
194
195
|
});
|
|
@@ -222,7 +223,7 @@ var BondModal = function (_a) {
|
|
|
222
223
|
var threshold = 5;
|
|
223
224
|
var thresholdToShow = new BigNumber(threshold).div((_b = bond === null || bond === void 0 ? void 0 : bond.payoutTokenPrice) !== null && _b !== void 0 ? _b : 0);
|
|
224
225
|
var safeAvailable = available.minus(thresholdToShow);
|
|
225
|
-
var singlePurchaseLimit = new BigNumber((_c = bond === null || bond === void 0 ? void 0 : bond.maxPayout) !== null && _c !== void 0 ? _c : 0).div(new BigNumber(10).pow((_d = bond === null || bond === void 0 ? void 0 : bond.earnToken.decimals[
|
|
226
|
+
var singlePurchaseLimit = new BigNumber((_c = bond === null || bond === void 0 ? void 0 : bond.maxPayout) !== null && _c !== void 0 ? _c : 0).div(new BigNumber(10).pow((_d = bond === null || bond === void 0 ? void 0 : bond.earnToken.decimals[chainId]) !== null && _d !== void 0 ? _d : 18));
|
|
226
227
|
return !available ? 0 : (singlePurchaseLimit.lt(safeAvailable) ? singlePurchaseLimit : safeAvailable);
|
|
227
228
|
};
|
|
228
229
|
return (_jsx(ThemeUIProvider, { theme: defaultTheme, children: bondData.map(function (bond) {
|
|
@@ -128,7 +128,7 @@ var Bonds = function (_a) {
|
|
|
128
128
|
};
|
|
129
129
|
var remainingPercentage = function (bond) {
|
|
130
130
|
var _a, _b;
|
|
131
|
-
var totalMaxPayout = new BigNumber((_a = bond.maxTotalPayout) !== null && _a !== void 0 ? _a : '0').div(new BigNumber(10).pow(bond.earnToken.decimals[
|
|
131
|
+
var totalMaxPayout = new BigNumber((_a = bond.maxTotalPayout) !== null && _a !== void 0 ? _a : '0').div(new BigNumber(10).pow(bond.earnToken.decimals[bond.chainId]));
|
|
132
132
|
var remainingTokens = new BigNumber((_b = bond.tokensRemaining) !== null && _b !== void 0 ? _b : '0');
|
|
133
133
|
return remainingTokens.div(totalMaxPayout).times(100).toNumber();
|
|
134
134
|
};
|
|
@@ -67,10 +67,11 @@ import BOND_ABI from '../../config/abi/bond.json';
|
|
|
67
67
|
import { useChainId, useWaitForTransactionReceipt, useWriteContract } from 'wagmi';
|
|
68
68
|
var YourBonds = function (_a) {
|
|
69
69
|
var account = _a.account, accountChainId = _a.accountChainId;
|
|
70
|
+
var chainId = useChainId();
|
|
70
71
|
var _b = useWriteContract(), hash = _b.data, isPending = _b.isPending, writeContract = _b.writeContract, writeContractAsync = _b.writeContractAsync;
|
|
71
72
|
var _c = useWaitForTransactionReceipt({
|
|
72
73
|
confirmations: 4,
|
|
73
|
-
chainId:
|
|
74
|
+
chainId: chainId,
|
|
74
75
|
hash: hash,
|
|
75
76
|
}), isConfirming = _c.isLoading, isConfirmed = _c.isSuccess;
|
|
76
77
|
var handleClaim = function (billId, billAddress) { return __awaiter(void 0, void 0, void 0, function () {
|
|
@@ -201,7 +202,6 @@ var YourBonds = function (_a) {
|
|
|
201
202
|
setSortedBonds(sorted);
|
|
202
203
|
}, [sortConfig, mappedUserBills]);
|
|
203
204
|
// Functions for calculations
|
|
204
|
-
var chainId = useChainId();
|
|
205
205
|
var currentTime = useCurrentTime() / 1000;
|
|
206
206
|
var vestingTimeRemaining = function (userBill) {
|
|
207
207
|
return getTimePeriods(parseInt(userBill.lastBlockTimestamp) + parseInt(userBill.vesting) - currentTime, true);
|