@ape.swap/bonds-sdk 1.0.566 → 1.0.568

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.
@@ -55,20 +55,23 @@ import ERC_20_ABI from '../../../config/abi/erc20.json';
55
55
  import { NETWORK_ICONS } from '../../../config/constants/chains';
56
56
  import { formatUSDNumber, getPremiumColor, premium, youGet, youGetUSD, youSpend, youSpendUSD } from './helper';
57
57
  import '../../../scss/BondModal.scss';
58
- import { useWriteContract } from "wagmi";
58
+ import { useWaitForTransactionReceipt, useWriteContract } from "wagmi";
59
59
  import { PUBLIC_RPC_URLS } from "../../../config/constants/networks";
60
60
  var BondModal = function (_a) {
61
61
  var account = _a.account, accountChainId = _a.accountChainId, isActive = _a.isActive, isOpen = _a.isOpen, onClose = _a.onClose, bondAddress = _a.bondAddress;
62
62
  if (!isOpen)
63
63
  return null;
64
- var _b = useWriteContract(), hash = _b.data, writeContract = _b.writeContract;
64
+ var _b = useWriteContract(), hash = _b.data, isPending = _b.isPending, writeContract = _b.writeContract;
65
+ var _c = useWaitForTransactionReceipt({
66
+ hash: hash,
67
+ }), isConfirming = _c.isLoading, isConfirmed = _c.isSuccess;
65
68
  //const { account, isActive } = useWeb3React();
66
- var _c = useState([]), bondData = _c[0], setBondData = _c[1];
69
+ var _d = useState([]), bondData = _d[0], setBondData = _d[1];
67
70
  //This is a temp solution, but we will force approval each time, and then once set we will set status here and allow
68
71
  //user to buy
69
72
  //Check with Fede if this needs to be temp, if we force approval everytime, isn't this fine?
70
73
  var handleBuy = function () { return __awaiter(void 0, void 0, void 0, function () {
71
- var billAddress, decimals, maxPrice, amount, tx, error_1;
74
+ var billAddress, decimals, maxPrice, amount, error_1;
72
75
  return __generator(this, function (_a) {
73
76
  switch (_a.label) {
74
77
  case 0:
@@ -79,6 +82,7 @@ var BondModal = function (_a) {
79
82
  _a.trys.push([1, 3, , 4]);
80
83
  maxPrice = new BigNumber(bondData[0].trueBillPrice).times(102).div(100);
81
84
  amount = convertToTokenValue(inputValue, decimals);
85
+ // @ts-ignore
82
86
  return [4 /*yield*/, writeContract({
83
87
  address: billAddress,
84
88
  abi: BOND_ABI,
@@ -86,10 +90,11 @@ var BondModal = function (_a) {
86
90
  args: [amount, maxPrice, account],
87
91
  })];
88
92
  case 2:
89
- tx = _a.sent();
90
- console.log('Transaction:', tx);
91
- if (tx != null) {
92
- setBuyTx(tx);
93
+ // @ts-ignore
94
+ _a.sent();
95
+ console.log('Transaction:', hash);
96
+ if (hash != null) {
97
+ setBuyTx(hash);
93
98
  }
94
99
  return [3 /*break*/, 4];
95
100
  case 3:
@@ -101,7 +106,7 @@ var BondModal = function (_a) {
101
106
  }
102
107
  });
103
108
  }); };
104
- var _d = useState(null), buyTx = _d[0], setBuyTx = _d[1];
109
+ var _e = useState(null), buyTx = _e[0], setBuyTx = _e[1];
105
110
  //You approve the token, not the contract (this code will have to be updated for zap)
106
111
  var handleApprove = function () { return __awaiter(void 0, void 0, void 0, function () {
107
112
  var tokenAddress, decimals, amount, error_2;
@@ -119,13 +124,14 @@ var BondModal = function (_a) {
119
124
  address: tokenAddress,
120
125
  abi: ERC_20_ABI,
121
126
  functionName: 'approve',
122
- args: [account, amount],
127
+ args: [account, amount]
123
128
  })];
124
129
  case 2:
125
130
  _a.sent();
126
131
  console.log('Transaction:', hash);
127
132
  if (hash != null) {
128
133
  setApproveTx(hash);
134
+ console.log('setApproveTx:', hash);
129
135
  }
130
136
  return [3 /*break*/, 4];
131
137
  case 3:
@@ -137,7 +143,7 @@ var BondModal = function (_a) {
137
143
  }
138
144
  });
139
145
  }); };
140
- var _e = useState(null), approveTx = _e[0], setApproveTx = _e[1];
146
+ var _f = useState(null), approveTx = _f[0], setApproveTx = _f[1];
141
147
  // Fetch data
142
148
  useEffect(function () {
143
149
  axios.get('https://realtime-api.ape.bond/bonds').then(function (response) {
@@ -170,17 +176,17 @@ var BondModal = function (_a) {
170
176
  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
177
  return !available ? 0 : (singlePurchaseLimit.lt(safeAvailable) ? singlePurchaseLimit : safeAvailable);
172
178
  };
173
- var _f = useState(''), inputValue = _f[0], setInputValue = _f[1];
179
+ var _g = useState(''), inputValue = _g[0], setInputValue = _g[1];
174
180
  var handleInputChange = function (event) {
175
181
  setInputValue(event.target.value);
176
182
  };
177
- var _g = useState(null), selectedBond = _g[0], setSelectedBond = _g[1];
183
+ var _h = useState(null), selectedBond = _h[0], setSelectedBond = _h[1];
178
184
  var navigate = useNavigate();
179
185
  var projectInfo = function (bond) {
180
186
  setSelectedBond(bond);
181
187
  navigate("/bondsingle/".concat(bond.billAddress));
182
188
  };
183
- var _h = useState(null), tokenBalance = _h[0], setTokenBalance = _h[1];
189
+ var _j = useState(null), tokenBalance = _j[0], setTokenBalance = _j[1];
184
190
  useEffect(function () {
185
191
  if (isActive && account && bondData.length > 0) {
186
192
  getTokenBalance(bondData[0].chainId, bondData[0].principalToken, account).then(function (balance) {
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.566",
6
+ "version": "1.0.568",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist/index.es.js",
9
9
  "types": "dist/index.d.ts",