MCPcopy
hub / github.com/BlueWallet/BlueWallet / StorageProvider

Function StorageProvider

components/Context/StorageProvider.tsx:69–586  ·  view source on GitHub ↗
({ children }: { children: React.ReactNode })

Source from the content-addressed store, hash-verified

67export const StorageContext = createContext<StorageContextType>(undefined);
68
69export const StorageProvider = ({ children }: { children: React.ReactNode }) => {
70 const txMetadata = useRef<TTXMetadata>(BlueApp.tx_metadata);
71 const counterpartyMetadata = useRef<TCounterpartyMetadata>(BlueApp.counterparty_metadata || {}); // init
72
73 const [wallets, setWallets] = useState<TWallet[]>([]);
74 const [walletTransactionUpdateStatus, setWalletTransactionUpdateStatus] = useState<WalletTransactionsStatus | string>(
75 WalletTransactionsStatus.NONE,
76 );
77 const [walletsInitialized, setWalletsInitialized] = useState<boolean>(false);
78 const [currentSharedCosigner, setCurrentSharedCosigner] = useState<string>('');
79
80 const selectedWalletID = useCallback((): string | undefined => {
81 if (!navigationRef.current || !navigationRef.current.isReady()) return undefined;
82
83 const screensToCheck = ['LNDCreateInvoice', 'SendDetails', 'WalletTransactions', 'TransactionStatus'];
84
85 const currentRoute = navigationRef.current.getCurrentRoute();
86 console.debug('[StorageProvider] Current route:', currentRoute?.name);
87
88 if (currentRoute) {
89 if (screensToCheck.includes(currentRoute.name) && currentRoute.params) {
90 const params = currentRoute.params as { walletID?: string };
91 if (params.walletID) {
92 console.debug('[StorageProvider] selectedWalletID from current route:', params.walletID);
93 return params.walletID;
94 }
95 }
96 }
97
98 const state = navigationRef.current.getState();
99
100 if (state?.routes) {
101 for (const screenName of screensToCheck) {
102 const walletID = findWalletIDInNavigationState(state.routes, screenName);
103 if (walletID) {
104 console.debug('[StorageProvider] selectedWalletID from navigation state:', walletID, 'in screen:', screenName);
105 return walletID;
106 }
107 }
108
109 const drawerRoute = state.routes.find(route => route.name === 'DrawerRoot');
110 if (drawerRoute?.state?.routes) {
111 const detailViewStack = drawerRoute.state.routes.find(route => route.name === 'DetailViewStackScreensStack');
112 if (detailViewStack?.state?.routes) {
113 for (const route of detailViewStack.state.routes) {
114 if (screensToCheck.includes(route.name) && (route.params as { walletID?: string })?.walletID) {
115 console.debug(
116 '[StorageProvider] selectedWalletID from drawer navigation:',
117 (route.params as { walletID?: string })?.walletID,
118 );
119 return (route.params as { walletID?: string })?.walletID;
120 }
121 }
122 }
123 }
124 }
125
126 return undefined;

Callers

nothing calls this directly

Calls 15

stopArkBackgroundTaskFunction · 0.90
isNotificationsEnabledFunction · 0.90
unsubscribeFunction · 0.90
getScanWasBBQRFunction · 0.90
setWalletIdMustUseBBQRFunction · 0.90
majorTomToGroundControlFunction · 0.90
triggerHapticFeedbackFunction · 0.85
saveToDiskMethod · 0.80
onDeleteMethod · 0.80
getLabelMethod · 0.80

Tested by

no test coverage detected