Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

feature/1 - Integrate wallet connect #2

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"@typescript-eslint/parser": "^5.31.0",
"@verida/account-web-vault": "^1.1.12",
"@verida/client-ts": "^1.1.15",
"@walletconnect/client": "^1.8.0",
"@walletconnect/qrcode-modal": "^1.8.0",
"eslint": "^8.20.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-react": "^1.1.7",
Expand Down
9 changes: 7 additions & 2 deletions src/lib/contexts/VeridaContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,18 @@ export const VeridaProvider: React.FunctionComponent<VeridaProviderType> = (
// TODO Handle these cases
return;
}
// eslint-disable-next-line no-console
console.debug("Preparing KYC request");
// TODO remove console.log, debuging time to prepare message
setWaitingKYCRequest(true);

const messaging = await context.getMessaging();

void messaging.onMessage((message: string) => {
console.log("message received from Verida", message);
void messaging.onMessage(() => {
setWaitingKYCRequest(false);

// TODO check KYC VC

setKYCChecked(true);
});

Expand All @@ -122,7 +125,9 @@ export const VeridaProvider: React.FunctionComponent<VeridaProviderType> = (
recipientContextName: "Verida: Vault",
did: requestFromDID,
});
// eslint-disable-next-line no-console
console.debug("KYC request sent");
// TODO remove console.log, debuging time to prepare message
}, [context, profile]);

const resetKYC = useCallback(() => {
Expand Down
1 change: 1 addition & 0 deletions src/lib/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./veridaUtils";
export * from "./walletConnectUtils";
27 changes: 24 additions & 3 deletions src/lib/utils/veridaUtils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import {
Network,
EnvironmentType,
Expand All @@ -6,17 +7,37 @@ import {
} from "@verida/client-ts";
import { VaultAccount } from "@verida/account-web-vault";
import { UserProfile } from "lib/types";
import { initWalletConnect, DEFAULT_CHAIN_ID } from "./walletConnectUtils";
import WalletConnect from "@walletconnect/client";

const connect = async (
contextName: string,
environment: EnvironmentType,
logoUrl?: string,
openUrl?: string
): Promise<[context: Context, account: VaultAccount, profile: UserProfile]> => {
openUrl?: string,
walletConnectChainId = DEFAULT_CHAIN_ID
): Promise<
[
context: Context,
account: VaultAccount,
profile: UserProfile,
walletConnectConnector: WalletConnect
]
> => {
const walletConnectConnector = await initWalletConnect();
// eslint-disable-next-line no-console
console.log(walletConnectConnector);

const account = new VaultAccount({
request: {
logoUrl,
openUrl,
// @ts-ignore
walletConnect: {

Choose a reason for hiding this comment

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

Hi @aurelticot, going through the @verida/account-web-vault packages I couldn't find where changes were made to support the WC + Verida connect .

Does it seem like it has not been updated ?

version: walletConnectConnector.version,
uri: walletConnectConnector.uri,
chainId: walletConnectChainId,
},
},
});

Expand All @@ -37,7 +58,7 @@ const connect = async (
const did = await account.did();
const profile = await getPublicProfileInfo(context, did);

return [context, account, profile];
return [context, account, profile, walletConnectConnector];
};

const disconnect = async (
Expand Down
50 changes: 50 additions & 0 deletions src/lib/utils/walletConnectUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* eslint-disable no-console */
import WalletConnect from "@walletconnect/client";
// import QRCodeModal from "@walletconnect/qrcode-modal";
// TODO remove the modal dependency after testing

export const DEFAULT_BRIDGE_URL = "https://bridge.walletconnect.org";
export const DEFAULT_CHAIN_ID = "eip155:1";

export const initWalletConnect = async (
bridgeURL = DEFAULT_BRIDGE_URL
): Promise<WalletConnect> => {
// Create a connector
const connector = new WalletConnect({
bridge: bridgeURL,
// qrcodeModal: QRCodeModal, // the modal is not required
});

// Check if connection is already established
if (!connector.connected) {
// create new session
await connector.createSession();
}

// Subscribe to connection events
connector.on("connect", (error, payload) => {
if (error) {
console.error(error);
return;
}
console.log("WalletConnect on connect payload:", payload);
});

connector.on("session_update", (error, payload) => {
if (error) {
console.error(error);
return;
}
console.log("WalletConnect on session_update payload:", payload);
});

connector.on("disconnect", (error, payload) => {
if (error) {
console.error(error);
return;
}
console.log("WalletConnect on disconnect payload:", payload);
});

return connector;
};
Loading