@ape.swap/bonds-sdk 1.0.562 → 1.0.564
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.
|
@@ -48,7 +48,7 @@ import { isNumber } from '../../../utils/numbers';
|
|
|
48
48
|
import { TooltipBubble, Button, Svg, ListTag } from '../../uikit-sdk';
|
|
49
49
|
import { TooltipText } from '../../../enum/tooltips';
|
|
50
50
|
import { ethers } from 'ethers';
|
|
51
|
-
import
|
|
51
|
+
import convertToTokenValue from "../../../utils/convertToTokenValue";
|
|
52
52
|
import TokenImage from '../../uikit-sdk/TokenImage';
|
|
53
53
|
import BOND_ABI from '../../../config/abi/bond.json';
|
|
54
54
|
import ERC_20_ABI from '../../../config/abi/erc20.json';
|
|
@@ -64,58 +64,56 @@ var BondModal = function (_a) {
|
|
|
64
64
|
var writeContract = useWriteContract().writeContract;
|
|
65
65
|
//const { account, isActive } = useWeb3React();
|
|
66
66
|
var _b = useState([]), bondData = _b[0], setBondData = _b[1];
|
|
67
|
-
var _c = useState(false), approvalStatus = _c[0], setApprovalStatus = _c[1];
|
|
68
67
|
//This is a temp solution, but we will force approval each time, and then once set we will set status here and allow
|
|
69
68
|
//user to buy
|
|
70
69
|
//Check with Fede if this needs to be temp, if we force approval everytime, isn't this fine?
|
|
71
70
|
var handleBuy = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
72
|
-
var
|
|
71
|
+
var billAddress, decimals, maxPrice, amount, tx, error_1;
|
|
73
72
|
return __generator(this, function (_a) {
|
|
74
73
|
switch (_a.label) {
|
|
75
74
|
case 0:
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
console.error('No Ethereum provider found');
|
|
79
|
-
alert('No Ethereum provider found');
|
|
80
|
-
return [2 /*return*/];
|
|
81
|
-
}
|
|
82
|
-
provider = new ethers.providers.Web3Provider(window.ethereum);
|
|
83
|
-
signer = provider.getSigner();
|
|
84
|
-
bondContract = new ethers.Contract(bondAddress !== null && bondAddress !== void 0 ? bondAddress : "", BOND_ABI, signer);
|
|
75
|
+
billAddress = bondData[0].billAddress;
|
|
76
|
+
decimals = 18;
|
|
85
77
|
_a.label = 1;
|
|
86
78
|
case 1:
|
|
87
|
-
_a.trys.push([1,
|
|
79
|
+
_a.trys.push([1, 3, , 4]);
|
|
88
80
|
maxPrice = new BigNumber(bondData[0].trueBillPrice).times(102).div(100);
|
|
89
|
-
amount =
|
|
90
|
-
return [4 /*yield*/,
|
|
81
|
+
amount = convertToTokenValue(inputValue, decimals);
|
|
82
|
+
return [4 /*yield*/, writeContract({
|
|
83
|
+
address: billAddress,
|
|
84
|
+
abi: BOND_ABI,
|
|
85
|
+
functionName: 'deposit',
|
|
86
|
+
args: [amount, maxPrice, account],
|
|
87
|
+
})];
|
|
91
88
|
case 2:
|
|
92
89
|
tx = _a.sent();
|
|
93
|
-
|
|
90
|
+
console.log('Transaction:', tx);
|
|
91
|
+
if (tx != null) {
|
|
92
|
+
setBuyTx(tx);
|
|
93
|
+
}
|
|
94
|
+
return [3 /*break*/, 4];
|
|
94
95
|
case 3:
|
|
95
|
-
_a.sent();
|
|
96
|
-
alert('Buy Successful');
|
|
97
|
-
return [3 /*break*/, 5];
|
|
98
|
-
case 4:
|
|
99
96
|
error_1 = _a.sent();
|
|
100
|
-
console.error('
|
|
101
|
-
alert('
|
|
102
|
-
return [3 /*break*/,
|
|
103
|
-
case
|
|
97
|
+
console.error('Buy error', error_1);
|
|
98
|
+
alert('Buy Failed');
|
|
99
|
+
return [3 /*break*/, 4];
|
|
100
|
+
case 4: return [2 /*return*/];
|
|
104
101
|
}
|
|
105
102
|
});
|
|
106
103
|
}); };
|
|
104
|
+
var _c = useState(null), buyTx = _c[0], setBuyTx = _c[1];
|
|
107
105
|
//You approve the token, not the contract (this code will have to be updated for zap)
|
|
108
106
|
var handleApprove = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
109
|
-
var tokenAddress, amount, tx, error_2;
|
|
107
|
+
var tokenAddress, decimals, amount, tx, error_2;
|
|
110
108
|
return __generator(this, function (_a) {
|
|
111
109
|
switch (_a.label) {
|
|
112
110
|
case 0:
|
|
113
111
|
tokenAddress = bondData[0].principalToken;
|
|
112
|
+
decimals = 18;
|
|
114
113
|
_a.label = 1;
|
|
115
114
|
case 1:
|
|
116
115
|
_a.trys.push([1, 3, , 4]);
|
|
117
|
-
|
|
118
|
-
amount = ethers.BigNumber.from(inputValue);
|
|
116
|
+
amount = convertToTokenValue(inputValue, decimals);
|
|
119
117
|
console.log('Amount:', amount);
|
|
120
118
|
return [4 /*yield*/, writeContract({
|
|
121
119
|
address: tokenAddress,
|
|
@@ -126,15 +124,20 @@ var BondModal = function (_a) {
|
|
|
126
124
|
case 2:
|
|
127
125
|
tx = _a.sent();
|
|
128
126
|
console.log('Transaction:', tx);
|
|
127
|
+
if (tx != null) {
|
|
128
|
+
setApproveTx(tx);
|
|
129
|
+
}
|
|
129
130
|
return [3 /*break*/, 4];
|
|
130
131
|
case 3:
|
|
131
132
|
error_2 = _a.sent();
|
|
132
133
|
console.error('Approval failed:', error_2);
|
|
134
|
+
alert('Approval Failed');
|
|
133
135
|
return [3 /*break*/, 4];
|
|
134
136
|
case 4: return [2 /*return*/];
|
|
135
137
|
}
|
|
136
138
|
});
|
|
137
139
|
}); };
|
|
140
|
+
var _d = useState(null), approveTx = _d[0], setApproveTx = _d[1];
|
|
138
141
|
// Fetch data
|
|
139
142
|
useEffect(function () {
|
|
140
143
|
axios.get('https://realtime-api.ape.bond/bonds').then(function (response) {
|
|
@@ -167,17 +170,17 @@ var BondModal = function (_a) {
|
|
|
167
170
|
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.payoutTokenDecimals) !== null && _d !== void 0 ? _d : 18));
|
|
168
171
|
return !available ? 0 : (singlePurchaseLimit.lt(safeAvailable) ? singlePurchaseLimit : safeAvailable);
|
|
169
172
|
};
|
|
170
|
-
var
|
|
173
|
+
var _e = useState(''), inputValue = _e[0], setInputValue = _e[1];
|
|
171
174
|
var handleInputChange = function (event) {
|
|
172
175
|
setInputValue(event.target.value);
|
|
173
176
|
};
|
|
174
|
-
var
|
|
177
|
+
var _f = useState(null), selectedBond = _f[0], setSelectedBond = _f[1];
|
|
175
178
|
var navigate = useNavigate();
|
|
176
179
|
var projectInfo = function (bond) {
|
|
177
180
|
setSelectedBond(bond);
|
|
178
181
|
navigate("/bondsingle/".concat(bond.billAddress));
|
|
179
182
|
};
|
|
180
|
-
var
|
|
183
|
+
var _g = useState(null), tokenBalance = _g[0], setTokenBalance = _g[1];
|
|
181
184
|
useEffect(function () {
|
|
182
185
|
if (isActive && account && bondData.length > 0) {
|
|
183
186
|
getTokenBalance(bondData[0].chainId, bondData[0].principalToken, account).then(function (balance) {
|
|
@@ -227,7 +230,7 @@ var BondModal = function (_a) {
|
|
|
227
230
|
!!v.currentTarget.value && isNumber(v.currentTarget.value) && parseFloat(v.currentTarget.value) >= 0
|
|
228
231
|
? v.currentTarget.value
|
|
229
232
|
: v.currentTarget.value.slice(0, v.currentTarget.value.length - 1);
|
|
230
|
-
} }) }), _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, { children: ["Get ", bond === null || bond === void 0 ? void 0 : bond.principalTokenName] }) }), _jsx(Flex, { className: "button-container buy", children:
|
|
233
|
+
} }) }), _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, { children: ["Get ", bond === null || bond === void 0 ? void 0 : bond.principalTokenName] }) }), _jsx(Flex, { className: "button-container buy", children: approveTx != null ?
|
|
231
234
|
_jsxs(Button, { onClick: handleBuy, children: ["Buy ", bond === null || bond === void 0 ? void 0 : bond.showcaseTokenName] })
|
|
232
235
|
:
|
|
233
236
|
_jsx(Button, { onClick: handleApprove, children: "Approve" }) })] })] })] }) }) }, bond.billAddress));
|