@talismn/balances-react 0.3.3 → 0.4.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @talismn/balances-react
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - a6969098: refactor: tweaks to trigger less balance subscription resets
8
+
9
+ ### Patch Changes
10
+
11
+ - 3068bd60: feat: stale balances and exponential rpc backoff
12
+ - 6643a4e4: fix: tokenRates in @talismn/balances-react
13
+ - 6643a4e4: fix: ported useDbCache related perf fixes to @talismn/balances-react
14
+ - Updated dependencies [3068bd60]
15
+ - Updated dependencies [6643a4e4]
16
+ - Updated dependencies [79f6ccf6]
17
+ - Updated dependencies [6643a4e4]
18
+ - Updated dependencies [c24dc1fb]
19
+ - @talismn/chain-connector@0.4.3
20
+ - @talismn/connection-meta@0.0.2
21
+ - @talismn/balances@0.4.0
22
+ - @talismn/token-rates@0.1.15
23
+ - @talismn/chaindata-provider-extension@0.4.3
24
+ - @talismn/chaindata-provider@0.4.3
25
+ - @talismn/chain-connector-evm@0.4.3
26
+
3
27
  ## 0.3.3
4
28
 
5
29
  ### Patch Changes
@@ -1,3 +1,23 @@
1
+ export * from "./useAllAddresses";
2
+ export * from "./useBalanceModules";
1
3
  export * from "./useBalances";
4
+ export * from "./useBalancesHydrate";
5
+ export * from "./useBalancesStatus";
6
+ export * from "./useChainConnectors";
2
7
  export * from "./useChaindata";
8
+ export * from "./useChains";
9
+ export * from "./useDbCache";
10
+ export * from "./useDbCacheSubscription";
11
+ export * from "./useEvmNetworks";
3
12
  export * from "./useTokenRates";
13
+ export * from "./useTokens";
14
+ export * from "./useWithTestnets";
15
+ import { BalanceModule, Hydrate } from "@talismn/balances";
16
+ import { ReactNode } from "react";
17
+ export type BalancesProviderProps = {
18
+ balanceModules: Array<(hydrate: Hydrate) => BalanceModule<any, any, any, any, any>>;
19
+ onfinalityApiKey?: string;
20
+ withTestnets?: boolean;
21
+ children?: ReactNode;
22
+ };
23
+ export declare const BalancesProvider: ({ balanceModules, onfinalityApiKey, withTestnets, children, }: BalancesProviderProps) => JSX.Element;
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ export declare const AllAddressesProvider: import("react").FC<{
3
+ children?: import("react").ReactNode;
4
+ }>, useAllAddresses: () => [string[], import("react").Dispatch<import("react").SetStateAction<string[]>>];
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { BalanceModule, Hydrate } from "@talismn/balances";
3
+ export type BalanceModulesProviderOptions = {
4
+ balanceModules: Array<(hydrate: Hydrate) => BalanceModule<any, any, any, any, any>>;
5
+ };
6
+ export declare const BalanceModulesProvider: import("react").FC<BalanceModulesProviderOptions & {
7
+ children?: import("react").ReactNode;
8
+ }>, useBalanceModules: () => BalanceModule<any, any, any, any, any>[];
@@ -1,6 +1,3 @@
1
- import { AddressesByToken, BalanceModule, Balances } from "@talismn/balances";
2
- import { ChaindataProvider, Token } from "@talismn/chaindata-provider";
3
- export type Options = {
4
- onfinalityApiKey?: string;
5
- };
6
- export declare function useBalances(balanceModules: Array<BalanceModule<any, any, any, any>>, chaindataProvider: ChaindataProvider | null, addressesByToken: AddressesByToken<Token> | null, options?: Options): Balances | undefined;
1
+ import { AddressesByToken, Balances } from "@talismn/balances";
2
+ import { Token } from "@talismn/chaindata-provider";
3
+ export declare function useBalances(addressesByToken: AddressesByToken<Token> | null): Balances;
@@ -0,0 +1,2 @@
1
+ import { HydrateDb } from "@talismn/balances";
2
+ export declare const useBalancesHydrate: () => HydrateDb;
@@ -0,0 +1,19 @@
1
+ import { Balances } from "@talismn/balances";
2
+ export type BalancesStatus = {
3
+ status: "live";
4
+ } | {
5
+ status: "fetching";
6
+ } | {
7
+ status: "stale";
8
+ staleChains: string[];
9
+ };
10
+ /**
11
+ * Given a collection of `Balances`, this hook returns a `BalancesStatus` summary for the collection.
12
+ *
13
+ * @param balances The collection of balances to get the status from.
14
+ * @param isLoadingLocks Because the wallet currently fetches locks outside of the balances api, this param can be used to indicate that the locks are still loading, even if the `Balances` collection is not.
15
+ * @returns An instance of `BalancesStatus` which represents the status of the balances collection.
16
+
17
+ */
18
+ export declare const useBalancesStatus: (balances: Balances, isLoadingLocks?: boolean) => BalancesStatus;
19
+ export declare const getStaleChains: (balances: Balances) => string[];
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { ChainConnector } from "@talismn/chain-connector";
3
+ import { ChainConnectorEvm } from "@talismn/chain-connector-evm";
4
+ export type ChainConnectorsProviderOptions = {
5
+ onfinalityApiKey?: string;
6
+ };
7
+ export declare const ChainConnectorsProvider: import("react").FC<ChainConnectorsProviderOptions & {
8
+ children?: import("react").ReactNode;
9
+ }>, useChainConnectors: () => {
10
+ substrate: ChainConnector;
11
+ evm: ChainConnectorEvm;
12
+ };
@@ -1,25 +1,8 @@
1
- import { Chain, ChainId, ChainList, ChaindataProvider, EvmNetwork, EvmNetworkId, EvmNetworkList, Token, TokenId, TokenList } from "@talismn/chaindata-provider";
2
- export type Options = {
1
+ /// <reference types="react" />
2
+ import { ChaindataProviderExtension } from "@talismn/chaindata-provider-extension";
3
+ export type ChaindataProviderOptions = {
3
4
  onfinalityApiKey?: string;
4
5
  };
5
- export declare function useChaindata(options?: Options): (ChaindataProvider & {
6
- generation?: number | undefined;
7
- }) | null;
8
- export declare function useChains(chaindata: (ChaindataProvider & {
9
- generation?: number;
10
- }) | null): ChainList;
11
- export declare function useChain(chaindata: (ChaindataProvider & {
12
- generation?: number;
13
- }) | null, chainId?: ChainId): Chain | null | undefined;
14
- export declare function useEvmNetworks(chaindata: (ChaindataProvider & {
15
- generation?: number;
16
- }) | null): EvmNetworkList;
17
- export declare function useEvmNetwork(chaindata: (ChaindataProvider & {
18
- generation?: number;
19
- }) | null, evmNetworkId?: EvmNetworkId): EvmNetwork | null | undefined;
20
- export declare function useTokens(chaindata: (ChaindataProvider & {
21
- generation?: number;
22
- }) | null): TokenList;
23
- export declare function useToken(chaindata: (ChaindataProvider & {
24
- generation?: number;
25
- }) | null, tokenId?: TokenId): Token | null | undefined;
6
+ export declare const ChaindataProvider: import("react").FC<ChaindataProviderOptions & {
7
+ children?: import("react").ReactNode;
8
+ }>, useChaindata: () => ChaindataProviderExtension;
@@ -0,0 +1,3 @@
1
+ import { ChainId } from "@talismn/chaindata-provider";
2
+ export declare function useChains(withTestnets?: boolean): Record<string, import("@talismn/chaindata-provider").Chain | import("@talismn/chaindata-provider").CustomChain>;
3
+ export declare function useChain(chainId?: ChainId, withTestnets?: boolean): import("@talismn/chaindata-provider").Chain | undefined;
@@ -0,0 +1,24 @@
1
+ /// <reference types="react" />
2
+ import { BalanceJson } from "@talismn/balances";
3
+ import { Chain, ChainId, CustomChain, CustomEvmNetwork, EvmNetwork, EvmNetworkId, Token, TokenId } from "@talismn/chaindata-provider";
4
+ import { TokenRates } from "@talismn/token-rates";
5
+ type DbCache = {
6
+ chainsWithTestnets: (Chain | CustomChain)[];
7
+ chainsWithoutTestnets: (Chain | CustomChain)[];
8
+ evmNetworksWithTestnets: (EvmNetwork | CustomEvmNetwork)[];
9
+ evmNetworksWithoutTestnets: (EvmNetwork | CustomEvmNetwork)[];
10
+ tokensWithTestnets: Token[];
11
+ tokensWithoutTestnets: Token[];
12
+ chainsWithTestnetsMap: Record<ChainId, Chain | CustomChain>;
13
+ chainsWithoutTestnetsMap: Record<ChainId, Chain | CustomChain>;
14
+ evmNetworksWithTestnetsMap: Record<EvmNetworkId, EvmNetwork | CustomEvmNetwork>;
15
+ evmNetworksWithoutTestnetsMap: Record<EvmNetworkId, EvmNetwork | CustomEvmNetwork>;
16
+ tokensWithTestnetsMap: Record<TokenId, Token>;
17
+ tokensWithoutTestnetsMap: Record<TokenId, Token>;
18
+ tokenRatesMap: Record<TokenId, TokenRates>;
19
+ balances: BalanceJson[];
20
+ };
21
+ export declare const DbCacheProvider: import("react").FC<{
22
+ children?: import("react").ReactNode;
23
+ }>, useDbCache: () => DbCache;
24
+ export {};
@@ -0,0 +1,13 @@
1
+ export type DbEntityType = "chains" | "evmNetworks" | "tokens";
2
+ /**
3
+ * This hook is responsible for fetching the data used for balances and inserting it into the db.
4
+ */
5
+ export declare const useDbCacheSubscription: (subscribeTo: DbEntityType) => void;
6
+ /**
7
+ * This hook is responsible for fetching the data used for token rates and inserting it into the db.
8
+ */
9
+ export declare function useDbCacheTokenRatesSubscription(): void;
10
+ /**
11
+ * This hook is responsible for fetching the data used for balances and inserting it into the db.
12
+ */
13
+ export declare function useDbCacheBalancesSubscription(): void;
@@ -0,0 +1,3 @@
1
+ import { EvmNetworkId } from "@talismn/chaindata-provider";
2
+ export declare function useEvmNetworks(withTestnets?: boolean): Record<string, import("@talismn/chaindata-provider").EvmNetwork | import("@talismn/chaindata-provider").CustomEvmNetwork>;
3
+ export declare function useEvmNetwork(evmNetworkId?: EvmNetworkId, withTestnets?: boolean): import("@talismn/chaindata-provider").EvmNetwork | undefined;
@@ -1,3 +1,3 @@
1
- import { IToken, TokenId } from "@talismn/chaindata-provider";
2
- import { TokenRatesList } from "@talismn/token-rates";
3
- export declare function useTokenRates(tokens?: Record<TokenId, IToken>): TokenRatesList;
1
+ import { TokenId } from "@talismn/chaindata-provider";
2
+ export declare function useTokenRates(): Record<string, import("@talismn/token-rates").TokenRates>;
3
+ export declare function useTokenRate(tokenId?: TokenId): import("@talismn/token-rates").TokenRates | undefined;
@@ -0,0 +1,3 @@
1
+ import { TokenId } from "@talismn/chaindata-provider";
2
+ export declare function useTokens(withTestnets?: boolean): Record<string, import("@talismn/chaindata-provider").IToken>;
3
+ export declare function useToken(tokenId?: TokenId, withTestnets?: boolean): import("@talismn/chaindata-provider").IToken | undefined;
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ export declare const WithTestnetsProvider: import("react").FC<{
3
+ withTestnets?: boolean | undefined;
4
+ } & {
5
+ children?: import("react").ReactNode;
6
+ }>, useWithTestnets: () => {
7
+ withTestnets: boolean | undefined;
8
+ };
@@ -1 +1,2 @@
1
1
  export * from "./hooks";
2
+ export * from "./util";
@@ -0,0 +1,2 @@
1
+ export * from "./provideContext";
2
+ export * from "./useMulticastSubscription";
@@ -0,0 +1,9 @@
1
+ import { FC, ReactNode } from "react";
2
+ /**
3
+ * This utility generates a context provider from a react hook passed as argument
4
+ *
5
+ * @returns an array containing the provider and the consumer hook
6
+ */
7
+ export declare const provideContext: <P, T>(useProviderContext: (props: P) => T) => [FC<P & {
8
+ children?: ReactNode;
9
+ }>, () => T];
@@ -0,0 +1,16 @@
1
+ export type Unsubscribe = () => void;
2
+ /**
3
+ * Creates a subscription function that can be used to subscribe to a multicast observable created from an upstream source.
4
+ *
5
+ * An example of when this is useful is when we want to subscribe to some data from multiple components, but we only want
6
+ * to actively keep that data hydrated when at least one component is subscribed to it.
7
+ *
8
+ * When the first component subscribes, the `upstream` function will be called. It should then set up a subscription and return a teardown function.
9
+ * When subsequent components subscribe, they will be added to the existing subscription.
10
+ * When the last component unsubscribes, the teardown function returned from the `upstream` function will be called.
11
+ *
12
+ * @param upstream A function that takes a "next" callback function as an argument, and returns either an unsubscribe function or void.
13
+ * @returns A subscription function that can be used to subscribe to the multicast observable.
14
+ */
15
+ export declare const useMulticastSubscription: <T>(upstream: (next: (val: T) => void) => Unsubscribe | void) => (callback?: ((val: T) => void) | undefined) => Unsubscribe;
16
+ export declare const createMulticastSubscription: <T>(upstream: (next: (val: T) => void) => Unsubscribe | void) => (callback?: ((val: T) => void) | undefined) => Unsubscribe;
@@ -0,0 +1,9 @@
1
+ type UnsubscribeFn = () => void;
2
+ type InitSubscriptionCallback = () => UnsubscribeFn;
3
+ /**
4
+ * This hook ensures a subscription is created only once, and unsubscribe automatically as soon as there is no consumer to the hook
5
+ * @param key key that is unique to the subscription's parameters
6
+ * @param subscribe // subscribe function that will be shared by all consumers of the key
7
+ */
8
+ export declare const useSharedSubscription: (key: string, subscribe: InitSubscriptionCallback) => void;
9
+ export {};