-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProviders.tsx
76 lines (64 loc) · 2.33 KB
/
Providers.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import React from 'react';
import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client';
import { DatabaseProvider } from '@nozbe/watermelondb/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import Config from '@constants/config';
import { LocalizationProvider } from '@contexts';
import { Database } from '@database';
import { BridgeContextProvider } from '@features/bridge/context';
import { SwapContextProvider } from '@features/swap/context';
import { WalletConnectContextProvider } from '@features/wallet-connect/context';
import { combineComponents } from '@utils';
const queryClient = new QueryClient();
const WrappedQueryClientProvider: React.FC = ({ children }: any) => (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
);
const ApolloQueryProvider = ({ children }: any) => {
const client = new ApolloClient({
uri: Config.CURRENCY_GRAPH_URL,
cache: new InMemoryCache()
});
return <ApolloProvider client={client}>{children}</ApolloProvider>;
};
const WrappedSafeAreaProvider: React.FC = ({ children }: any) => (
<SafeAreaProvider style={{ flex: 1 }}>{children}</SafeAreaProvider>
);
const WrappedLocalizationProvider: React.FC = ({ children }: any) => (
<LocalizationProvider>{children}</LocalizationProvider>
);
const LocalDBProvider: React.FC = ({ children }: any) => (
<DatabaseProvider database={Database.getDatabase()}>
{children}
</DatabaseProvider>
);
const BridgeProvider: React.FC = ({ children }: any) => (
// @ts-ignore
<BridgeContextProvider>{children}</BridgeContextProvider>
);
const SwapProvider: React.FC = ({ children }: any) => (
// @ts-ignore
<SwapContextProvider>{children}</SwapContextProvider>
);
const WalletConnectProvider: React.FC = ({ children }: any) => (
// @ts-ignore
<WalletConnectContextProvider>{children}</WalletConnectContextProvider>
);
const independentProviders = [
WrappedQueryClientProvider,
ApolloQueryProvider,
WrappedSafeAreaProvider,
WrappedLocalizationProvider
];
/**
* The order of the providers matters
*/
const providers = [
...independentProviders,
LocalDBProvider,
WrappedLocalizationProvider,
BridgeProvider,
SwapProvider,
WalletConnectProvider
];
export const Providers = combineComponents(...providers);