@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
|
};
|
|
@@ -714,7 +714,7 @@ function useForwarder(signer, CHAIN_ID) {
|
|
|
714
714
|
/**
|
|
715
715
|
* Extract a useful error message from an unknown error value.
|
|
716
716
|
*/
|
|
717
|
-
function parseApiError$
|
|
717
|
+
function parseApiError$3(error) {
|
|
718
718
|
if (!error)
|
|
719
719
|
return "Unknown error";
|
|
720
720
|
if (error instanceof Error)
|
|
@@ -742,7 +742,7 @@ function ControlRouter(baseUrl) {
|
|
|
742
742
|
return (data?.gctl_balance ?? "0").toString();
|
|
743
743
|
}
|
|
744
744
|
catch (error) {
|
|
745
|
-
throw new Error(parseApiError$
|
|
745
|
+
throw new Error(parseApiError$3(error));
|
|
746
746
|
}
|
|
747
747
|
};
|
|
748
748
|
const fetchGctlPrice = async () => {
|
|
@@ -751,7 +751,7 @@ function ControlRouter(baseUrl) {
|
|
|
751
751
|
return data.currentPriceUsdc;
|
|
752
752
|
}
|
|
753
753
|
catch (error) {
|
|
754
|
-
throw new Error(parseApiError$
|
|
754
|
+
throw new Error(parseApiError$3(error));
|
|
755
755
|
}
|
|
756
756
|
};
|
|
757
757
|
const fetchGlwPrice = async () => {
|
|
@@ -760,7 +760,7 @@ function ControlRouter(baseUrl) {
|
|
|
760
760
|
return data.currentPriceUsdc;
|
|
761
761
|
}
|
|
762
762
|
catch (error) {
|
|
763
|
-
throw new Error(parseApiError$
|
|
763
|
+
throw new Error(parseApiError$3(error));
|
|
764
764
|
}
|
|
765
765
|
};
|
|
766
766
|
const fetchLastNonce = async (wallet) => {
|
|
@@ -769,7 +769,7 @@ function ControlRouter(baseUrl) {
|
|
|
769
769
|
return data.lastNonce;
|
|
770
770
|
}
|
|
771
771
|
catch (error) {
|
|
772
|
-
throw new Error(parseApiError$
|
|
772
|
+
throw new Error(parseApiError$3(error));
|
|
773
773
|
}
|
|
774
774
|
};
|
|
775
775
|
const fetchCirculatingSupply = async () => {
|
|
@@ -778,7 +778,7 @@ function ControlRouter(baseUrl) {
|
|
|
778
778
|
return data.circulatingSupply;
|
|
779
779
|
}
|
|
780
780
|
catch (error) {
|
|
781
|
-
throw new Error(parseApiError$
|
|
781
|
+
throw new Error(parseApiError$3(error));
|
|
782
782
|
}
|
|
783
783
|
};
|
|
784
784
|
// Build pagination query helper
|
|
@@ -793,7 +793,7 @@ function ControlRouter(baseUrl) {
|
|
|
793
793
|
return data.events ?? [];
|
|
794
794
|
}
|
|
795
795
|
catch (error) {
|
|
796
|
-
throw new Error(parseApiError$
|
|
796
|
+
throw new Error(parseApiError$3(error));
|
|
797
797
|
}
|
|
798
798
|
};
|
|
799
799
|
const fetchStakeEvents = async (page, limit, regionId) => {
|
|
@@ -804,7 +804,7 @@ function ControlRouter(baseUrl) {
|
|
|
804
804
|
return data.events ?? [];
|
|
805
805
|
}
|
|
806
806
|
catch (error) {
|
|
807
|
-
throw new Error(parseApiError$
|
|
807
|
+
throw new Error(parseApiError$3(error));
|
|
808
808
|
}
|
|
809
809
|
};
|
|
810
810
|
const fetchPendingTransfers = async (page, limit) => {
|
|
@@ -813,7 +813,7 @@ function ControlRouter(baseUrl) {
|
|
|
813
813
|
return data.transfers ?? [];
|
|
814
814
|
}
|
|
815
815
|
catch (error) {
|
|
816
|
-
throw new Error(parseApiError$
|
|
816
|
+
throw new Error(parseApiError$3(error));
|
|
817
817
|
}
|
|
818
818
|
};
|
|
819
819
|
const fetchTransferDetails = async (txId) => {
|
|
@@ -821,7 +821,7 @@ function ControlRouter(baseUrl) {
|
|
|
821
821
|
return await request(`/transfer/${txId}`);
|
|
822
822
|
}
|
|
823
823
|
catch (error) {
|
|
824
|
-
throw new Error(parseApiError$
|
|
824
|
+
throw new Error(parseApiError$3(error));
|
|
825
825
|
}
|
|
826
826
|
};
|
|
827
827
|
const fetchFailedOperations = async (page, limit) => {
|
|
@@ -830,7 +830,7 @@ function ControlRouter(baseUrl) {
|
|
|
830
830
|
return data.operations ?? [];
|
|
831
831
|
}
|
|
832
832
|
catch (error) {
|
|
833
|
-
throw new Error(parseApiError$
|
|
833
|
+
throw new Error(parseApiError$3(error));
|
|
834
834
|
}
|
|
835
835
|
};
|
|
836
836
|
// Exposed query with error parsing
|
|
@@ -839,7 +839,7 @@ function ControlRouter(baseUrl) {
|
|
|
839
839
|
return await fetchTransferDetails(txId);
|
|
840
840
|
}
|
|
841
841
|
catch (error) {
|
|
842
|
-
throw new Error(parseApiError$
|
|
842
|
+
throw new Error(parseApiError$3(error));
|
|
843
843
|
}
|
|
844
844
|
};
|
|
845
845
|
const fetchRegionStake = async (regionId) => {
|
|
@@ -847,7 +847,7 @@ function ControlRouter(baseUrl) {
|
|
|
847
847
|
return await request(`/region/${regionId}/stake`);
|
|
848
848
|
}
|
|
849
849
|
catch (error) {
|
|
850
|
-
throw new Error(parseApiError$
|
|
850
|
+
throw new Error(parseApiError$3(error));
|
|
851
851
|
}
|
|
852
852
|
};
|
|
853
853
|
const fetchWalletRegionStake = async (wallet, regionId) => {
|
|
@@ -855,7 +855,7 @@ function ControlRouter(baseUrl) {
|
|
|
855
855
|
return await request(`/wallet/${wallet}/region/${regionId}/stake`);
|
|
856
856
|
}
|
|
857
857
|
catch (error) {
|
|
858
|
-
throw new Error(parseApiError$
|
|
858
|
+
throw new Error(parseApiError$3(error));
|
|
859
859
|
}
|
|
860
860
|
};
|
|
861
861
|
const fetchWalletRegionUnlocked = async (wallet, regionId) => {
|
|
@@ -863,7 +863,7 @@ function ControlRouter(baseUrl) {
|
|
|
863
863
|
return await request(`/wallet/${wallet}/region/${regionId}/unlocked`);
|
|
864
864
|
}
|
|
865
865
|
catch (error) {
|
|
866
|
-
throw new Error(parseApiError$
|
|
866
|
+
throw new Error(parseApiError$3(error));
|
|
867
867
|
}
|
|
868
868
|
};
|
|
869
869
|
// ----------------------- Mutations ---------------------------------------
|
|
@@ -881,7 +881,7 @@ function ControlRouter(baseUrl) {
|
|
|
881
881
|
return true;
|
|
882
882
|
}
|
|
883
883
|
catch (error) {
|
|
884
|
-
throw new Error(parseApiError$
|
|
884
|
+
throw new Error(parseApiError$3(error));
|
|
885
885
|
}
|
|
886
886
|
finally {
|
|
887
887
|
isStaking = false;
|
|
@@ -898,7 +898,7 @@ function ControlRouter(baseUrl) {
|
|
|
898
898
|
return true;
|
|
899
899
|
}
|
|
900
900
|
catch (error) {
|
|
901
|
-
throw new Error(parseApiError$
|
|
901
|
+
throw new Error(parseApiError$3(error));
|
|
902
902
|
}
|
|
903
903
|
finally {
|
|
904
904
|
isUnstaking = false;
|
|
@@ -914,7 +914,7 @@ function ControlRouter(baseUrl) {
|
|
|
914
914
|
return true;
|
|
915
915
|
}
|
|
916
916
|
catch (error) {
|
|
917
|
-
throw new Error(parseApiError$
|
|
917
|
+
throw new Error(parseApiError$3(error));
|
|
918
918
|
}
|
|
919
919
|
finally {
|
|
920
920
|
isRetryingFailedOperation = false;
|
|
@@ -1636,7 +1636,7 @@ const countries = allRegions.filter((r) => !r.isUs);
|
|
|
1636
1636
|
// ---------------------------------------------------------------------------
|
|
1637
1637
|
// Helpers
|
|
1638
1638
|
// ---------------------------------------------------------------------------
|
|
1639
|
-
function parseApiError$
|
|
1639
|
+
function parseApiError$2(error) {
|
|
1640
1640
|
if (!error)
|
|
1641
1641
|
return "Unknown error";
|
|
1642
1642
|
if (error instanceof Error)
|
|
@@ -1678,7 +1678,7 @@ function RegionRouter(baseUrl) {
|
|
|
1678
1678
|
return cachedRegions;
|
|
1679
1679
|
}
|
|
1680
1680
|
catch (error) {
|
|
1681
|
-
throw new Error(parseApiError$
|
|
1681
|
+
throw new Error(parseApiError$2(error));
|
|
1682
1682
|
}
|
|
1683
1683
|
finally {
|
|
1684
1684
|
isLoading = false;
|
|
@@ -1689,7 +1689,7 @@ function RegionRouter(baseUrl) {
|
|
|
1689
1689
|
return await request(`/regions/activation-config?code=${regionCode}`);
|
|
1690
1690
|
}
|
|
1691
1691
|
catch (error) {
|
|
1692
|
-
throw new Error(parseApiError$
|
|
1692
|
+
throw new Error(parseApiError$2(error));
|
|
1693
1693
|
}
|
|
1694
1694
|
};
|
|
1695
1695
|
const fetchActivationEvents = async (regionId) => {
|
|
@@ -1699,7 +1699,7 @@ function RegionRouter(baseUrl) {
|
|
|
1699
1699
|
return data.events ?? [];
|
|
1700
1700
|
}
|
|
1701
1701
|
catch (error) {
|
|
1702
|
-
throw new Error(parseApiError$
|
|
1702
|
+
throw new Error(parseApiError$2(error));
|
|
1703
1703
|
}
|
|
1704
1704
|
};
|
|
1705
1705
|
const fetchRegionByIdOrSlug = async (idOrSlug) => {
|
|
@@ -1708,7 +1708,7 @@ function RegionRouter(baseUrl) {
|
|
|
1708
1708
|
return data.region;
|
|
1709
1709
|
}
|
|
1710
1710
|
catch (error) {
|
|
1711
|
-
throw new Error(parseApiError$
|
|
1711
|
+
throw new Error(parseApiError$2(error));
|
|
1712
1712
|
}
|
|
1713
1713
|
};
|
|
1714
1714
|
const fetchRegionSolarFarms = async (regionId) => {
|
|
@@ -1717,7 +1717,7 @@ function RegionRouter(baseUrl) {
|
|
|
1717
1717
|
return data.sponsoredFarms ?? [];
|
|
1718
1718
|
}
|
|
1719
1719
|
catch (error) {
|
|
1720
|
-
throw new Error(parseApiError$
|
|
1720
|
+
throw new Error(parseApiError$2(error));
|
|
1721
1721
|
}
|
|
1722
1722
|
};
|
|
1723
1723
|
// -------------------------------------------------------------------------
|
|
@@ -1735,7 +1735,7 @@ function RegionRouter(baseUrl) {
|
|
|
1735
1735
|
await fetchRegions();
|
|
1736
1736
|
}
|
|
1737
1737
|
catch (error) {
|
|
1738
|
-
throw new Error(parseApiError$
|
|
1738
|
+
throw new Error(parseApiError$2(error));
|
|
1739
1739
|
}
|
|
1740
1740
|
finally {
|
|
1741
1741
|
isCreatingRegion = false;
|
|
@@ -1803,7 +1803,7 @@ function RegionRouter(baseUrl) {
|
|
|
1803
1803
|
};
|
|
1804
1804
|
}
|
|
1805
1805
|
|
|
1806
|
-
function parseApiError(error) {
|
|
1806
|
+
function parseApiError$1(error) {
|
|
1807
1807
|
if (!error)
|
|
1808
1808
|
return "Unknown error";
|
|
1809
1809
|
if (error instanceof Error)
|
|
@@ -1829,7 +1829,7 @@ function KickstarterRouter(baseUrl) {
|
|
|
1829
1829
|
return data.kickstarters ?? [];
|
|
1830
1830
|
}
|
|
1831
1831
|
catch (error) {
|
|
1832
|
-
throw new Error(parseApiError(error));
|
|
1832
|
+
throw new Error(parseApiError$1(error));
|
|
1833
1833
|
}
|
|
1834
1834
|
};
|
|
1835
1835
|
const createKickstarter = async (payload) => {
|
|
@@ -1847,7 +1847,7 @@ function KickstarterRouter(baseUrl) {
|
|
|
1847
1847
|
return data;
|
|
1848
1848
|
}
|
|
1849
1849
|
catch (error) {
|
|
1850
|
-
throw new Error(parseApiError(error));
|
|
1850
|
+
throw new Error(parseApiError$1(error));
|
|
1851
1851
|
}
|
|
1852
1852
|
finally {
|
|
1853
1853
|
isCreatingKickstarter = false;
|
|
@@ -1859,7 +1859,7 @@ function KickstarterRouter(baseUrl) {
|
|
|
1859
1859
|
return data.kickstarter;
|
|
1860
1860
|
}
|
|
1861
1861
|
catch (error) {
|
|
1862
|
-
throw new Error(parseApiError(error));
|
|
1862
|
+
throw new Error(parseApiError$1(error));
|
|
1863
1863
|
}
|
|
1864
1864
|
};
|
|
1865
1865
|
const fetchKickstartersByWallet = async (wallet) => {
|
|
@@ -1868,7 +1868,7 @@ function KickstarterRouter(baseUrl) {
|
|
|
1868
1868
|
return data.kickstarters ?? [];
|
|
1869
1869
|
}
|
|
1870
1870
|
catch (error) {
|
|
1871
|
-
throw new Error(parseApiError(error));
|
|
1871
|
+
throw new Error(parseApiError$1(error));
|
|
1872
1872
|
}
|
|
1873
1873
|
};
|
|
1874
1874
|
const commitKickstarter = async (kickstarterId, payload) => {
|
|
@@ -1881,7 +1881,7 @@ function KickstarterRouter(baseUrl) {
|
|
|
1881
1881
|
return data;
|
|
1882
1882
|
}
|
|
1883
1883
|
catch (error) {
|
|
1884
|
-
throw new Error(parseApiError(error));
|
|
1884
|
+
throw new Error(parseApiError$1(error));
|
|
1885
1885
|
}
|
|
1886
1886
|
};
|
|
1887
1887
|
return {
|
|
@@ -1896,6 +1896,75 @@ function KickstarterRouter(baseUrl) {
|
|
|
1896
1896
|
};
|
|
1897
1897
|
}
|
|
1898
1898
|
|
|
1899
|
+
function parseApiError(error) {
|
|
1900
|
+
if (!error)
|
|
1901
|
+
return "Unknown error";
|
|
1902
|
+
if (error instanceof Error)
|
|
1903
|
+
return error.message;
|
|
1904
|
+
const possible = error;
|
|
1905
|
+
return possible?.error?.message ?? possible?.message ?? "Unknown error";
|
|
1906
|
+
}
|
|
1907
|
+
function WalletsRouter(baseUrl) {
|
|
1908
|
+
if (!baseUrl)
|
|
1909
|
+
throw new Error("CONTROL API base URL is not set");
|
|
1910
|
+
const request = async (path, init) => {
|
|
1911
|
+
const res = await fetch(`${baseUrl}${path}`, init);
|
|
1912
|
+
if (!res.ok) {
|
|
1913
|
+
const errData = await res.json().catch(() => ({}));
|
|
1914
|
+
throw new Error(errData?.error || `Request to ${path} failed`);
|
|
1915
|
+
}
|
|
1916
|
+
return (await res.json());
|
|
1917
|
+
};
|
|
1918
|
+
const buildPaginationQuery = (page, limit) => {
|
|
1919
|
+
const p = page ?? 1;
|
|
1920
|
+
const l = limit ?? 50;
|
|
1921
|
+
return `?page=${p}&limit=${l}`;
|
|
1922
|
+
};
|
|
1923
|
+
const fetchAllWallets = async () => {
|
|
1924
|
+
try {
|
|
1925
|
+
const data = await request(`/wallets/all`);
|
|
1926
|
+
return data.wallets ?? [];
|
|
1927
|
+
}
|
|
1928
|
+
catch (error) {
|
|
1929
|
+
throw new Error(parseApiError(error));
|
|
1930
|
+
}
|
|
1931
|
+
};
|
|
1932
|
+
const fetchWalletByAddress = async (wallet) => {
|
|
1933
|
+
try {
|
|
1934
|
+
return await request(`/wallets/address/${encodeURIComponent(wallet)}`);
|
|
1935
|
+
}
|
|
1936
|
+
catch (error) {
|
|
1937
|
+
throw new Error(parseApiError(error));
|
|
1938
|
+
}
|
|
1939
|
+
};
|
|
1940
|
+
const fetchWalletMintedEvents = async (wallet, page, limit) => {
|
|
1941
|
+
try {
|
|
1942
|
+
const data = await request(`/wallets/address/${encodeURIComponent(wallet)}/events/minted${buildPaginationQuery(page, limit)}`);
|
|
1943
|
+
return data.events ?? [];
|
|
1944
|
+
}
|
|
1945
|
+
catch (error) {
|
|
1946
|
+
throw new Error(parseApiError(error));
|
|
1947
|
+
}
|
|
1948
|
+
};
|
|
1949
|
+
const fetchWalletStakeEvents = async (wallet, page, limit, regionId) => {
|
|
1950
|
+
try {
|
|
1951
|
+
const base = `/wallets/address/${encodeURIComponent(wallet)}/events/stake${buildPaginationQuery(page, limit)}`;
|
|
1952
|
+
const query = typeof regionId === "number" ? `${base}®ionId=${regionId}` : base;
|
|
1953
|
+
const data = await request(query);
|
|
1954
|
+
return data.events ?? [];
|
|
1955
|
+
}
|
|
1956
|
+
catch (error) {
|
|
1957
|
+
throw new Error(parseApiError(error));
|
|
1958
|
+
}
|
|
1959
|
+
};
|
|
1960
|
+
return {
|
|
1961
|
+
fetchAllWallets,
|
|
1962
|
+
fetchWalletByAddress,
|
|
1963
|
+
fetchWalletMintedEvents,
|
|
1964
|
+
fetchWalletStakeEvents,
|
|
1965
|
+
};
|
|
1966
|
+
}
|
|
1967
|
+
|
|
1899
1968
|
exports.ControlRouter = ControlRouter;
|
|
1900
1969
|
exports.DECIMALS_BY_TOKEN = DECIMALS_BY_TOKEN;
|
|
1901
1970
|
exports.FORWARDER_ABI = FORWARDER_ABI;
|
|
@@ -1906,10 +1975,11 @@ exports.KickstarterRouter = KickstarterRouter;
|
|
|
1906
1975
|
exports.MAX_WEIGHT = MAX_WEIGHT;
|
|
1907
1976
|
exports.RegionRouter = RegionRouter;
|
|
1908
1977
|
exports.USDG_WEIGHT_DECIMAL_PRECISION = USDG_WEIGHT_DECIMAL_PRECISION;
|
|
1978
|
+
exports.WalletsRouter = WalletsRouter;
|
|
1909
1979
|
exports.allRegions = allRegions;
|
|
1910
1980
|
exports.countries = countries;
|
|
1911
1981
|
exports.getAddresses = getAddresses;
|
|
1912
1982
|
exports.regionMetadata = regionMetadata;
|
|
1913
1983
|
exports.usStates = usStates;
|
|
1914
1984
|
exports.useForwarder = useForwarder;
|
|
1915
|
-
//# sourceMappingURL=
|
|
1985
|
+
//# sourceMappingURL=wallets-router-CGxiEOFF.js.map
|