Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web5.connect() with react-native #51

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ yarn-error.log
.expo/
web-build/
dist/
.yarn
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
27 changes: 26 additions & 1 deletion metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,31 @@ const { mergeConfig } = require("metro-config");

const config = getDefaultConfig(__dirname);
const web5Config = require("@tbd54566975/web5-react-native-metro-config");
const currentDir = process.cwd();
const customConfig = {
...config,
resolver: {
sourceExts: ["ts", "tsx", "js", "jsx", "json", "cjs", "mjs"],
resolveRequest: (context, moduleName, platform) => {
if (moduleName === "@decentralized-identity/ion-tools") {
return {
// @tbd54566975/web5-react-native-metro-config references @decentralized-identity/ion-tools/dist/esm/index.js but the correct path is @decentralized-identity/ion-tools/dist/esm/src/index.js
filePath: `${currentDir}/node_modules/@decentralized-identity/ion-tools/dist/esm/src/index.js`,
type: "sourceFile",
};
}

if (moduleName === "@tbd54566975/web5") {
return {
filePath: `${currentDir}/node_modules/@tbd54566975/web5/dist/esm/main.mjs`,
type: "sourceFile",
};
}

return context.resolveRequest(context, moduleName, platform);
},
},
};
config.resolver.sourceExts.push("mjs");

module.exports = mergeConfig(config, web5Config);
module.exports = mergeConfig(customConfig, web5Config);
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@
},
"@comment resolutions": "enforce de-duping even if upstream wont. this will need to be maintained.",
"resolutions": {
"@ipld/dag-cbor": "^9.0.3"
"@ipld/dag-cbor": "^9.0.3",
"level": "file:./src/rn-async-storage-level"
},
"dependencies": {
"@craftzdog/react-native-buffer": "6.0.5",
"@decentralized-identity/ion-tools": "1.0.7",
"@legendapp/state": "1.3.6",
"@react-native-async-storage/async-storage": "^1.19.1",
"@react-navigation/bottom-tabs": "6.5.8",
"@react-navigation/native": "6.1.7",
"@react-navigation/native-stack": "6.9.13",
"@tbd54566975/dwn-sdk-js": "0.1.0",
"@tbd54566975/dwn-sql-store": "0.0.3",
"@tbd54566975/web5": "0.7.11",
"@tbd54566975/web5-react-native-metro-config": "0.1.2",
Expand Down
8 changes: 7 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { DwnService } from "./features/dwn/dwn-service";
import { enableLegendStateReact } from "@legendapp/state/react";
import { StatusBar } from "expo-status-bar";
import { linking } from "./navigation/deep-links";
import { Web5 } from "@tbd54566975/web5";

enableLegendStateReact();

Expand All @@ -19,7 +20,12 @@ export const theme: typeof MD3DarkTheme = {

export default function App() {
useEffect(() => {
void DwnService.initSqliteDwn();
async function init() {
void DwnService.initMemoryDwn();
const { web5, did: myDid } = await Web5.connect();
Copy link
Contributor

@amika-sq amika-sq Aug 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that Web5.connect() won't be called from the identity agents like the wallet. This concept is going through a pretty major refactor currently by @frankhinek on the web5-js side.

Would like to hold off on thoroughly reviewing this in until we have a solid understanding of what this re-write entails for clients. @frankhinek if you have any insights here, would greatly appreciate it!

console.log("myDid", myDid);
}
void init();
}, []);

return (
Expand Down
Loading