@glowlabs-org/utils 0.2.61 → 0.2.63
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/dist/cjs/browser.d.ts +1 -0
- package/dist/cjs/browser.js +20 -19
- package/dist/cjs/browser.js.map +1 -1
- package/dist/cjs/index.js +35 -77
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/control-api/wallets-router.d.ts +3 -0
- package/dist/cjs/lib/types/index.d.ts +1 -1
- package/dist/cjs/{kickstarter-router-CZaSq6Pl.js → wallets-router-CGxiEOFF.js} +102 -32
- package/dist/cjs/wallets-router-CGxiEOFF.js.map +1 -0
- package/dist/esm/browser.d.ts +1 -0
- package/dist/esm/browser.js +1 -1
- package/dist/esm/index.js +3 -45
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/control-api/wallets-router.d.ts +3 -0
- package/dist/esm/lib/types/index.d.ts +1 -1
- package/dist/esm/{kickstarter-router-D8tZPVSu.js → wallets-router-KYbgrMuV.js} +102 -33
- package/dist/esm/wallets-router-KYbgrMuV.js.map +1 -0
- package/package.json +1 -1
- package/src/browser.ts +1 -0
- package/src/lib/control-api/wallets-router.ts +45 -0
- package/src/lib/types/index.ts +1 -1
- package/dist/cjs/kickstarter-router-CZaSq6Pl.js.map +0 -1
- package/dist/esm/kickstarter-router-D8tZPVSu.js.map +0 -1
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { ControlWallet, WalletDetails } from "../types";
|
|
2
|
+
import type { MintedEvent, StakedEvent } from "../types";
|
|
2
3
|
export declare function WalletsRouter(baseUrl: string): {
|
|
3
4
|
readonly fetchAllWallets: () => Promise<ControlWallet[]>;
|
|
4
5
|
readonly fetchWalletByAddress: (wallet: string) => Promise<WalletDetails>;
|
|
6
|
+
readonly fetchWalletMintedEvents: (wallet: string, page?: number, limit?: number) => Promise<MintedEvent[]>;
|
|
7
|
+
readonly fetchWalletStakeEvents: (wallet: string, page?: number, limit?: number, regionId?: number) => Promise<StakedEvent[]>;
|
|
5
8
|
};
|
|
@@ -712,7 +712,7 @@ function useForwarder(signer, CHAIN_ID) {
|
|
|
712
712
|
/**
|
|
713
713
|
* Extract a useful error message from an unknown error value.
|
|
714
714
|
*/
|
|
715
|
-
function parseApiError$
|
|
715
|
+
function parseApiError$3(error) {
|
|
716
716
|
if (!error)
|
|
717
717
|
return "Unknown error";
|
|
718
718
|
if (error instanceof Error)
|
|
@@ -740,7 +740,7 @@ function ControlRouter(baseUrl) {
|
|
|
740
740
|
return (data?.gctl_balance ?? "0").toString();
|
|
741
741
|
}
|
|
742
742
|
catch (error) {
|
|
743
|
-
throw new Error(parseApiError$
|
|
743
|
+
throw new Error(parseApiError$3(error));
|
|
744
744
|
}
|
|
745
745
|
};
|
|
746
746
|
const fetchGctlPrice = async () => {
|
|
@@ -749,7 +749,7 @@ function ControlRouter(baseUrl) {
|
|
|
749
749
|
return data.currentPriceUsdc;
|
|
750
750
|
}
|
|
751
751
|
catch (error) {
|
|
752
|
-
throw new Error(parseApiError$
|
|
752
|
+
throw new Error(parseApiError$3(error));
|
|
753
753
|
}
|
|
754
754
|
};
|
|
755
755
|
const fetchGlwPrice = async () => {
|
|
@@ -758,7 +758,7 @@ function ControlRouter(baseUrl) {
|
|
|
758
758
|
return data.currentPriceUsdc;
|
|
759
759
|
}
|
|
760
760
|
catch (error) {
|
|
761
|
-
throw new Error(parseApiError$
|
|
761
|
+
throw new Error(parseApiError$3(error));
|
|
762
762
|
}
|
|
763
763
|
};
|
|
764
764
|
const fetchLastNonce = async (wallet) => {
|
|
@@ -767,7 +767,7 @@ function ControlRouter(baseUrl) {
|
|
|
767
767
|
return data.lastNonce;
|
|
768
768
|
}
|
|
769
769
|
catch (error) {
|
|
770
|
-
throw new Error(parseApiError$
|
|
770
|
+
throw new Error(parseApiError$3(error));
|
|
771
771
|
}
|
|
772
772
|
};
|
|
773
773
|
const fetchCirculatingSupply = async () => {
|
|
@@ -776,7 +776,7 @@ function ControlRouter(baseUrl) {
|
|
|
776
776
|
return data.circulatingSupply;
|
|
777
777
|
}
|
|
778
778
|
catch (error) {
|
|
779
|
-
throw new Error(parseApiError$
|
|
779
|
+
throw new Error(parseApiError$3(error));
|
|
780
780
|
}
|
|
781
781
|
};
|
|
782
782
|
// Build pagination query helper
|
|
@@ -791,7 +791,7 @@ function ControlRouter(baseUrl) {
|
|
|
791
791
|
return data.events ?? [];
|
|
792
792
|
}
|
|
793
793
|
catch (error) {
|
|
794
|
-
throw new Error(parseApiError$
|
|
794
|
+
throw new Error(parseApiError$3(error));
|
|
795
795
|
}
|
|
796
796
|
};
|
|
797
797
|
const fetchStakeEvents = async (page, limit, regionId) => {
|
|
@@ -802,7 +802,7 @@ function ControlRouter(baseUrl) {
|
|
|
802
802
|
return data.events ?? [];
|
|
803
803
|
}
|
|
804
804
|
catch (error) {
|
|
805
|
-
throw new Error(parseApiError$
|
|
805
|
+
throw new Error(parseApiError$3(error));
|
|
806
806
|
}
|
|
807
807
|
};
|
|
808
808
|
const fetchPendingTransfers = async (page, limit) => {
|
|
@@ -811,7 +811,7 @@ function ControlRouter(baseUrl) {
|
|
|
811
811
|
return data.transfers ?? [];
|
|
812
812
|
}
|
|
813
813
|
catch (error) {
|
|
814
|
-
throw new Error(parseApiError$
|
|
814
|
+
throw new Error(parseApiError$3(error));
|
|
815
815
|
}
|
|
816
816
|
};
|
|
817
817
|
const fetchTransferDetails = async (txId) => {
|
|
@@ -819,7 +819,7 @@ function ControlRouter(baseUrl) {
|
|
|
819
819
|
return await request(`/transfer/${txId}`);
|
|
820
820
|
}
|
|
821
821
|
catch (error) {
|
|
822
|
-
throw new Error(parseApiError$
|
|
822
|
+
throw new Error(parseApiError$3(error));
|
|
823
823
|
}
|
|
824
824
|
};
|
|
825
825
|
const fetchFailedOperations = async (page, limit) => {
|
|
@@ -828,7 +828,7 @@ function ControlRouter(baseUrl) {
|
|
|
828
828
|
return data.operations ?? [];
|
|
829
829
|
}
|
|
830
830
|
catch (error) {
|
|
831
|
-
throw new Error(parseApiError$
|
|
831
|
+
throw new Error(parseApiError$3(error));
|
|
832
832
|
}
|
|
833
833
|
};
|
|
834
834
|
// Exposed query with error parsing
|
|
@@ -837,7 +837,7 @@ function ControlRouter(baseUrl) {
|
|
|
837
837
|
return await fetchTransferDetails(txId);
|
|
838
838
|
}
|
|
839
839
|
catch (error) {
|
|
840
|
-
throw new Error(parseApiError$
|
|
840
|
+
throw new Error(parseApiError$3(error));
|
|
841
841
|
}
|
|
842
842
|
};
|
|
843
843
|
const fetchRegionStake = async (regionId) => {
|
|
@@ -845,7 +845,7 @@ function ControlRouter(baseUrl) {
|
|
|
845
845
|
return await request(`/region/${regionId}/stake`);
|
|
846
846
|
}
|
|
847
847
|
catch (error) {
|
|
848
|
-
throw new Error(parseApiError$
|
|
848
|
+
throw new Error(parseApiError$3(error));
|
|
849
849
|
}
|
|
850
850
|
};
|
|
851
851
|
const fetchWalletRegionStake = async (wallet, regionId) => {
|
|
@@ -853,7 +853,7 @@ function ControlRouter(baseUrl) {
|
|
|
853
853
|
return await request(`/wallet/${wallet}/region/${regionId}/stake`);
|
|
854
854
|
}
|
|
855
855
|
catch (error) {
|
|
856
|
-
throw new Error(parseApiError$
|
|
856
|
+
throw new Error(parseApiError$3(error));
|
|
857
857
|
}
|
|
858
858
|
};
|
|
859
859
|
const fetchWalletRegionUnlocked = async (wallet, regionId) => {
|
|
@@ -861,7 +861,7 @@ function ControlRouter(baseUrl) {
|
|
|
861
861
|
return await request(`/wallet/${wallet}/region/${regionId}/unlocked`);
|
|
862
862
|
}
|
|
863
863
|
catch (error) {
|
|
864
|
-
throw new Error(parseApiError$
|
|
864
|
+
throw new Error(parseApiError$3(error));
|
|
865
865
|
}
|
|
866
866
|
};
|
|
867
867
|
// ----------------------- Mutations ---------------------------------------
|
|
@@ -879,7 +879,7 @@ function ControlRouter(baseUrl) {
|
|
|
879
879
|
return true;
|
|
880
880
|
}
|
|
881
881
|
catch (error) {
|
|
882
|
-
throw new Error(parseApiError$
|
|
882
|
+
throw new Error(parseApiError$3(error));
|
|
883
883
|
}
|
|
884
884
|
finally {
|
|
885
885
|
isStaking = false;
|
|
@@ -896,7 +896,7 @@ function ControlRouter(baseUrl) {
|
|
|
896
896
|
return true;
|
|
897
897
|
}
|
|
898
898
|
catch (error) {
|
|
899
|
-
throw new Error(parseApiError$
|
|
899
|
+
throw new Error(parseApiError$3(error));
|
|
900
900
|
}
|
|
901
901
|
finally {
|
|
902
902
|
isUnstaking = false;
|
|
@@ -912,7 +912,7 @@ function ControlRouter(baseUrl) {
|
|
|
912
912
|
return true;
|
|
913
913
|
}
|
|
914
914
|
catch (error) {
|
|
915
|
-
throw new Error(parseApiError$
|
|
915
|
+
throw new Error(parseApiError$3(error));
|
|
916
916
|
}
|
|
917
917
|
finally {
|
|
918
918
|
isRetryingFailedOperation = false;
|
|
@@ -1634,7 +1634,7 @@ const countries = allRegions.filter((r) => !r.isUs);
|
|
|
1634
1634
|
// ---------------------------------------------------------------------------
|
|
1635
1635
|
// Helpers
|
|
1636
1636
|
// ---------------------------------------------------------------------------
|
|
1637
|
-
function parseApiError$
|
|
1637
|
+
function parseApiError$2(error) {
|
|
1638
1638
|
if (!error)
|
|
1639
1639
|
return "Unknown error";
|
|
1640
1640
|
if (error instanceof Error)
|
|
@@ -1676,7 +1676,7 @@ function RegionRouter(baseUrl) {
|
|
|
1676
1676
|
return cachedRegions;
|
|
1677
1677
|
}
|
|
1678
1678
|
catch (error) {
|
|
1679
|
-
throw new Error(parseApiError$
|
|
1679
|
+
throw new Error(parseApiError$2(error));
|
|
1680
1680
|
}
|
|
1681
1681
|
finally {
|
|
1682
1682
|
isLoading = false;
|
|
@@ -1687,7 +1687,7 @@ function RegionRouter(baseUrl) {
|
|
|
1687
1687
|
return await request(`/regions/activation-config?code=${regionCode}`);
|
|
1688
1688
|
}
|
|
1689
1689
|
catch (error) {
|
|
1690
|
-
throw new Error(parseApiError$
|
|
1690
|
+
throw new Error(parseApiError$2(error));
|
|
1691
1691
|
}
|
|
1692
1692
|
};
|
|
1693
1693
|
const fetchActivationEvents = async (regionId) => {
|
|
@@ -1697,7 +1697,7 @@ function RegionRouter(baseUrl) {
|
|
|
1697
1697
|
return data.events ?? [];
|
|
1698
1698
|
}
|
|
1699
1699
|
catch (error) {
|
|
1700
|
-
throw new Error(parseApiError$
|
|
1700
|
+
throw new Error(parseApiError$2(error));
|
|
1701
1701
|
}
|
|
1702
1702
|
};
|
|
1703
1703
|
const fetchRegionByIdOrSlug = async (idOrSlug) => {
|
|
@@ -1706,7 +1706,7 @@ function RegionRouter(baseUrl) {
|
|
|
1706
1706
|
return data.region;
|
|
1707
1707
|
}
|
|
1708
1708
|
catch (error) {
|
|
1709
|
-
throw new Error(parseApiError$
|
|
1709
|
+
throw new Error(parseApiError$2(error));
|
|
1710
1710
|
}
|
|
1711
1711
|
};
|
|
1712
1712
|
const fetchRegionSolarFarms = async (regionId) => {
|
|
@@ -1715,7 +1715,7 @@ function RegionRouter(baseUrl) {
|
|
|
1715
1715
|
return data.sponsoredFarms ?? [];
|
|
1716
1716
|
}
|
|
1717
1717
|
catch (error) {
|
|
1718
|
-
throw new Error(parseApiError$
|
|
1718
|
+
throw new Error(parseApiError$2(error));
|
|
1719
1719
|
}
|
|
1720
1720
|
};
|
|
1721
1721
|
// -------------------------------------------------------------------------
|
|
@@ -1733,7 +1733,7 @@ function RegionRouter(baseUrl) {
|
|
|
1733
1733
|
await fetchRegions();
|
|
1734
1734
|
}
|
|
1735
1735
|
catch (error) {
|
|
1736
|
-
throw new Error(parseApiError$
|
|
1736
|
+
throw new Error(parseApiError$2(error));
|
|
1737
1737
|
}
|
|
1738
1738
|
finally {
|
|
1739
1739
|
isCreatingRegion = false;
|
|
@@ -1801,7 +1801,7 @@ function RegionRouter(baseUrl) {
|
|
|
1801
1801
|
};
|
|
1802
1802
|
}
|
|
1803
1803
|
|
|
1804
|
-
function parseApiError(error) {
|
|
1804
|
+
function parseApiError$1(error) {
|
|
1805
1805
|
if (!error)
|
|
1806
1806
|
return "Unknown error";
|
|
1807
1807
|
if (error instanceof Error)
|
|
@@ -1827,7 +1827,7 @@ function KickstarterRouter(baseUrl) {
|
|
|
1827
1827
|
return data.kickstarters ?? [];
|
|
1828
1828
|
}
|
|
1829
1829
|
catch (error) {
|
|
1830
|
-
throw new Error(parseApiError(error));
|
|
1830
|
+
throw new Error(parseApiError$1(error));
|
|
1831
1831
|
}
|
|
1832
1832
|
};
|
|
1833
1833
|
const createKickstarter = async (payload) => {
|
|
@@ -1845,7 +1845,7 @@ function KickstarterRouter(baseUrl) {
|
|
|
1845
1845
|
return data;
|
|
1846
1846
|
}
|
|
1847
1847
|
catch (error) {
|
|
1848
|
-
throw new Error(parseApiError(error));
|
|
1848
|
+
throw new Error(parseApiError$1(error));
|
|
1849
1849
|
}
|
|
1850
1850
|
finally {
|
|
1851
1851
|
isCreatingKickstarter = false;
|
|
@@ -1857,7 +1857,7 @@ function KickstarterRouter(baseUrl) {
|
|
|
1857
1857
|
return data.kickstarter;
|
|
1858
1858
|
}
|
|
1859
1859
|
catch (error) {
|
|
1860
|
-
throw new Error(parseApiError(error));
|
|
1860
|
+
throw new Error(parseApiError$1(error));
|
|
1861
1861
|
}
|
|
1862
1862
|
};
|
|
1863
1863
|
const fetchKickstartersByWallet = async (wallet) => {
|
|
@@ -1866,7 +1866,7 @@ function KickstarterRouter(baseUrl) {
|
|
|
1866
1866
|
return data.kickstarters ?? [];
|
|
1867
1867
|
}
|
|
1868
1868
|
catch (error) {
|
|
1869
|
-
throw new Error(parseApiError(error));
|
|
1869
|
+
throw new Error(parseApiError$1(error));
|
|
1870
1870
|
}
|
|
1871
1871
|
};
|
|
1872
1872
|
const commitKickstarter = async (kickstarterId, payload) => {
|
|
@@ -1879,7 +1879,7 @@ function KickstarterRouter(baseUrl) {
|
|
|
1879
1879
|
return data;
|
|
1880
1880
|
}
|
|
1881
1881
|
catch (error) {
|
|
1882
|
-
throw new Error(parseApiError(error));
|
|
1882
|
+
throw new Error(parseApiError$1(error));
|
|
1883
1883
|
}
|
|
1884
1884
|
};
|
|
1885
1885
|
return {
|
|
@@ -1894,5 +1894,74 @@ function KickstarterRouter(baseUrl) {
|
|
|
1894
1894
|
};
|
|
1895
1895
|
}
|
|
1896
1896
|
|
|
1897
|
-
|
|
1898
|
-
|
|
1897
|
+
function parseApiError(error) {
|
|
1898
|
+
if (!error)
|
|
1899
|
+
return "Unknown error";
|
|
1900
|
+
if (error instanceof Error)
|
|
1901
|
+
return error.message;
|
|
1902
|
+
const possible = error;
|
|
1903
|
+
return possible?.error?.message ?? possible?.message ?? "Unknown error";
|
|
1904
|
+
}
|
|
1905
|
+
function WalletsRouter(baseUrl) {
|
|
1906
|
+
if (!baseUrl)
|
|
1907
|
+
throw new Error("CONTROL API base URL is not set");
|
|
1908
|
+
const request = async (path, init) => {
|
|
1909
|
+
const res = await fetch(`${baseUrl}${path}`, init);
|
|
1910
|
+
if (!res.ok) {
|
|
1911
|
+
const errData = await res.json().catch(() => ({}));
|
|
1912
|
+
throw new Error(errData?.error || `Request to ${path} failed`);
|
|
1913
|
+
}
|
|
1914
|
+
return (await res.json());
|
|
1915
|
+
};
|
|
1916
|
+
const buildPaginationQuery = (page, limit) => {
|
|
1917
|
+
const p = page ?? 1;
|
|
1918
|
+
const l = limit ?? 50;
|
|
1919
|
+
return `?page=${p}&limit=${l}`;
|
|
1920
|
+
};
|
|
1921
|
+
const fetchAllWallets = async () => {
|
|
1922
|
+
try {
|
|
1923
|
+
const data = await request(`/wallets/all`);
|
|
1924
|
+
return data.wallets ?? [];
|
|
1925
|
+
}
|
|
1926
|
+
catch (error) {
|
|
1927
|
+
throw new Error(parseApiError(error));
|
|
1928
|
+
}
|
|
1929
|
+
};
|
|
1930
|
+
const fetchWalletByAddress = async (wallet) => {
|
|
1931
|
+
try {
|
|
1932
|
+
return await request(`/wallets/address/${encodeURIComponent(wallet)}`);
|
|
1933
|
+
}
|
|
1934
|
+
catch (error) {
|
|
1935
|
+
throw new Error(parseApiError(error));
|
|
1936
|
+
}
|
|
1937
|
+
};
|
|
1938
|
+
const fetchWalletMintedEvents = async (wallet, page, limit) => {
|
|
1939
|
+
try {
|
|
1940
|
+
const data = await request(`/wallets/address/${encodeURIComponent(wallet)}/events/minted${buildPaginationQuery(page, limit)}`);
|
|
1941
|
+
return data.events ?? [];
|
|
1942
|
+
}
|
|
1943
|
+
catch (error) {
|
|
1944
|
+
throw new Error(parseApiError(error));
|
|
1945
|
+
}
|
|
1946
|
+
};
|
|
1947
|
+
const fetchWalletStakeEvents = async (wallet, page, limit, regionId) => {
|
|
1948
|
+
try {
|
|
1949
|
+
const base = `/wallets/address/${encodeURIComponent(wallet)}/events/stake${buildPaginationQuery(page, limit)}`;
|
|
1950
|
+
const query = typeof regionId === "number" ? `${base}®ionId=${regionId}` : base;
|
|
1951
|
+
const data = await request(query);
|
|
1952
|
+
return data.events ?? [];
|
|
1953
|
+
}
|
|
1954
|
+
catch (error) {
|
|
1955
|
+
throw new Error(parseApiError(error));
|
|
1956
|
+
}
|
|
1957
|
+
};
|
|
1958
|
+
return {
|
|
1959
|
+
fetchAllWallets,
|
|
1960
|
+
fetchWalletByAddress,
|
|
1961
|
+
fetchWalletMintedEvents,
|
|
1962
|
+
fetchWalletStakeEvents,
|
|
1963
|
+
};
|
|
1964
|
+
}
|
|
1965
|
+
|
|
1966
|
+
export { ControlRouter as C, DECIMALS_BY_TOKEN as D, ForwarderError as F, GLOW_WEIGHT_DECIMAL_PRECISION as G, HUB_URL as H, KickstarterRouter as K, MAX_WEIGHT as M, RegionRouter as R, USDG_WEIGHT_DECIMAL_PRECISION as U, WalletsRouter as W, allRegions as a, usStates as b, countries as c, FORWARDER_ABI as d, GCA_URLS as e, getAddresses as g, regionMetadata as r, useForwarder as u };
|
|
1967
|
+
//# sourceMappingURL=wallets-router-KYbgrMuV.js.map
|