@kodiak-finance/orderly-wallet-connector-privy 2.8.18 → 2.8.19

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.
package/README.md CHANGED
@@ -35,6 +35,13 @@ If abstractConfig is not configured, the Abstract Global Wallet connector will b
35
35
 
36
36
  At least one of privyConfig, wagmiConfig, or solanaConfig must be provided.
37
37
 
38
+ **Available Login Methods for Privy:**
39
+
40
+ - `email` - Email/password login
41
+ - `google` - Google OAuth login
42
+ - `twitter` - Twitter OAuth login
43
+ - `telegram` - Telegram login (optional)
44
+
38
45
  If customChains only includes a Solana chain, then Privy will only display the Solana injected wallet, and the Wagmi connector will be disabled.
39
46
 
40
47
  If customChains only includes EVM chains, then Privy will only display the EVM injected wallet, and the Solana connector will be disabled.
@@ -54,6 +61,7 @@ eg:
54
61
  accentColor: "#181C23",
55
62
  logo: "/orderly-logo.svg",
56
63
  },
64
+ loginMethods: ["email", "google", "twitter", "telegram"],
57
65
  },
58
66
  }}
59
67
  wagmiConfig={{
package/dist/index.js CHANGED
@@ -50,11 +50,11 @@ var Network = /* @__PURE__ */ ((Network3) => {
50
50
  Network3["testnet"] = "testnet";
51
51
  return Network3;
52
52
  })(Network || {});
53
- var WalletType = /* @__PURE__ */ ((WalletType5) => {
54
- WalletType5["EVM"] = "EVM";
55
- WalletType5["SOL"] = "SOL";
56
- WalletType5["ABSTRACT"] = "Abstract";
57
- return WalletType5;
53
+ var WalletType = /* @__PURE__ */ ((WalletType4) => {
54
+ WalletType4["EVM"] = "EVM";
55
+ WalletType4["SOL"] = "SOL";
56
+ WalletType4["ABSTRACT"] = "Abstract";
57
+ return WalletType4;
58
58
  })(WalletType || {});
59
59
  var WalletConnectType = /* @__PURE__ */ ((WalletConnectType2) => {
60
60
  WalletConnectType2["EVM"] = "EVM";
@@ -232,6 +232,8 @@ var PrivyWalletProvider = ({
232
232
  address = `@${account.username}`;
233
233
  } else if (account.type === "google_oauth") {
234
234
  address = `@${account.name}`;
235
+ } else if (account.type === "telegram") {
236
+ address = `@${account.username}`;
235
237
  }
236
238
  return {
237
239
  type: account.type,
@@ -1131,6 +1133,7 @@ function useWallet2() {
1131
1133
  if (chainType === "SOL" /* SOL */) {
1132
1134
  if (isConnectedSOL && walletSOL) {
1133
1135
  setStorageChain(parseInt(chain.chainId));
1136
+ return Promise.resolve(true);
1134
1137
  } else {
1135
1138
  setOpenConnectDrawer(true);
1136
1139
  setTargetWalletType("SOL" /* SOL */);
@@ -1345,7 +1348,7 @@ var RenderLoginMethodsDom = ({
1345
1348
  {
1346
1349
  className: orderlyUi.cn(
1347
1350
  "oui-flex oui-cursor-pointer oui-items-center oui-justify-center oui-gap-1 oui-rounded-[6px] oui-border oui-border-base-contrast-12 oui-px-2 oui-py-[11px]",
1348
- isDesktop && "oui-border-none oui-bg-[#333948]"
1351
+ "oui-border-none oui-bg-[#333948]"
1349
1352
  ),
1350
1353
  onClick: () => connect({ walletType: "privy", extraType: "email" })
1351
1354
  },
@@ -1356,7 +1359,7 @@ var RenderLoginMethodsDom = ({
1356
1359
  className: "oui-size-[18px]"
1357
1360
  }
1358
1361
  ),
1359
- isDesktop && /* @__PURE__ */ React19__default.default.createElement("div", { className: "oui-text-2xs oui-text-base-contrast" }, t("connector.privy.email"))
1362
+ /* @__PURE__ */ React19__default.default.createElement("div", { className: "oui-text-2xs oui-text-base-contrast" }, t("connector.privy.email"))
1360
1363
  )
1361
1364
  );
1362
1365
  }
@@ -1367,7 +1370,7 @@ var RenderLoginMethodsDom = ({
1367
1370
  {
1368
1371
  className: orderlyUi.cn(
1369
1372
  "oui-flex oui-cursor-pointer oui-items-center oui-justify-center oui-gap-1 oui-rounded-[6px] oui-border oui-border-base-contrast-12 oui-px-2 oui-py-[11px]",
1370
- isDesktop && "oui-border-none oui-bg-[#335FFC]"
1373
+ "oui-border-none oui-bg-[#335FFC]"
1371
1374
  ),
1372
1375
  onClick: () => connect({ walletType: "privy", extraType: "google" })
1373
1376
  },
@@ -1378,7 +1381,7 @@ var RenderLoginMethodsDom = ({
1378
1381
  className: "oui-size-[18px]"
1379
1382
  }
1380
1383
  ),
1381
- isDesktop && /* @__PURE__ */ React19__default.default.createElement("div", { className: "oui-text-2xs oui-text-base-contrast" }, t("connector.privy.google"))
1384
+ /* @__PURE__ */ React19__default.default.createElement("div", { className: "oui-text-2xs oui-text-base-contrast" }, t("connector.privy.google"))
1382
1385
  )
1383
1386
  );
1384
1387
  }
@@ -1389,7 +1392,7 @@ var RenderLoginMethodsDom = ({
1389
1392
  {
1390
1393
  className: orderlyUi.cn(
1391
1394
  "oui-flex oui-cursor-pointer oui-items-center oui-justify-center oui-gap-1 oui-rounded-[6px] oui-border oui-border-base-contrast-12 oui-px-2 oui-py-[11px]",
1392
- isDesktop && "oui-border-none oui-bg-[#07080A]"
1395
+ "oui-border-none oui-bg-[#07080A]"
1393
1396
  ),
1394
1397
  onClick: () => connect({ walletType: "privy", extraType: "twitter" })
1395
1398
  },
@@ -1400,7 +1403,39 @@ var RenderLoginMethodsDom = ({
1400
1403
  className: "oui-size-[18px]"
1401
1404
  }
1402
1405
  ),
1403
- isDesktop && /* @__PURE__ */ React19__default.default.createElement("div", { className: "oui-text-2xs oui-text-base-contrast" }, t("connector.privy.twitter"))
1406
+ /* @__PURE__ */ React19__default.default.createElement("div", { className: "oui-text-2xs oui-text-base-contrast" }, t("connector.privy.twitter"))
1407
+ )
1408
+ );
1409
+ }
1410
+ if (loginMethods?.includes("telegram")) {
1411
+ arr.push(
1412
+ /* @__PURE__ */ React19__default.default.createElement(
1413
+ "div",
1414
+ {
1415
+ className: orderlyUi.cn(
1416
+ "oui-flex oui-cursor-pointer oui-items-center oui-justify-center oui-gap-1 oui-rounded-[6px] oui-border oui-border-base-contrast-12 oui-px-2 oui-py-[11px]",
1417
+ "oui-border-none oui-bg-[#3D79A9]"
1418
+ ),
1419
+ onClick: () => connect({ walletType: "privy", extraType: "telegram" })
1420
+ },
1421
+ /* @__PURE__ */ React19__default.default.createElement(
1422
+ "svg",
1423
+ {
1424
+ width: "18",
1425
+ height: "18",
1426
+ viewBox: "0 0 18 18",
1427
+ fill: "none",
1428
+ xmlns: "http://www.w3.org/2000/svg"
1429
+ },
1430
+ /* @__PURE__ */ React19__default.default.createElement(
1431
+ "path",
1432
+ {
1433
+ d: "M2.652 8.12916L15.0683 4.04929C15.6468 3.87358 16.1499 4.16929 15.9587 4.91069L13.8458 13.3962C13.6898 13.9961 13.2672 14.1461 12.6836 13.859L9.46384 11.8362L7.90929 13.109C7.73824 13.2547 7.59234 13.379 7.2603 13.379L7.4867 10.5891L13.4584 5.99923C13.72 5.80638 13.398 5.69495 13.0559 5.8878L5.68061 9.8434L2.50107 8.99914C1.81687 8.81058 1.80178 8.41201 2.652 8.12916Z",
1434
+ fill: "white"
1435
+ }
1436
+ )
1437
+ ),
1438
+ /* @__PURE__ */ React19__default.default.createElement("div", { className: "oui-text-2xs oui-text-base-contrast" }, t("connector.privy.telegram"))
1404
1439
  )
1405
1440
  );
1406
1441
  }
@@ -1415,7 +1450,7 @@ var PrivyConnectAreaMobile = ({
1415
1450
  const { isMobile, isDesktop } = orderlyUi.useScreen();
1416
1451
  const { connectorWalletType, privyConfig } = useWalletConnectorPrivy();
1417
1452
  const loginMethods = privyConfig.loginMethods;
1418
- return /* @__PURE__ */ React19__default.default.createElement(orderlyUi.Flex, { direction: "column", className: "oui-w-full" }, /* @__PURE__ */ React19__default.default.createElement(orderlyUi.Grid, { cols: 3, rows: 1, className: "oui-w-full", gap: 2 }, /* @__PURE__ */ React19__default.default.createElement(RenderLoginMethodsDom, { connect, loginMethods })), (!connectorWalletType.disableWagmi || !connectorWalletType.disableSolana) && /* @__PURE__ */ React19__default.default.createElement("div", { className: "oui-mt-4 oui-h-px oui-w-full oui-bg-line md:oui-mt-5" }));
1453
+ return /* @__PURE__ */ React19__default.default.createElement(orderlyUi.Flex, { direction: "column", className: "oui-w-full" }, /* @__PURE__ */ React19__default.default.createElement(orderlyUi.Grid, { cols: 2, rows: 2, className: "oui-w-full", gap: 2 }, /* @__PURE__ */ React19__default.default.createElement(RenderLoginMethodsDom, { connect, loginMethods })), (!connectorWalletType.disableWagmi || !connectorWalletType.disableSolana) && /* @__PURE__ */ React19__default.default.createElement("div", { className: "oui-mt-4 oui-h-px oui-w-full oui-bg-line md:oui-mt-5" }));
1419
1454
  };
1420
1455
  var PrivyConnectAreaDesktop = ({
1421
1456
  connect
@@ -1466,6 +1501,25 @@ function RenderPrivyTypeIcon({
1466
1501
  }
1467
1502
  );
1468
1503
  }
1504
+ if (type === "telegram") {
1505
+ return /* @__PURE__ */ React19__default.default.createElement(
1506
+ "svg",
1507
+ {
1508
+ width: size,
1509
+ height: size,
1510
+ viewBox: "0 0 18 18",
1511
+ fill: "none",
1512
+ xmlns: "http://www.w3.org/2000/svg"
1513
+ },
1514
+ /* @__PURE__ */ React19__default.default.createElement(
1515
+ "path",
1516
+ {
1517
+ d: "M2.652 8.12916L15.0683 4.04929C15.6468 3.87358 16.1499 4.16929 15.9587 4.91069L13.8458 13.3962C13.6898 13.9961 13.2672 14.1461 12.6836 13.859L9.46384 11.8362L7.90929 13.109C7.73824 13.2547 7.59234 13.379 7.2603 13.379L7.4867 10.5891L13.4584 5.99923C13.72 5.80638 13.398 5.69495 13.0559 5.8878L5.68061 9.8434L2.50107 8.99914C1.81687 8.81058 1.80178 8.41201 2.652 8.12916Z",
1518
+ fill: black ? "black" : "white"
1519
+ }
1520
+ )
1521
+ );
1522
+ }
1469
1523
  return /* @__PURE__ */ React19__default.default.createElement(
1470
1524
  "img",
1471
1525
  {
@@ -1594,7 +1648,24 @@ function EVMConnectArea({
1594
1648
  // src/components/renderConnector/index.tsx
1595
1649
  function RenderConnector() {
1596
1650
  const { connect } = useWallet2();
1597
- const { setOpenConnectDrawer, connectorWalletType, walletChainTypeConfig } = useWalletConnectorPrivy();
1651
+ const {
1652
+ setOpenConnectDrawer,
1653
+ connectorWalletType,
1654
+ walletChainTypeConfig,
1655
+ targetWalletType
1656
+ } = useWalletConnectorPrivy();
1657
+ const { storageChain } = orderlyHooks.useStorageChain();
1658
+ const selectedWalletType = (() => {
1659
+ if (targetWalletType)
1660
+ return targetWalletType;
1661
+ if (!storageChain?.chainId)
1662
+ return void 0;
1663
+ try {
1664
+ return getChainType(parseInt(storageChain.chainId));
1665
+ } catch {
1666
+ return void 0;
1667
+ }
1668
+ })();
1598
1669
  const handleConnect = (params) => {
1599
1670
  connect(params);
1600
1671
  if (params.walletType === "privy" /* PRIVY */) {
@@ -1663,7 +1734,30 @@ function RenderConnector() {
1663
1734
  }
1664
1735
  );
1665
1736
  };
1666
- return /* @__PURE__ */ React19__default.default.createElement(orderlyUi.ScrollArea, { className: "oui-flex oui-grow oui-shrik oui-basis-auto oui-custom-scrollbar" }, /* @__PURE__ */ React19__default.default.createElement("div", { className: orderlyUi.cn("oui-flex oui-flex-col oui-gap-4", "md:oui-gap-5") }, renderPrivyConnectArea(), renderWagmiConnectArea(), renderSolanaConnectArea(), renderAbstractConnectArea()));
1737
+ const walletOrder = ["evm", "sol", "abstract"];
1738
+ const typeToKey = {
1739
+ ["EVM" /* EVM */]: "evm",
1740
+ ["SOL" /* SOL */]: "sol",
1741
+ ["Abstract" /* ABSTRACT */]: "abstract"
1742
+ };
1743
+ const prioritizedKey = selectedWalletType ? typeToKey[selectedWalletType] : void 0;
1744
+ const orderedWalletKeys = prioritizedKey ? [
1745
+ prioritizedKey,
1746
+ ...walletOrder.filter((k) => k !== prioritizedKey)
1747
+ ] : walletOrder;
1748
+ const renderByKey = (key) => {
1749
+ switch (key) {
1750
+ case "evm":
1751
+ return renderWagmiConnectArea();
1752
+ case "sol":
1753
+ return renderSolanaConnectArea();
1754
+ case "abstract":
1755
+ return renderAbstractConnectArea();
1756
+ default:
1757
+ return null;
1758
+ }
1759
+ };
1760
+ return /* @__PURE__ */ React19__default.default.createElement(orderlyUi.ScrollArea, { className: "oui-flex oui-grow oui-shrik oui-basis-auto oui-custom-scrollbar" }, /* @__PURE__ */ React19__default.default.createElement("div", { className: orderlyUi.cn("oui-flex oui-flex-col oui-gap-4", "md:oui-gap-5") }, renderPrivyConnectArea(), orderedWalletKeys.map((key) => /* @__PURE__ */ React19__default.default.createElement(React19__default.default.Fragment, { key }, renderByKey(key)))));
1667
1761
  }
1668
1762
  function SwitchNetworkTips({
1669
1763
  tipsContent
@@ -2589,7 +2683,7 @@ function ConnectDrawer(props) {
2589
2683
  }
2590
2684
  ),
2591
2685
  /* @__PURE__ */ React19__default.default.createElement("div", { className: "oui-relative oui-z-10 oui-flex oui-h-full oui-flex-col oui-gap-4 md:oui-gap-5" }, /* @__PURE__ */ React19__default.default.createElement("div", { className: "oui-flex oui-flex-none oui-items-center oui-justify-between" }, renderHeader(), /* @__PURE__ */ React19__default.default.createElement(
2592
- orderlyUi.CloseIcon,
2686
+ orderlyUi.CloseSquareFillIcon,
2593
2687
  {
2594
2688
  className: "oui-size-5 oui-cursor-pointer oui-text-base-contrast-20 hover:oui-text-base-contrast-80",
2595
2689
  onClick: () => props.onChangeOpen(false)
@@ -3095,19 +3189,6 @@ var WagmiWallet = (props) => {
3095
3189
  };
3096
3190
 
3097
3191
  // src/provider.tsx
3098
- var commonSwrOpts = {
3099
- revalidateIfStale: false,
3100
- revalidateOnFocus: false,
3101
- revalidateOnReconnect: false,
3102
- // If false, undefined data gets cached against the key.
3103
- revalidateOnMount: true,
3104
- // don't duplicate a request with the same key for 1hr
3105
- dedupingInterval: 36e5
3106
- };
3107
- orderlyTypes.TesntTokenFallback([
3108
- orderlyTypes.ArbitrumSepoliaTokenInfo,
3109
- orderlyTypes.SolanaDevnetTokenInfo
3110
- ]);
3111
3192
  var testnetChainFallback = [orderlyTypes.ArbitrumSepoliaChainInfo, orderlyTypes.SolanaDevnetChainInfo];
3112
3193
  var formatSwapChainInfo = (data = {}) => {
3113
3194
  return Object.keys(data).map((key) => {
@@ -3192,7 +3273,22 @@ function WalletConnectorPrivyProvider(props) {
3192
3273
  const [initChains, setInitChains] = React19.useState([]);
3193
3274
  const [mainnetChains, setMainnetChains] = React19.useState([]);
3194
3275
  const [testnetChains, setTestnetChains] = React19.useState([]);
3195
- const initRef = React19.useRef(false);
3276
+ const [mainnetChainInfos, setMainnetChainInfos] = React19.useState(null);
3277
+ const [testChainInfos, setTestChainInfos] = React19.useState(
3278
+ null
3279
+ );
3280
+ const fetchMainChains = orderlyHooks.useMainnetChainsStore((state) => state.fetchData);
3281
+ const fetchTestChains = orderlyHooks.useTestnetChainsStore((state) => state.fetchData);
3282
+ const mainnetChainsHydrated = orderlyHooks.useMainnetChainsStore(
3283
+ (state) => state.hydrated
3284
+ );
3285
+ const testChainsHydrated = orderlyHooks.useTestnetChainsStore((state) => state.hydrated);
3286
+ const mainnetChainInfosFromStore = orderlyHooks.useMainnetChainsStore(
3287
+ (state) => state.data
3288
+ );
3289
+ const testChainInfosFromStore = orderlyHooks.useTestnetChainsStore((state) => state.data);
3290
+ const hasCustomChains = Array.isArray(props.customChains) && props.customChains.length > 0;
3291
+ const initRef = React19.useRef(hasCustomChains);
3196
3292
  const [openConnectDrawer, setOpenConnectDrawer] = React19.useState(false);
3197
3293
  const [targetWalletType, setTargetWalletType] = React19.useState();
3198
3294
  const [privyConfig, setPrivyConfig] = React19.useState({
@@ -3237,24 +3333,29 @@ function WalletConnectorPrivyProvider(props) {
3237
3333
  });
3238
3334
  return chainTypeObj;
3239
3335
  }, [initChains]);
3240
- const { data: swapChainInfoRes, isLoading: swapLoading } = orderlyHooks.useSWR(
3241
- !props.customChains && props.enableSwapDeposit ? "https://fi-api.woo.org/swap_support" : null,
3242
- orderlyHooks.fetcher,
3243
- commonSwrOpts
3244
- );
3245
- const { data: mainnetChainInfos } = orderlyHooks.useSWR(
3246
- !props.customChains ? "https://api.orderly.org/v1/public/chain_info" : null,
3247
- orderlyHooks.fetcher,
3248
- commonSwrOpts
3249
- );
3250
- const { data: testChainInfos } = orderlyHooks.useSWR(
3251
- !props.customChains ? "https://testnet-api.orderly.org/v1/public/chain_info" : null,
3252
- orderlyHooks.fetcher,
3253
- {
3254
- ...commonSwrOpts,
3255
- fallbackData: testnetChainFallback
3336
+ const {
3337
+ data: swapChainInfoRes,
3338
+ // loading: swapLoading,
3339
+ fetchData: fetchSwapData
3340
+ } = orderlyHooks.useSwapSupportStore();
3341
+ React19.useEffect(() => {
3342
+ if (!props.enableSwapDeposit || !!props.customChains)
3343
+ return;
3344
+ fetchSwapData();
3345
+ }, [props.enableSwapDeposit, props.customChains]);
3346
+ React19.useEffect(() => {
3347
+ if (!mainnetChainsHydrated || !testChainsHydrated)
3348
+ return;
3349
+ if (Array.isArray(orderlyHooks.useMainnetChainsStore.getState().data) && orderlyHooks.useTestnetChainsStore.getState().data) {
3350
+ return;
3256
3351
  }
3257
- );
3352
+ fetchMainChains().then((data) => {
3353
+ setMainnetChainInfos(data);
3354
+ });
3355
+ fetchTestChains().then((data) => {
3356
+ setTestChainInfos(data);
3357
+ });
3358
+ }, [mainnetChainsHydrated, testChainsHydrated]);
3258
3359
  const handleCustomerChains = () => {
3259
3360
  const testChains = processChainInfo(
3260
3361
  props.customChains.testnet?.map((item) => item.network_infos)
@@ -3337,21 +3438,33 @@ function WalletConnectorPrivyProvider(props) {
3337
3438
  ]
3338
3439
  );
3339
3440
  React19.useEffect(() => {
3340
- if (props.customChains) {
3441
+ if (initRef.current)
3442
+ return;
3443
+ if (hasCustomChains) {
3341
3444
  return;
3342
3445
  }
3343
- if (!mainnetChainInfos || !testChainInfos || swapLoading) {
3446
+ const hasStoreData = mainnetChainInfosFromStore && testChainInfosFromStore;
3447
+ const hasApiData = mainnetChainInfos && testChainInfos;
3448
+ if (!hasStoreData && !hasApiData) {
3449
+ return;
3450
+ }
3451
+ if (props.enableSwapDeposit && !swapChainInfoRes) {
3344
3452
  return;
3345
3453
  }
3346
3454
  let testChainsList = [];
3347
3455
  let mainnetChainsList = [];
3348
3456
  try {
3349
- testChainsList = testChainInfos;
3350
- mainnetChainsList = mainnetChainInfos;
3457
+ if (hasStoreData) {
3458
+ testChainsList = testChainInfosFromStore;
3459
+ mainnetChainsList = mainnetChainInfosFromStore;
3460
+ } else {
3461
+ testChainsList = testChainInfos || testnetChainFallback;
3462
+ mainnetChainsList = mainnetChainInfos || [];
3463
+ }
3351
3464
  const testChains = processChainInfo(testChainsList);
3352
3465
  const mainnetChains2 = processChainInfo(mainnetChainsList);
3353
3466
  const swapChains = processChainInfo(
3354
- formatSwapChainInfo(swapChainInfoRes?.data || {})
3467
+ formatSwapChainInfo(swapChainInfoRes || {})
3355
3468
  );
3356
3469
  const chains = [...testChains, ...mainnetChains2];
3357
3470
  const filterSwapChains = swapChains.filter(
@@ -3369,8 +3482,11 @@ function WalletConnectorPrivyProvider(props) {
3369
3482
  props.customChains,
3370
3483
  mainnetChainInfos,
3371
3484
  testChainInfos,
3485
+ mainnetChainInfosFromStore,
3486
+ testChainInfosFromStore,
3372
3487
  swapChainInfoRes,
3373
- swapLoading
3488
+ props.enableSwapDeposit
3489
+ // swapLoading,
3374
3490
  ]);
3375
3491
  React19.useEffect(() => {
3376
3492
  if (props.customChains) {