moviendome/expo-solana-wallet

Frozen app

Closed this issue · 5 comments

Attempting to run the Solana web3 library using the methods from this repo doesn't work. Attempts to establish an RPC connection (new Connection(...)) freeze execution.

I'm importing react-native-url-polyfill/auto, react-native-get-random-values, and a global.js file similar to the one in this repo.

// metro.config.js
const { getDefaultConfig } = require("@expo/metro-config");

const defaultConfig = getDefaultConfig(__dirname);

defaultConfig.resolver.sourceExts.push("cjs");
defaultConfig.resolver.extraNodeModules = {
	...defaultConfig.resolver?.extraNodeModules,
	stream: require.resolve("readable-stream"),
};

module.exports = defaultConfig;

Let me know if any other information would be helpful!

@ideopunk have you found the solution yet i am also facing the problem not being able to use solana web3js with react native ?

@Haianh9999 No solution yet, but I've realized that it's two separate issues.

  1. Calling web3 methods disables console logging. My suspicion is that the console object is being redefined somewhere.

  2. Something else is causing the freezes.

Logging was fixed by adding these lines to the beginning of global.native.js

console.warn("Console is frozen in global.native.js");
Object.freeze(console);

Note that this doesn't seem to work without that pre-freeze console.warn. It's a rather brittle solution, but it works. If my remaining problem turns out to be relevant to this repo, I'll make a new issue for it.

@ideopunk Did you create a file global.native.js then add the above code and import it into App.js is that correct?

@Haianh9999 Yes, it's the exact same as the global.native.js and the global.js files in this repo, just with those two lines added. However, we've run into the (now obvious) problem that the app panics when the underlying library tries to modify the frozen console. We've decided to focus on web for now, but good luck!