@zubari/sdk 0.5.7 → 0.5.9

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.
@@ -1466,7 +1466,10 @@ var WalletManager = class _WalletManager {
1466
1466
  storage: config.storage || createSecureStorage(),
1467
1467
  enabledChains: config.enabledChains || SUPPORTED_CHAINS,
1468
1468
  apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || "https://ckgwifsxka.us-east-2.awsapprunner.com",
1469
- accessToken: config.accessToken
1469
+ accessToken: config.accessToken,
1470
+ chainRpcUrls: config.chainRpcUrls || {},
1471
+ tronApiKey: config.tronApiKey,
1472
+ tonApiKey: config.tonApiKey
1470
1473
  };
1471
1474
  this.storage = this.config.storage;
1472
1475
  this.wdkService = getZubariWdkService({
@@ -2028,7 +2031,7 @@ var WalletManager = class _WalletManager {
2028
2031
  }
2029
2032
  }
2030
2033
  } else if (chain === "solana") {
2031
- const rpcUrl = this.config.network === "mainnet" ? "https://api.mainnet-beta.solana.com" : "https://api.devnet.solana.com";
2034
+ const rpcUrl = this.config.chainRpcUrls.solana || (this.config.network === "mainnet" ? "https://api.mainnet-beta.solana.com" : "https://api.devnet.solana.com");
2032
2035
  try {
2033
2036
  const response = await fetch(rpcUrl, {
2034
2037
  method: "POST",
@@ -2081,12 +2084,40 @@ var WalletManager = class _WalletManager {
2081
2084
  console.warn("Failed to fetch Solana USDT balance:", error);
2082
2085
  }
2083
2086
  }
2087
+ if (balance === "0" && this.config.apiUrl && this.config.accessToken) {
2088
+ try {
2089
+ const fallbackResponse = await fetch(`${this.config.apiUrl}/api/wallets/wdk/balance`, {
2090
+ method: "POST",
2091
+ headers: {
2092
+ "Content-Type": "application/json",
2093
+ "Authorization": `Bearer ${this.config.accessToken}`
2094
+ },
2095
+ body: JSON.stringify({
2096
+ chain: "solana",
2097
+ address,
2098
+ network: this.config.network
2099
+ })
2100
+ });
2101
+ if (fallbackResponse.ok) {
2102
+ const fallbackData = await fallbackResponse.json();
2103
+ if (fallbackData.success && fallbackData.balance && fallbackData.balance !== "0") {
2104
+ balance = fallbackData.balance;
2105
+ }
2106
+ }
2107
+ } catch (fallbackError) {
2108
+ console.warn("Solana backend fallback failed:", fallbackError);
2109
+ }
2110
+ }
2084
2111
  } else if (chain === "tron") {
2085
2112
  const tronConfig = getNetworkConfig("tron", this.config.network !== "mainnet");
2086
2113
  const baseUrl = tronConfig.rpcUrl;
2087
2114
  try {
2115
+ const tronHeaders = { "Accept": "application/json" };
2116
+ if (this.config.tronApiKey) {
2117
+ tronHeaders["TRON-PRO-API-KEY"] = this.config.tronApiKey;
2118
+ }
2088
2119
  const response = await fetch(`${baseUrl}/v1/accounts/${address}`, {
2089
- headers: { "Accept": "application/json" }
2120
+ headers: tronHeaders
2090
2121
  });
2091
2122
  if (response.ok) {
2092
2123
  const data = await response.json();
@@ -2116,8 +2147,12 @@ var WalletManager = class _WalletManager {
2116
2147
  const isTestnet = this.config.network !== "mainnet";
2117
2148
  const baseUrl = isTestnet ? "https://testnet.toncenter.com/api/v2" : "https://toncenter.com/api/v2";
2118
2149
  try {
2150
+ const tonHeaders = { "Accept": "application/json" };
2151
+ if (this.config.tonApiKey) {
2152
+ tonHeaders["X-API-Key"] = this.config.tonApiKey;
2153
+ }
2119
2154
  const response = await fetch(`${baseUrl}/getAddressBalance?address=${address}`, {
2120
- headers: { "Accept": "application/json" }
2155
+ headers: tonHeaders
2121
2156
  });
2122
2157
  if (response.ok) {
2123
2158
  const data = await response.json();
@@ -2167,9 +2202,13 @@ var WalletManager = class _WalletManager {
2167
2202
  }
2168
2203
  } else if (chain === "spark") {
2169
2204
  try {
2205
+ const sparkHeaders = { "Content-Type": "application/json" };
2206
+ if (this.config.accessToken) {
2207
+ sparkHeaders["Authorization"] = `Bearer ${this.config.accessToken}`;
2208
+ }
2170
2209
  const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/balance`, {
2171
2210
  method: "POST",
2172
- headers: { "Content-Type": "application/json" },
2211
+ headers: sparkHeaders,
2173
2212
  body: JSON.stringify({
2174
2213
  chain: "spark",
2175
2214
  address,
@@ -2212,7 +2251,7 @@ var WalletManager = class _WalletManager {
2212
2251
  if (result.status === "fulfilled") {
2213
2252
  return result.value;
2214
2253
  }
2215
- console.error(`Failed to fetch balance for ${chain}:`, result.reason);
2254
+ console.warn(`Failed to fetch balance for ${chain}:`, result.reason);
2216
2255
  const networkConfig = this.getChainConfig(chain);
2217
2256
  return {
2218
2257
  chain,