@ape.swap/bonds-sdk 1.0.97 → 1.0.98
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.
- package/dist/components/Bonds/Bonds.js +31 -31
- package/package.json +1 -1
|
@@ -48,30 +48,34 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
48
48
|
import { jsx as _jsx, jsxs as _jsxs } from "theme-ui/jsx-runtime";
|
|
49
49
|
/** @jsxImportSource theme-ui */
|
|
50
50
|
import { useEffect, useState } from 'react';
|
|
51
|
-
import { Flex, ThemeUIProvider } from
|
|
52
|
-
import axios from
|
|
51
|
+
import { Flex, ThemeUIProvider } from 'theme-ui';
|
|
52
|
+
import axios from 'axios';
|
|
53
53
|
import { ethers } from 'ethers';
|
|
54
|
-
import { useWeb3React } from
|
|
54
|
+
import { useWeb3React } from '@web3-react/core';
|
|
55
|
+
import { useSearchParams, useNavigate } from 'react-router-dom';
|
|
55
56
|
import styles, { getColumnDiscountStyle } from './styles';
|
|
56
57
|
import getTimePeriods from '../../utils/getTimePeriods';
|
|
57
58
|
import { defaultTheme } from '../../theme';
|
|
58
59
|
import Svg from '../uikit/Svg';
|
|
59
60
|
import '../../scss/bonds.scss';
|
|
61
|
+
import BondModal from '../BondModal/BondModal';
|
|
60
62
|
var Bonds = function (_a) {
|
|
61
63
|
var connectionString = _a.connectionString;
|
|
62
64
|
var _b = useWeb3React(), account = _b.account, isActive = _b.isActive;
|
|
65
|
+
var _c = useSearchParams(), searchParams = _c[0], setSearchParams = _c[1];
|
|
66
|
+
var navigate = useNavigate();
|
|
63
67
|
var USDT_ABI = [
|
|
64
68
|
// The ERC-20 approve function ABI
|
|
65
|
-
|
|
69
|
+
'function approve(address spender, uint256 amount) public returns (bool)',
|
|
66
70
|
];
|
|
67
|
-
var USDT_ADDRESS =
|
|
71
|
+
var USDT_ADDRESS = '0xdAC17F958D2ee523a2206206994597C13D831ec7'; // USDT contract address on Ethereum mainnet
|
|
68
72
|
var handleApprove = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
69
73
|
var provider, signer, usdtContract, tx, error_1;
|
|
70
74
|
return __generator(this, function (_a) {
|
|
71
75
|
switch (_a.label) {
|
|
72
76
|
case 0:
|
|
73
77
|
if (!window.ethereum) {
|
|
74
|
-
console.error(
|
|
78
|
+
console.error('No Ethereum provider found');
|
|
75
79
|
alert('No Ethereum provider found');
|
|
76
80
|
return [2 /*return*/];
|
|
77
81
|
}
|
|
@@ -82,8 +86,7 @@ var Bonds = function (_a) {
|
|
|
82
86
|
case 1:
|
|
83
87
|
_a.trys.push([1, 4, , 5]);
|
|
84
88
|
return [4 /*yield*/, usdtContract.approve(account, // Replace with the actual spender address
|
|
85
|
-
ethers.utils.parseUnits(
|
|
86
|
-
)];
|
|
89
|
+
ethers.utils.parseUnits('1000.0', 6))];
|
|
87
90
|
case 2:
|
|
88
91
|
tx = _a.sent();
|
|
89
92
|
return [4 /*yield*/, tx.wait()];
|
|
@@ -93,29 +96,29 @@ var Bonds = function (_a) {
|
|
|
93
96
|
return [3 /*break*/, 5];
|
|
94
97
|
case 4:
|
|
95
98
|
error_1 = _a.sent();
|
|
96
|
-
console.error(
|
|
99
|
+
console.error('Approval error', error_1);
|
|
97
100
|
alert('Approval Failed');
|
|
98
101
|
return [3 /*break*/, 5];
|
|
99
102
|
case 5: return [2 /*return*/];
|
|
100
103
|
}
|
|
101
104
|
});
|
|
102
105
|
}); };
|
|
103
|
-
var
|
|
104
|
-
var
|
|
106
|
+
var _d = useState([]), bondData = _d[0], setBondData = _d[1];
|
|
107
|
+
var _e = useState([]), hotBonds = _e[0], setHotBonds = _e[1];
|
|
105
108
|
var vestingTime = function (vestingTerm) {
|
|
106
109
|
return getTimePeriods(vestingTerm !== null && vestingTerm !== void 0 ? vestingTerm : 0, true);
|
|
107
110
|
};
|
|
108
111
|
useEffect(function () {
|
|
109
112
|
axios.get('https://realtime-api.ape.bond/bonds').then(function (response) {
|
|
110
|
-
var bonds = response.data.bonds.filter(function (x) {
|
|
111
|
-
return x.soldOut !== true && x.inactive !== true && x.discount < 25;
|
|
112
|
-
});
|
|
113
|
+
var bonds = response.data.bonds.filter(function (x) { return x.soldOut !== true && x.inactive !== true && x.discount < 25; });
|
|
113
114
|
setBondData(bonds);
|
|
114
115
|
});
|
|
115
116
|
}, []);
|
|
116
117
|
useEffect(function () {
|
|
117
118
|
axios.get('https://apeswap-strapi.herokuapp.com/hot-bonds').then(function (response) {
|
|
118
|
-
var hotBondAddresses = response.data.map(function (bond) {
|
|
119
|
+
var hotBondAddresses = response.data.map(function (bond) {
|
|
120
|
+
return bond.BondAddress.toLowerCase();
|
|
121
|
+
});
|
|
119
122
|
setHotBonds(hotBondAddresses);
|
|
120
123
|
});
|
|
121
124
|
}, []);
|
|
@@ -133,24 +136,21 @@ var Bonds = function (_a) {
|
|
|
133
136
|
return b.discount - a.discount;
|
|
134
137
|
}
|
|
135
138
|
});
|
|
136
|
-
var
|
|
137
|
-
|
|
138
|
-
window.location.href = url;
|
|
139
|
-
};
|
|
140
|
-
// Modal
|
|
141
|
-
var _e = useState(false), isModalOpen = _e[0], setIsModalOpen = _e[1];
|
|
142
|
-
var _f = useState(null), selectedBond = _f[0], setSelectedBond = _f[1];
|
|
139
|
+
var _f = useState(false), isModalOpen = _f[0], setIsModalOpen = _f[1];
|
|
140
|
+
var _g = useState(null), selectedBond = _g[0], setSelectedBond = _g[1];
|
|
143
141
|
var rowClick = function (bond) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
142
|
+
setSelectedBond(bond);
|
|
143
|
+
setIsModalOpen(true);
|
|
144
|
+
navigate("/?bondAddress=".concat(bond.billAddress, "&bondChain=").concat(bond.chainId), { replace: true });
|
|
145
|
+
};
|
|
146
|
+
var handleCloseModal = function () {
|
|
147
|
+
setIsModalOpen(false);
|
|
148
|
+
setSelectedBond(null);
|
|
149
|
+
navigate('/', { replace: true });
|
|
148
150
|
};
|
|
149
|
-
return (_jsxs(ThemeUIProvider, __assign({ theme: defaultTheme }, { children: [isActive && account &&
|
|
151
|
+
return (_jsxs(ThemeUIProvider, __assign({ theme: defaultTheme }, { children: [isActive && account && _jsx("p", { children: account }), isActive && account && _jsx("button", __assign({ onClick: handleApprove }, { children: "Approve USDT" })), _jsxs(Flex, __assign({ className: "container table-container" }, { children: [_jsxs(Flex, __assign({ className: "container header-container" }, { children: [_jsx(Flex, __assign({ className: "column column-header" }, { children: "Tokens" })), _jsx(Flex, __assign({ className: "column column-header" }, { children: "Discount" })), _jsx(Flex, __assign({ className: "column column-header" }, { children: "ARR" })), _jsx(Flex, __assign({ className: "column column-header" }, { children: "Terms" })), _jsx(Flex, __assign({ className: "column column-header" }, { children: "Tokens Remaining" })), _jsx(Flex, { className: "column column-header" })] })), sortedBonds.map(function (bond) {
|
|
150
152
|
var _a, _b, _c, _d;
|
|
151
|
-
return (
|
|
152
|
-
|
|
153
|
-
_jsxs(Flex, __assign({ className: "container bondrow-container", onClick: function () { return rowClick(bond); } }, { children: [_jsx(Flex, __assign({ className: "column column-token", sx: styles.columnToken }, { children: bond.showcaseTokenName })), _jsx(Flex, __assign({ className: "column column-discount", sx: getColumnDiscountStyle((_a = bond === null || bond === void 0 ? void 0 : bond.discount) !== null && _a !== void 0 ? _a : 0) }, { children: "".concat((_b = bond === null || bond === void 0 ? void 0 : bond.discount) === null || _b === void 0 ? void 0 : _b.toFixed(2), "%") })), _jsx(Flex, __assign({ className: "column column-arr", sx: styles.columnArr }, { children: "".concat("".concat(((((_c = bond === null || bond === void 0 ? void 0 : bond.discount) !== null && _c !== void 0 ? _c : 0) * 365) / vestingTime(bond.vestingTerm).days).toFixed(2), "%")) })), _jsx(Flex, __assign({ className: "column column-term", sx: styles.columnTerm }, { children: vestingTime(bond.vestingTerm).days ? "".concat(vestingTime(bond.vestingTerm).days, " D") : '-' })), _jsx(Flex, __assign({ className: "column column-tokensremaining", sx: styles.columnTokensRemaining }, { children: bond.tokensRemaining.split('.')[0] })), _jsx(Flex, __assign({ className: "column column-hotbond" }, { children: _jsx(Flex, __assign({ className: "column column-icon" }, { children: hotBonds.includes(bond.billAddress.toLowerCase()) && ((_d = bond.discount) !== null && _d !== void 0 ? _d : 0) > 0 && (_jsx(Svg, { icon: "fire", width: "20px" })) })) }))] })));
|
|
154
|
-
})] }))] })));
|
|
153
|
+
return (_jsxs(Flex, __assign({ className: "container bondrow-container", onClick: function () { return rowClick(bond); } }, { children: [_jsx(Flex, __assign({ className: "column column-token", sx: styles.columnToken }, { children: bond.showcaseTokenName })), _jsx(Flex, __assign({ className: "column column-discount", sx: getColumnDiscountStyle((_a = bond === null || bond === void 0 ? void 0 : bond.discount) !== null && _a !== void 0 ? _a : 0) }, { children: "".concat((_b = bond === null || bond === void 0 ? void 0 : bond.discount) === null || _b === void 0 ? void 0 : _b.toFixed(2), "%") })), _jsx(Flex, __assign({ className: "column column-arr", sx: styles.columnArr }, { children: "".concat(((((_c = bond === null || bond === void 0 ? void 0 : bond.discount) !== null && _c !== void 0 ? _c : 0) * 365) / vestingTime(bond.vestingTerm).days).toFixed(2), "%") })), _jsx(Flex, __assign({ className: "column column-term", sx: styles.columnTerm }, { children: vestingTime(bond.vestingTerm).days ? "".concat(vestingTime(bond.vestingTerm).days, " D") : '-' })), _jsx(Flex, __assign({ className: "column column-tokensremaining", sx: styles.columnTokensRemaining }, { children: bond.tokensRemaining.split('.')[0] })), _jsx(Flex, __assign({ className: "column column-hotbond" }, { children: _jsx(Flex, __assign({ className: "column column-icon" }, { children: hotBonds.includes(bond.billAddress.toLowerCase()) && ((_d = bond.discount) !== null && _d !== void 0 ? _d : 0) > 0 && (_jsx(Svg, { icon: "fire", width: "20px" })) })) }))] }), bond.billAddress));
|
|
154
|
+
})] })), selectedBond && (_jsx(BondModal, { isOpen: isModalOpen, onClose: handleCloseModal, bondAddress: selectedBond.billAddress }))] })));
|
|
155
155
|
};
|
|
156
156
|
export default Bonds;
|