@ape.swap/bonds-sdk 1.0.563 → 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 convertToTokenValue, { adjustDecimals } from "../../../utils/convertToTokenValue";
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,46 +64,44 @@ 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 provider, signer, bondContract, maxPrice, amount, tx, error_1;
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
- console.log('handle buy clicked');
77
- if (!window.ethereum) {
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, 4, , 5]);
79
+ _a.trys.push([1, 3, , 4]);
88
80
  maxPrice = new BigNumber(bondData[0].trueBillPrice).times(102).div(100);
89
- amount = adjustDecimals(inputValue);
90
- return [4 /*yield*/, bondContract.deposit(amount, maxPrice, account)];
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
- return [4 /*yield*/, tx.wait()];
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('Approval error', error_1);
101
- alert('Approval Failed');
102
- return [3 /*break*/, 5];
103
- case 5: return [2 /*return*/];
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
107
  var tokenAddress, decimals, amount, tx, error_2;
@@ -115,7 +113,6 @@ var BondModal = function (_a) {
115
113
  _a.label = 1;
116
114
  case 1:
117
115
  _a.trys.push([1, 3, , 4]);
118
- console.log(adjustDecimals(inputValue));
119
116
  amount = convertToTokenValue(inputValue, decimals);
120
117
  console.log('Amount:', amount);
121
118
  return [4 /*yield*/, writeContract({
@@ -127,7 +124,9 @@ var BondModal = function (_a) {
127
124
  case 2:
128
125
  tx = _a.sent();
129
126
  console.log('Transaction:', tx);
130
- alert('Buy Successful');
127
+ if (tx != null) {
128
+ setApproveTx(tx);
129
+ }
131
130
  return [3 /*break*/, 4];
132
131
  case 3:
133
132
  error_2 = _a.sent();
@@ -138,6 +137,7 @@ var BondModal = function (_a) {
138
137
  }
139
138
  });
140
139
  }); };
140
+ var _d = useState(null), approveTx = _d[0], setApproveTx = _d[1];
141
141
  // Fetch data
142
142
  useEffect(function () {
143
143
  axios.get('https://realtime-api.ape.bond/bonds').then(function (response) {
@@ -170,17 +170,17 @@ var BondModal = function (_a) {
170
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));
171
171
  return !available ? 0 : (singlePurchaseLimit.lt(safeAvailable) ? singlePurchaseLimit : safeAvailable);
172
172
  };
173
- var _d = useState(''), inputValue = _d[0], setInputValue = _d[1];
173
+ var _e = useState(''), inputValue = _e[0], setInputValue = _e[1];
174
174
  var handleInputChange = function (event) {
175
175
  setInputValue(event.target.value);
176
176
  };
177
- var _e = useState(null), selectedBond = _e[0], setSelectedBond = _e[1];
177
+ var _f = useState(null), selectedBond = _f[0], setSelectedBond = _f[1];
178
178
  var navigate = useNavigate();
179
179
  var projectInfo = function (bond) {
180
180
  setSelectedBond(bond);
181
181
  navigate("/bondsingle/".concat(bond.billAddress));
182
182
  };
183
- var _f = useState(null), tokenBalance = _f[0], setTokenBalance = _f[1];
183
+ var _g = useState(null), tokenBalance = _g[0], setTokenBalance = _g[1];
184
184
  useEffect(function () {
185
185
  if (isActive && account && bondData.length > 0) {
186
186
  getTokenBalance(bondData[0].chainId, bondData[0].principalToken, account).then(function (balance) {
@@ -230,7 +230,7 @@ var BondModal = function (_a) {
230
230
  !!v.currentTarget.value && isNumber(v.currentTarget.value) && parseFloat(v.currentTarget.value) >= 0
231
231
  ? v.currentTarget.value
232
232
  : v.currentTarget.value.slice(0, v.currentTarget.value.length - 1);
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: approvalStatus === true ?
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 ?
234
234
  _jsxs(Button, { onClick: handleBuy, children: ["Buy ", bond === null || bond === void 0 ? void 0 : bond.showcaseTokenName] })
235
235
  :
236
236
  _jsx(Button, { onClick: handleApprove, children: "Approve" }) })] })] })] }) }) }, bond.billAddress));
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.563",
6
+ "version": "1.0.564",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist/index.es.js",
9
9
  "types": "dist/index.d.ts",