@ape.swap/bonds-sdk 1.0.568 → 1.0.570

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.
@@ -3,7 +3,6 @@ import React from 'react';
3
3
  import '../../../scss/BondModal.scss';
4
4
  interface BondModalProps {
5
5
  account: string;
6
- accountChainId: number;
7
6
  isActive: boolean;
8
7
  isOpen: boolean;
9
8
  onClose: () => void;
@@ -58,7 +58,7 @@ import '../../../scss/BondModal.scss';
58
58
  import { useWaitForTransactionReceipt, useWriteContract } from "wagmi";
59
59
  import { PUBLIC_RPC_URLS } from "../../../config/constants/networks";
60
60
  var BondModal = function (_a) {
61
- var account = _a.account, accountChainId = _a.accountChainId, isActive = _a.isActive, isOpen = _a.isOpen, onClose = _a.onClose, bondAddress = _a.bondAddress;
61
+ var account = _a.account, isActive = _a.isActive, isOpen = _a.isOpen, onClose = _a.onClose, bondAddress = _a.bondAddress;
62
62
  if (!isOpen)
63
63
  return null;
64
64
  var _b = useWriteContract(), hash = _b.data, isPending = _b.isPending, writeContract = _b.writeContract;
@@ -71,76 +71,60 @@ var BondModal = function (_a) {
71
71
  //user to buy
72
72
  //Check with Fede if this needs to be temp, if we force approval everytime, isn't this fine?
73
73
  var handleBuy = function () { return __awaiter(void 0, void 0, void 0, function () {
74
- var billAddress, decimals, maxPrice, amount, error_1;
74
+ var billAddress, decimals, maxPrice, amount;
75
75
  return __generator(this, function (_a) {
76
- switch (_a.label) {
77
- case 0:
78
- billAddress = bondData[0].billAddress;
79
- decimals = 18;
80
- _a.label = 1;
81
- case 1:
82
- _a.trys.push([1, 3, , 4]);
83
- maxPrice = new BigNumber(bondData[0].trueBillPrice).times(102).div(100);
84
- amount = convertToTokenValue(inputValue, decimals);
85
- // @ts-ignore
86
- return [4 /*yield*/, writeContract({
87
- address: billAddress,
88
- abi: BOND_ABI,
89
- functionName: 'deposit',
90
- args: [amount, maxPrice, account],
91
- })];
92
- case 2:
93
- // @ts-ignore
94
- _a.sent();
95
- console.log('Transaction:', hash);
96
- if (hash != null) {
97
- setBuyTx(hash);
98
- }
99
- return [3 /*break*/, 4];
100
- case 3:
101
- error_1 = _a.sent();
102
- console.error('Buy error', error_1);
103
- alert('Buy Failed');
104
- return [3 /*break*/, 4];
105
- case 4: return [2 /*return*/];
76
+ billAddress = bondData[0].billAddress;
77
+ decimals = 18;
78
+ try {
79
+ maxPrice = new BigNumber(bondData[0].trueBillPrice).times(102).div(100);
80
+ amount = convertToTokenValue(inputValue, decimals);
81
+ // @ts-ignore
82
+ writeContract({
83
+ address: billAddress,
84
+ abi: BOND_ABI,
85
+ functionName: 'deposit',
86
+ args: [amount, maxPrice, account],
87
+ });
88
+ console.log('BuyTransaction:', hash);
89
+ if (hash) {
90
+ setBuyTx(hash);
91
+ console.log('setBuyTx:', hash);
92
+ }
93
+ }
94
+ catch (error) {
95
+ console.error('Buy error', error);
96
+ alert('Buy Failed');
106
97
  }
98
+ return [2 /*return*/];
107
99
  });
108
100
  }); };
109
101
  var _e = useState(null), buyTx = _e[0], setBuyTx = _e[1];
110
102
  //You approve the token, not the contract (this code will have to be updated for zap)
111
103
  var handleApprove = function () { return __awaiter(void 0, void 0, void 0, function () {
112
- var tokenAddress, decimals, amount, error_2;
104
+ var tokenAddress, decimals, amount;
113
105
  return __generator(this, function (_a) {
114
- switch (_a.label) {
115
- case 0:
116
- tokenAddress = bondData[0].principalToken;
117
- decimals = 18;
118
- _a.label = 1;
119
- case 1:
120
- _a.trys.push([1, 3, , 4]);
121
- amount = convertToTokenValue(inputValue, decimals);
122
- console.log('Amount:', amount);
123
- return [4 /*yield*/, writeContract({
124
- address: tokenAddress,
125
- abi: ERC_20_ABI,
126
- functionName: 'approve',
127
- args: [account, amount]
128
- })];
129
- case 2:
130
- _a.sent();
131
- console.log('Transaction:', hash);
132
- if (hash != null) {
133
- setApproveTx(hash);
134
- console.log('setApproveTx:', hash);
135
- }
136
- return [3 /*break*/, 4];
137
- case 3:
138
- error_2 = _a.sent();
139
- console.error('Approval failed:', error_2);
140
- alert('Approval Failed');
141
- return [3 /*break*/, 4];
142
- case 4: return [2 /*return*/];
106
+ tokenAddress = bondData[0].principalToken;
107
+ decimals = 18;
108
+ try {
109
+ amount = convertToTokenValue(inputValue, decimals);
110
+ console.log('Amount:', amount);
111
+ writeContract({
112
+ address: tokenAddress,
113
+ abi: ERC_20_ABI,
114
+ functionName: 'approve',
115
+ args: [account, amount]
116
+ });
117
+ console.log('ApproveTransaction:', hash);
118
+ if (hash) {
119
+ setApproveTx(hash);
120
+ console.log('setApproveTx:', hash);
121
+ }
122
+ }
123
+ catch (error) {
124
+ console.error('Approval failed:', error);
125
+ alert('Approval Failed');
143
126
  }
127
+ return [2 /*return*/];
144
128
  });
145
129
  }); };
146
130
  var _f = useState(null), approveTx = _f[0], setApproveTx = _f[1];
@@ -195,7 +179,7 @@ var BondModal = function (_a) {
195
179
  }
196
180
  }, [isActive, account, bondData]);
197
181
  var getTokenBalance = function (chainId, tokenAddress, walletAddress) { return __awaiter(void 0, void 0, void 0, function () {
198
- var urls, provider, contract, balance, balanceInEther, error_3;
182
+ var urls, provider, contract, balance, balanceInEther, error_1;
199
183
  return __generator(this, function (_a) {
200
184
  switch (_a.label) {
201
185
  case 0:
@@ -213,8 +197,8 @@ var BondModal = function (_a) {
213
197
  console.log("Token Balance: ".concat(balanceInEther));
214
198
  return [2 /*return*/, balanceInEther];
215
199
  case 2:
216
- error_3 = _a.sent();
217
- console.error('Error fetching token balance', error_3);
200
+ error_1 = _a.sent();
201
+ console.error('Error fetching token balance', error_1);
218
202
  return [2 /*return*/, 'Error fetching token balance'];
219
203
  case 3: return [2 /*return*/];
220
204
  }
@@ -90,7 +90,7 @@ var YourBonds = function (_a) {
90
90
  })];
91
91
  case 2:
92
92
  tx = _a.sent();
93
- console.log('Transaction:', tx);
93
+ console.log('ClaimTransaction:', tx);
94
94
  if (tx != null) {
95
95
  setClaimTx(tx);
96
96
  }
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.568",
6
+ "version": "1.0.570",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist/index.es.js",
9
9
  "types": "dist/index.d.ts",