@ape.swap/bonds-sdk 1.0.575 → 1.0.577

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.
@@ -43,12 +43,11 @@ import getTimePeriods from '../../../utils/getTimePeriods';
43
43
  import axios from 'axios';
44
44
  import { BigNumber } from 'bignumber.js';
45
45
  import { getFirstNonZeroDigits } from '../../../utils/roundNumber';
46
- import { useNavigate } from 'react-router-dom';
47
46
  import { isNumber } from '../../../utils/numbers';
48
47
  import { TooltipBubble, Button, Svg, ListTag } from '../../uikit-sdk';
49
48
  import { TooltipText } from '../../../enum/tooltips';
50
49
  import { ethers } from 'ethers';
51
- import convertToTokenValue from "../../../utils/convertToTokenValue";
50
+ import convertToTokenValue, { adjustDecimals } from "../../../utils/convertToTokenValue";
52
51
  import TokenImage from '../../uikit-sdk/TokenImage';
53
52
  import BOND_ABI from '../../../config/abi/bond.json';
54
53
  import ERC_20_ABI from '../../../config/abi/erc20.json';
@@ -71,19 +70,25 @@ var BondModal = function (_a) {
71
70
  //user to buy
72
71
  //Check with Fede if this needs to be temp, if we force approval everytime, isn't this fine?
73
72
  var handleBuy = function () { return __awaiter(void 0, void 0, void 0, function () {
74
- var billAddress, decimals, maxPrice, amount;
75
- return __generator(this, function (_a) {
73
+ var billAddress, decimals, maxPrice, amount, amountAlt, amountAlt2;
74
+ var _a;
75
+ return __generator(this, function (_b) {
76
76
  billAddress = bondData[0].billAddress;
77
77
  decimals = 18;
78
78
  try {
79
+ console.log('HANDLEBUY CLICKED');
79
80
  maxPrice = new BigNumber(bondData[0].trueBillPrice).times(102).div(100);
80
81
  amount = convertToTokenValue(inputValue, decimals);
82
+ amountAlt = adjustDecimals(inputValue);
83
+ amountAlt2 = new BigNumber(amountAlt).times(new BigNumber(10).pow((_a = bondData[0].principalTokenDecimals) !== null && _a !== void 0 ? _a : 18)).toString();
84
+ console.log('Amount:', amount);
85
+ console.log('MaxPrice:', maxPrice);
81
86
  // @ts-ignore
82
87
  writeContract({
83
88
  address: billAddress,
84
89
  abi: BOND_ABI,
85
90
  functionName: 'deposit',
86
- args: [amount, maxPrice, account],
91
+ args: [amount, maxPrice.toFixed(0), account],
87
92
  });
88
93
  console.log('BuyTransaction:', hash);
89
94
  if (hash) {
@@ -101,39 +106,30 @@ var BondModal = function (_a) {
101
106
  var _e = useState(null), buyTx = _e[0], setBuyTx = _e[1];
102
107
  //You approve the token, not the contract (this code will have to be updated for zap)
103
108
  var handleApprove = function () { return __awaiter(void 0, void 0, void 0, function () {
104
- var tokenAddress, decimals, amount, result, error_1;
109
+ var tokenAddress, decimals, amount;
105
110
  return __generator(this, function (_a) {
106
- switch (_a.label) {
107
- case 0:
108
- tokenAddress = bondData[0].principalToken;
109
- decimals = 18;
110
- _a.label = 1;
111
- case 1:
112
- _a.trys.push([1, 3, , 4]);
113
- amount = convertToTokenValue(inputValue, decimals);
114
- console.log('Amount:', amount);
115
- return [4 /*yield*/, writeContract({
116
- address: tokenAddress,
117
- abi: ERC_20_ABI,
118
- functionName: 'approve',
119
- args: [account, amount]
120
- })];
121
- case 2:
122
- result = _a.sent();
123
- console.log('Result:', result);
124
- console.log('ApproveTransaction:', hash);
125
- if (hash) {
126
- setApproveTx(hash);
127
- console.log('setApproveTx:', hash);
128
- }
129
- return [3 /*break*/, 4];
130
- case 3:
131
- error_1 = _a.sent();
132
- console.error('Approval failed:', error_1);
133
- alert('Approval Failed');
134
- return [3 /*break*/, 4];
135
- case 4: return [2 /*return*/];
111
+ tokenAddress = bondData[0].principalToken;
112
+ decimals = 18;
113
+ try {
114
+ amount = convertToTokenValue(inputValue, decimals);
115
+ console.log('Amount:', amount);
116
+ writeContract({
117
+ address: tokenAddress,
118
+ abi: ERC_20_ABI,
119
+ functionName: 'approve',
120
+ args: [account, amount]
121
+ });
122
+ console.log('ApproveTransaction:', hash);
123
+ if (hash) {
124
+ setApproveTx(hash);
125
+ console.log('setApproveTx:', hash);
126
+ }
136
127
  }
128
+ catch (error) {
129
+ console.error('Approval failed:', error);
130
+ alert('Approval Failed');
131
+ }
132
+ return [2 /*return*/];
137
133
  });
138
134
  }); };
139
135
  var _f = useState(null), approveTx = _f[0], setApproveTx = _f[1];
@@ -173,13 +169,7 @@ var BondModal = function (_a) {
173
169
  var handleInputChange = function (event) {
174
170
  setInputValue(event.target.value);
175
171
  };
176
- var _h = useState(null), selectedBond = _h[0], setSelectedBond = _h[1];
177
- var navigate = useNavigate();
178
- var projectInfo = function (bond) {
179
- setSelectedBond(bond);
180
- navigate("/bondsingle/".concat(bond.billAddress));
181
- };
182
- var _j = useState(null), tokenBalance = _j[0], setTokenBalance = _j[1];
172
+ var _h = useState(null), tokenBalance = _h[0], setTokenBalance = _h[1];
183
173
  useEffect(function () {
184
174
  if (isActive && account && bondData.length > 0) {
185
175
  getTokenBalance(bondData[0].chainId, bondData[0].principalToken, account).then(function (balance) {
@@ -188,7 +178,7 @@ var BondModal = function (_a) {
188
178
  }
189
179
  }, [isActive, account, bondData]);
190
180
  var getTokenBalance = function (chainId, tokenAddress, walletAddress) { return __awaiter(void 0, void 0, void 0, function () {
191
- var urls, provider, contract, balance, balanceInEther, error_2;
181
+ var urls, provider, contract, balance, balanceInEther, error_1;
192
182
  return __generator(this, function (_a) {
193
183
  switch (_a.label) {
194
184
  case 0:
@@ -206,8 +196,8 @@ var BondModal = function (_a) {
206
196
  console.log("Token Balance: ".concat(balanceInEther));
207
197
  return [2 /*return*/, balanceInEther];
208
198
  case 2:
209
- error_2 = _a.sent();
210
- console.error('Error fetching token balance', error_2);
199
+ error_1 = _a.sent();
200
+ console.error('Error fetching token balance', error_1);
211
201
  return [2 /*return*/, 'Error fetching token balance'];
212
202
  case 3: return [2 /*return*/];
213
203
  }
@@ -230,7 +220,7 @@ var BondModal = function (_a) {
230
220
  ? v.currentTarget.value
231
221
  : v.currentTarget.value.slice(0, v.currentTarget.value.length - 1);
232
222
  } }) }), _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, { onClick: function () { window.open('https://ape.bond/swap', '_blank'); }, children: ["Get ", bond === null || bond === void 0 ? void 0 : bond.principalTokenName] }) }), _jsx(Flex, { className: "button-container buy", children: approveTx != null ?
233
- _jsxs(Button, { onClick: handleBuy, children: ["Buy ", bond === null || bond === void 0 ? void 0 : bond.showcaseTokenName] })
223
+ _jsxs(Button, { disabled: isPending, onClick: handleBuy, children: ["Buy ", bond === null || bond === void 0 ? void 0 : bond.showcaseTokenName] })
234
224
  :
235
225
  _jsx(Button, { disabled: isPending, onClick: handleApprove, children: "Approve" }) })] })] })] }) }) }, bond.billAddress));
236
226
  }) }));
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Ape Bond SDK",
4
4
  "author": "Ape Bond",
5
5
  "license": "MIT",
6
- "version": "1.0.575",
6
+ "version": "1.0.577",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist/index.es.js",
9
9
  "types": "dist/index.d.ts",