@splitmarkets/sdk 0.2.1 → 0.2.2

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.
Files changed (2) hide show
  1. package/dist/widget.js +20 -15
  2. package/package.json +1 -1
package/dist/widget.js CHANGED
@@ -36,7 +36,7 @@ function SplitTradeWidget({
36
36
  const [side, setSide] = useState("long");
37
37
  const [markets, setMarkets] = useState([]);
38
38
  const [picked, setPicked] = useState(null);
39
- const [amount, setAmount] = useState("0.1");
39
+ const [amount, setAmount] = useState("5");
40
40
  const [position, setPosition] = useState(null);
41
41
  const [status, setStatus] = useState("");
42
42
  const [busy, setBusy] = useState(false);
@@ -105,11 +105,17 @@ function SplitTradeWidget({
105
105
  setStatus("Connect a wallet first.");
106
106
  return;
107
107
  }
108
- const qN = Number(amount);
109
- if (!(qN > 0)) {
110
- setStatus("Enter an amount > 0.");
108
+ const usd = Number(amount);
109
+ if (!(usd > 0)) {
110
+ setStatus("Enter a dollar amount > 0.");
111
111
  return;
112
112
  }
113
+ const m = markets.find((x) => x.seriesId === picked);
114
+ if (!m || !(m.premium > 0)) {
115
+ setStatus("Market not ready \u2014 try again.");
116
+ return;
117
+ }
118
+ const qN = usd / m.premium;
113
119
  setBusy(true);
114
120
  try {
115
121
  if (gasless) {
@@ -117,11 +123,11 @@ function SplitTradeWidget({
117
123
  const t = trading ?? await deriveTradingAccount(walletClient, account, chain);
118
124
  if (!trading) setTrading(t);
119
125
  const r = await buyGasless({ chain, side, seriesId: picked, qN, walletClient, account, trading: t });
120
- setStatus(`Bought ${qN} contracts. tx ${r.txHash.slice(0, 10)}\u2026`);
126
+ setStatus(`Bought $${usd} of ${side}. tx ${r.txHash.slice(0, 10)}\u2026`);
121
127
  } else {
122
128
  setStatus("Confirm in your wallet (approve, then buy)\u2026");
123
129
  const r = await buy({ chain, side, seriesId: picked, qN, walletClient, account });
124
- setStatus(`Bought ${r.qN} contracts. tx ${r.txHash.slice(0, 10)}\u2026`);
130
+ setStatus(`Bought $${usd} of ${side}. tx ${r.txHash.slice(0, 10)}\u2026`);
125
131
  }
126
132
  await refreshPosition();
127
133
  } catch (e) {
@@ -181,31 +187,30 @@ function SplitTradeWidget({
181
187
  children: [
182
188
  /* @__PURE__ */ jsx("div", { className: "swt-lev", children: m.leverage > 0 ? `${m.leverage.toFixed(0)}x` : "\u2014" }),
183
189
  /* @__PURE__ */ jsxs("div", { className: "swt-muted", children: [
184
- "$",
185
- m.strike.toLocaleString()
190
+ "ETH ",
191
+ side === "long" ? ">" : "<",
192
+ " $",
193
+ (side === "long" ? m.strike + m.premium : m.strike - m.premium).toLocaleString(void 0, { maximumFractionDigits: 0 })
186
194
  ] }),
187
- /* @__PURE__ */ jsxs("div", { className: "swt-muted-sm", children: [
188
- "$",
189
- m.premium.toFixed(2),
190
- "/contract"
191
- ] })
195
+ /* @__PURE__ */ jsx("div", { className: "swt-muted-sm", children: "by expiry" })
192
196
  ]
193
197
  },
194
198
  m.seriesId
195
199
  ))
196
200
  ] }),
197
201
  /* @__PURE__ */ jsxs("div", { className: "swt-row", children: [
202
+ /* @__PURE__ */ jsx("span", { className: "swt-muted", children: "$" }),
198
203
  /* @__PURE__ */ jsx(
199
204
  "input",
200
205
  {
201
206
  value: amount,
202
207
  onChange: (e) => setAmount(e.target.value),
203
208
  inputMode: "decimal",
204
- placeholder: "0.1",
209
+ placeholder: "5",
205
210
  className: "swt-input"
206
211
  }
207
212
  ),
208
- /* @__PURE__ */ jsx("span", { className: "swt-muted", children: "contracts" }),
213
+ /* @__PURE__ */ jsx("span", { className: "swt-muted", children: "USDC" }),
209
214
  /* @__PURE__ */ jsx(
210
215
  "button",
211
216
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splitmarkets/sdk",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Oracle-free, non-liquidatable ETH options — viem client + optional React widget for Split (split.markets). Integrate leverage your users can't get liquidated out of.",
5
5
  "license": "MIT",
6
6
  "type": "module",