@b3dotfun/sdk 0.0.3 → 0.0.4-alpha.1

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 (58) hide show
  1. package/dist/cjs/anyspend/index.js +1 -0
  2. package/dist/cjs/anyspend/react/components/index.d.ts +6 -5
  3. package/dist/cjs/anyspend/react/components/index.js +13 -11
  4. package/dist/cjs/anyspend/react/components/webview/WebviewOnrampPayment.d.ts +11 -0
  5. package/dist/cjs/anyspend/react/components/webview/WebviewOnrampPayment.js +93 -0
  6. package/dist/cjs/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +10 -0
  7. package/dist/cjs/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +10 -0
  8. package/dist/cjs/anyspend/services/anyspend.d.ts +5 -0
  9. package/dist/cjs/anyspend/types/order.d.ts +18 -0
  10. package/dist/cjs/anyspend/types/order.js +1 -0
  11. package/dist/cjs/anyspend/types/req-res/createOrder.d.ts +25 -0
  12. package/dist/cjs/anyspend/types/req-res/getOrderAndTransactions.d.ts +35 -0
  13. package/dist/cjs/anyspend/types/req-res/getOrderHistory.d.ts +25 -0
  14. package/dist/cjs/global-account/react/hooks/useTokenFromUrl.d.ts +1 -1
  15. package/dist/cjs/global-account/react/hooks/useTokenFromUrl.js +51 -13
  16. package/dist/cjs/shared/constants/chains/supported.d.ts +14 -4
  17. package/dist/cjs/shared/constants/chains/supported.js +11 -8
  18. package/dist/cjs/shared/generated/coingecko-chains.json +1072 -0
  19. package/dist/esm/anyspend/index.js +1 -0
  20. package/dist/esm/anyspend/react/components/index.d.ts +6 -5
  21. package/dist/esm/anyspend/react/components/index.js +6 -5
  22. package/dist/esm/anyspend/react/components/webview/WebviewOnrampPayment.d.ts +11 -0
  23. package/dist/esm/anyspend/react/components/webview/WebviewOnrampPayment.js +87 -0
  24. package/dist/esm/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +10 -0
  25. package/dist/esm/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +10 -0
  26. package/dist/esm/anyspend/services/anyspend.d.ts +5 -0
  27. package/dist/esm/anyspend/types/order.d.ts +18 -0
  28. package/dist/esm/anyspend/types/order.js +1 -0
  29. package/dist/esm/anyspend/types/req-res/createOrder.d.ts +25 -0
  30. package/dist/esm/anyspend/types/req-res/getOrderAndTransactions.d.ts +35 -0
  31. package/dist/esm/anyspend/types/req-res/getOrderHistory.d.ts +25 -0
  32. package/dist/esm/global-account/react/hooks/useTokenFromUrl.d.ts +1 -1
  33. package/dist/esm/global-account/react/hooks/useTokenFromUrl.js +51 -13
  34. package/dist/esm/shared/constants/chains/supported.d.ts +14 -4
  35. package/dist/esm/shared/constants/chains/supported.js +9 -7
  36. package/dist/esm/shared/generated/coingecko-chains.json +1072 -0
  37. package/dist/types/anyspend/react/components/index.d.ts +6 -5
  38. package/dist/types/anyspend/react/components/webview/WebviewOnrampPayment.d.ts +11 -0
  39. package/dist/types/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +10 -0
  40. package/dist/types/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +10 -0
  41. package/dist/types/anyspend/services/anyspend.d.ts +5 -0
  42. package/dist/types/anyspend/types/order.d.ts +18 -0
  43. package/dist/types/anyspend/types/req-res/createOrder.d.ts +25 -0
  44. package/dist/types/anyspend/types/req-res/getOrderAndTransactions.d.ts +35 -0
  45. package/dist/types/anyspend/types/req-res/getOrderHistory.d.ts +25 -0
  46. package/dist/types/global-account/react/hooks/useTokenFromUrl.d.ts +1 -1
  47. package/dist/types/shared/constants/chains/supported.d.ts +14 -4
  48. package/package.json +3 -3
  49. package/src/anyspend/index.ts +2 -0
  50. package/src/anyspend/react/components/index.ts +6 -5
  51. package/src/anyspend/react/components/webview/WebviewOnrampPayment.tsx +207 -0
  52. package/src/anyspend/types/order.ts +1 -0
  53. package/src/global-account/react/hooks/useTokenFromUrl.tsx +72 -14
  54. package/src/shared/constants/chains/supported.ts +23 -12
  55. package/src/shared/generated/coingecko-chains.json +1072 -0
  56. /package/dist/cjs/{generated → shared/generated}/chain-networks.json +0 -0
  57. /package/dist/esm/{generated → shared/generated}/chain-networks.json +0 -0
  58. /package/src/{generated → shared/generated}/chain-networks.json +0 -0
@@ -1,27 +1,65 @@
1
1
  "use client";
2
+ import { getCoingeckoChainInfo } from "../../../shared/constants/chains/supported";
3
+ import { useQuery } from "@tanstack/react-query";
2
4
  import { useSearchParams } from "next/navigation";
5
+ async function fetchTokenInfo(network, address) {
6
+ const response = await fetch("https://api.b3.fun/tokens", {
7
+ method: "POST",
8
+ headers: {
9
+ "Content-Type": "application/json",
10
+ "X-Service-Method": "getCoinGeckoTokenInfo"
11
+ },
12
+ body: JSON.stringify({
13
+ network,
14
+ address
15
+ })
16
+ });
17
+ if (!response.ok) {
18
+ throw new Error("Failed to fetch token info");
19
+ }
20
+ return response.json();
21
+ }
3
22
  /**
4
- * Hook to parse token data from URL parameters.
23
+ * Hook to parse token data from URL parameters and fetch additional token info.
5
24
  * Looks for parameters: [prefix]Currency
6
25
  */
7
26
  export function useTokenFromUrl({ defaultToken, prefix }) {
8
27
  const searchParams = useSearchParams();
9
- if (!searchParams) {
10
- return defaultToken;
11
- }
12
28
  // Get parameters from URL
13
- const currencyParam = searchParams.get(`${prefix}Currency`);
14
- const chainIdParam = searchParams.get(`${prefix}ChainId`);
15
- if (!currencyParam || !chainIdParam) {
29
+ const currencyParam = searchParams?.get(`${prefix}Currency`);
30
+ const chainIdParam = searchParams?.get(`${prefix}ChainId`);
31
+ // Determine if we should fetch token info
32
+ const shouldFetchToken = Boolean(currencyParam && chainIdParam && currencyParam.toLowerCase() !== defaultToken.address.toLowerCase());
33
+ // Determine network based on chainId
34
+ const network = chainIdParam ? getCoingeckoChainInfo(Number(chainIdParam)).coingecko_id : "";
35
+ const { data: tokenInfo, isError } = useQuery({
36
+ queryKey: ["tokenInfo", network, currencyParam],
37
+ queryFn: () => fetchTokenInfo(network, currencyParam),
38
+ enabled: shouldFetchToken,
39
+ staleTime: Infinity,
40
+ gcTime: Infinity
41
+ });
42
+ // Return default token if no params or same as default
43
+ if (!shouldFetchToken) {
16
44
  return defaultToken;
17
45
  }
18
- // If the currency is the same as the default token, return that
19
- if (currencyParam.toLowerCase() === defaultToken.address.toLowerCase()) {
20
- return defaultToken;
46
+ // Return basic token info if API call fails or while loading
47
+ if (isError || !tokenInfo) {
48
+ return {
49
+ ...defaultToken,
50
+ address: currencyParam,
51
+ chainId: Number(chainIdParam)
52
+ };
21
53
  }
54
+ // Return enhanced token with API data
22
55
  return {
23
- ...defaultToken,
24
- address: currencyParam,
25
- chainId: Number(chainIdParam)
56
+ address: tokenInfo.data.attributes.address,
57
+ chainId: Number(chainIdParam),
58
+ name: tokenInfo.data.attributes.name,
59
+ symbol: tokenInfo.data.attributes.symbol,
60
+ decimals: tokenInfo.data.attributes.decimals,
61
+ metadata: {
62
+ logoURI: tokenInfo.data.attributes.image_url
63
+ }
26
64
  };
27
65
  }
@@ -43,12 +43,22 @@ export declare const supportedChainNetworks: {
43
43
  };
44
44
  _id: string | {};
45
45
  }[];
46
- export declare const b3Mainnet: import("viem").Chain;
47
- export declare const b3Testnet: import("viem").Chain;
46
+ export declare const coingeckoChains: Record<number, {
47
+ coingecko_id: string;
48
+ name: string;
49
+ native_coin_id: string;
50
+ }>;
51
+ export declare function getCoingeckoChainInfo(chainId: number): {
52
+ coingecko_id: string;
53
+ name: string;
54
+ native_coin_id: string;
55
+ };
56
+ export declare const b3Mainnet: import("viem").Chain | undefined;
57
+ export declare const b3Testnet: import("viem").Chain | undefined;
48
58
  export declare const baseMainnet: import("viem").Chain | undefined;
49
59
  export declare const b3MainnetThirdWeb: Readonly<import("thirdweb/dist/types/chains/types").ChainOptions & {
50
60
  rpc: string;
51
- }>;
61
+ }> | undefined;
52
62
  export declare const b3TestnetThirdWeb: Readonly<import("thirdweb/dist/types/chains/types").ChainOptions & {
53
63
  rpc: string;
54
- }>;
64
+ }> | undefined;
@@ -1,8 +1,9 @@
1
1
  import { toThirdwebChain, toViemChain } from "../../../shared/utils/chain-transformers";
2
2
  // Import the JSON directly
3
3
  // @ts-ignore
4
- import chainNetworksJSON from "../../../generated/chain-networks.json" with { type: "json" };
5
- import invariant from "invariant";
4
+ import chainNetworksJSON from "../../generated/chain-networks.json" with { type: "json" };
5
+ // @ts-ignore
6
+ import coingeckoChainsJSON from "../../generated/coingecko-chains.json" with { type: "json" };
6
7
  const chainNetworks = chainNetworksJSON;
7
8
  // Convert custom chains to Viem format
8
9
  const viemChains = chainNetworks.map(toViemChain);
@@ -20,13 +21,14 @@ export const supportedChainsTW = [
20
21
  ];
21
22
  // Original format from chain-networks.json
22
23
  export const supportedChainNetworks = chainNetworks;
24
+ // CoinGecko chain mapping
25
+ export const coingeckoChains = coingeckoChainsJSON;
26
+ // Helper function to get CoinGecko chain info
27
+ export function getCoingeckoChainInfo(chainId) {
28
+ return coingeckoChains[chainId];
29
+ }
23
30
  export const b3Mainnet = supportedChains.find(chain => chain.id === 8333);
24
- invariant(b3Mainnet, "B3 mainnet chain not found in supported chains");
25
31
  export const b3Testnet = supportedChains.find(chain => chain.id === 1993);
26
- invariant(b3Testnet, "B3 testnet chain not found in supported chains");
27
32
  export const baseMainnet = supportedChains.find(chain => chain.id === 8453);
28
- invariant(baseMainnet, "Base mainnet chain not found in supported chains");
29
33
  export const b3MainnetThirdWeb = supportedChainsTW.find(chain => chain.id === 8333);
30
- invariant(b3MainnetThirdWeb, "B3 mainnet chain not found in supported chains TW");
31
34
  export const b3TestnetThirdWeb = supportedChainsTW.find(chain => chain.id === 1993);
32
- invariant(b3TestnetThirdWeb, "B3 testnet chain not found in supported chains TW");