@@ -2,83 +2,10 @@ import { useMemo, useContext } from "react";
22import type algosdk from "algosdk" ;
33import { getAlgosdk } from "../algod" ;
44import { useWalletStore , walletStoreSelector } from "../store/index" ;
5- import {
6- PROVIDER_ID ,
7- TransactionsArray ,
8- WalletClient ,
9- Network ,
10- } from "../types" ;
5+ import { PROVIDER_ID , TransactionsArray , WalletClient } from "../types" ;
116import { ClientContext } from "../store/state/clientStore" ;
127import allClients from "../clients" ;
138import shallow from "zustand/shallow" ;
14- import {
15- DEFAULT_NODE_BASEURL ,
16- DEFAULT_NODE_TOKEN ,
17- DEFAULT_NODE_PORT ,
18- DEFAULT_NETWORK ,
19- } from "../constants" ;
20-
21- type SupportedProviders = { [ x : string ] : Promise < WalletClient | null > } ;
22-
23- type NodeConfig = {
24- network : Network ;
25- nodeServer : string ;
26- nodeToken ?: string ;
27- nodePort ?: string ;
28- } ;
29-
30- export const initializeProviders = (
31- providers ?: PROVIDER_ID [ ] ,
32- nodeConfig ?: NodeConfig ,
33- algosdkStatic ?: typeof algosdk
34- ) => {
35- const initializedProviders : SupportedProviders = { } ;
36-
37- const {
38- network = DEFAULT_NETWORK ,
39- nodeServer = DEFAULT_NODE_BASEURL ,
40- nodePort = DEFAULT_NODE_PORT ,
41- nodeToken = DEFAULT_NODE_TOKEN ,
42- } = nodeConfig || { } ;
43-
44- if ( ! providers || providers . length === 0 )
45- for ( const [ id , client ] of Object . entries ( allClients ) ) {
46- if ( id === "kmd" ) {
47- continue ;
48- }
49-
50- initializedProviders [ id ] = client . init ( {
51- network,
52- algodOptions : [ nodeToken , nodeServer , nodePort ] ,
53- algosdkStatic : algosdkStatic ,
54- } ) ;
55- }
56-
57- if ( providers ) {
58- for ( const id of providers ) {
59- initializedProviders [ id ] = allClients [ id ] . init ( {
60- network,
61- algodOptions : [ nodeToken , nodeServer , nodePort ] ,
62- algosdkStatic : algosdkStatic ,
63- } ) ;
64- }
65- }
66-
67- return initializedProviders ;
68- } ;
69-
70- export const reconnectProviders = async ( providers : SupportedProviders ) => {
71- try {
72- const clients = Object . values ( providers ) ;
73-
74- for ( const client of clients ) {
75- const c = await client ;
76- c ?. reconnect ( c ?. disconnect ) ;
77- }
78- } catch ( e ) {
79- console . error ( e ) ;
80- }
81- } ;
829
8310export { PROVIDER_ID } ;
8411
0 commit comments