-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
error solved in main with JSON.parse
- Loading branch information
Philip
authored and
Philip
committed
Dec 20, 2023
1 parent
c95106e
commit ec481f5
Showing
8 changed files
with
33,103 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
packages/nextjs/components/wallet/WalletConnect/PairingModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// import { SignClientTypes } from "@walletconnect/types"; | ||
// import { Button, Image, Modal, StyleSheet, Text, View } from "react-native"; | ||
|
||
// interface PairingModalProps { | ||
// visible: boolean; | ||
// setModalVisible: (arg1: boolean) => void; | ||
// currentProposal: SignClientTypes.EventArguments["session_proposal"] | undefined; | ||
// handleAccept: () => void; | ||
// handleReject: () => void; | ||
// } | ||
|
||
// export default function PairingModal({ visible, currentProposal, handleAccept, handleReject }: PairingModalProps) { | ||
// const name = currentProposal?.params?.proposer?.metadata?.name; | ||
// const url = currentProposal?.params?.proposer?.metadata.url; | ||
// const methods = currentProposal?.params?.requiredNamespaces.eip155.methods; | ||
// const events = currentProposal?.params?.requiredNamespaces.eip155.events; | ||
// const chains = currentProposal?.params?.requiredNamespaces.eip155.chains; | ||
// const icon = currentProposal?.params.proposer.metadata.icons[0]; | ||
|
||
// return ( | ||
// <Modal visible={visible} animationType="slide" transparent> | ||
// <View style={styles.container}> | ||
// <View style={styles.modalContentContainer}> | ||
// <Image | ||
// style={styles.dappLogo} | ||
// source={{ | ||
// uri: icon, | ||
// }} | ||
// /> | ||
// <Text>{name}</Text> | ||
// <Text>{url}</Text> | ||
|
||
// <Text>Chains: {chains}</Text> | ||
|
||
// <View style={styles.marginVertical8}> | ||
// <Text style={styles.subHeading}>Methods:</Text> | ||
// {methods?.map(method => ( | ||
// <Text style={styles.centerText} key={method}> | ||
// {method} | ||
// </Text> | ||
// ))} | ||
// </View> | ||
|
||
// <View style={styles.marginVertical8}> | ||
// <Text style={styles.subHeading}>Events:</Text> | ||
// {events?.map(events => ( | ||
// <Text style={styles.centerText}>{events}</Text> | ||
// ))} | ||
// </View> | ||
|
||
// <View style={styles.flexRow}> | ||
// <Button onPress={() => handleReject()} title="Cancel" /> | ||
// <Button onPress={() => handleAccept()} title="Accept" /> | ||
// </View> | ||
// </View> | ||
// </View> | ||
// </Modal> | ||
// ); | ||
// } | ||
|
||
// const styles = StyleSheet.create({ | ||
// container: { | ||
// flex: 1, | ||
// alignItems: "center", | ||
// justifyContent: "center", | ||
// }, | ||
// modalContentContainer: { | ||
// display: "flex", | ||
// justifyContent: "center", | ||
// alignItems: "center", | ||
// borderRadius: 34, | ||
// borderWidth: 1, | ||
// width: "100%", | ||
// height: "50%", | ||
// position: "absolute", | ||
// backgroundColor: "white", | ||
// bottom: 0, | ||
// }, | ||
// dappLogo: { | ||
// width: 50, | ||
// height: 50, | ||
// borderRadius: 8, | ||
// marginVertical: 4, | ||
// }, | ||
// flexRow: { | ||
// display: "flex", | ||
// flexDirection: "row", | ||
// }, | ||
// marginVertical8: { | ||
// marginVertical: 8, | ||
// textAlign: "center", | ||
// }, | ||
// subHeading: { | ||
// textAlign: "center", | ||
// fontWeight: "600", | ||
// }, | ||
// centerText: { | ||
// textAlign: "center", | ||
// }, | ||
// }); |
51 changes: 51 additions & 0 deletions
51
packages/nextjs/components/wallet/WalletConnect/WalletConnect.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// import { useCallback, useEffect, useState } from "react"; | ||
// import { createWeb3Wallet, web3wallet } from "./utils/WalletConnectUtils"; | ||
// import { Core } from "@walletconnect/core"; | ||
// import { SignClient } from "@walletconnect/sign-client"; | ||
// import { buildApprovedNamespaces, getSdkError } from "@walletconnect/utils"; | ||
// import { Web3Wallet, Web3WalletTypes } from "@walletconnect/web3wallet"; | ||
// // import { Web3Wallet } from "@walletconnect/web3wallet/dist/types/client"; | ||
// import { useSharedState } from "~~/sharedStateContext"; | ||
|
||
// export const WalletConnect = () => { | ||
// // ETHEREUM Wallet connect react app | ||
// const [currentWCURI, setCurrentWCURI] = useState( | ||
// "wc:2f3149afc03351c24565c683fe05bea8f6e6bb6283fc1f5ebacb544f079d600a@2?relay-protocol=irn&symKey=6fc7f0a3c1dec613af93b73e447caef0c59183ff865c0654ae3c384ea507b9c5", | ||
// ); | ||
// const [web3walletNew, setWeb3WalletNew] = useState<Web3Wallet | null>(null); | ||
// const [signClient, setSignClient] = useState(); | ||
|
||
// async function createClient() { | ||
// try { | ||
// const client = await SignClient.init(); | ||
// console.log("createClient", client); | ||
// setSignClient(client); | ||
// } catch (error) { | ||
// console.log(error); | ||
// } | ||
// } | ||
|
||
// useEffect(() => { | ||
// if (!signClient) { | ||
// createClient(); | ||
// } | ||
// }, [signClient]); | ||
|
||
// return ( | ||
// <> | ||
// <h1>Wallet Connect</h1> | ||
// <button onClick={() => console.log(createWeb3Wallet())}>Click Me</button> | ||
// <form> | ||
// <input | ||
// onChange={e => setCurrentWCURI(e.target.value)} | ||
// value={currentWCURI} | ||
// placeholder="Enter WC URI (wc:1234...)" | ||
// /> | ||
|
||
// <button onClick={() => pair()} title="Pair Session"> | ||
// PAIR Session | ||
// </button> | ||
// </form> | ||
// </> | ||
// ); | ||
// }; |
140 changes: 140 additions & 0 deletions
140
packages/nextjs/components/wallet/WalletConnect/utils/EIP155Lib.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
// /** | ||
// * Types | ||
// */ | ||
// interface IInitArgs { | ||
// mnemonic?: string; | ||
// } | ||
|
||
// /** | ||
// * Library | ||
// */ | ||
// export default class EIP155Lib { | ||
// wallet: Wallet; | ||
|
||
// constructor(wallet: Wallet) { | ||
// this.wallet = wallet; | ||
// } | ||
|
||
// static init({ mnemonic }: IInitArgs) { | ||
// const wallet = mnemonic ? Wallet.fromMnemonic(mnemonic) : Wallet.createRandom(); | ||
|
||
// return new EIP155Lib(wallet); | ||
// } | ||
|
||
// getMnemonic() { | ||
// return this.wallet.mnemonic.phrase; | ||
|
||
// getAddress() { | ||
// return this.wallet.address; | ||
// } | ||
|
||
// signMessage(message: string) { | ||
// return this.wallet.signMessage(message); | ||
// } | ||
|
||
// _signTypedData(domain: any, types: any, data: any) { | ||
// return this.wallet._signTypedData(domain, types, data); | ||
// } | ||
|
||
// connect(provider: providers.JsonRpcProvider) { | ||
// return this.wallet.connect(provider); | ||
// } | ||
|
||
// signTransaction(transaction: providers.TransactionRequest) { | ||
// return this.wallet.signTransaction(transaction); | ||
// } | ||
// } | ||
|
||
// /** | ||
// * @desc Reference list of eip155 chains | ||
// * @url https://chainlist.org | ||
// */ | ||
|
||
// /** | ||
// * Types | ||
// */ | ||
// export type TEIP155Chain = keyof typeof EIP155_CHAINS; | ||
|
||
// /** | ||
// * Chains | ||
// */ | ||
// export const EIP155_MAINNET_CHAINS = { | ||
// "eip155:1": { | ||
// chainId: 1, | ||
// name: "Ethereum", | ||
// logo: "/chain-logos/eip155-1.png", | ||
// rgb: "99, 125, 234", | ||
// rpc: "https://cloudflare-eth.com/", | ||
// }, | ||
// "eip155:43114": { | ||
// chainId: 43114, | ||
// name: "Avalanche C-Chain", | ||
// logo: "/chain-logos/eip155-43113.png", | ||
// rgb: "232, 65, 66", | ||
// rpc: "https://api.avax.network/ext/bc/C/rpc", | ||
// }, | ||
// "eip155:137": { | ||
// chainId: 137, | ||
// name: "Polygon", | ||
// logo: "/chain-logos/eip155-137.png", | ||
// rgb: "130, 71, 229", | ||
// rpc: "https://polygon-rpc.com/", | ||
// }, | ||
// "eip155:10": { | ||
// chainId: 10, | ||
// name: "Optimism", | ||
// logo: "/chain-logos/eip155-10.png", | ||
// rgb: "235, 0, 25", | ||
// rpc: "https://mainnet.optimism.io", | ||
// }, | ||
// }; | ||
|
||
// export const EIP155_TEST_CHAINS = { | ||
// "eip155:5": { | ||
// chainId: 5, | ||
// name: "Ethereum Goerli", | ||
// logo: "/chain-logos/eip155-1.png", | ||
// rgb: "99, 125, 234", | ||
// rpc: "https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161", | ||
// }, | ||
// "eip155:43113": { | ||
// chainId: 43113, | ||
// name: "Avalanche Fuji", | ||
// logo: "/chain-logos/eip155-43113.png", | ||
// rgb: "232, 65, 66", | ||
// rpc: "https://api.avax-test.network/ext/bc/C/rpc", | ||
// }, | ||
// "eip155:80001": { | ||
// chainId: 80001, | ||
// name: "Polygon Mumbai", | ||
// logo: "/chain-logos/eip155-137.png", | ||
// rgb: "130, 71, 229", | ||
// rpc: "https://matic-mumbai.chainstacklabs.com", | ||
// }, | ||
// "eip155:420": { | ||
// chainId: 420, | ||
// name: "Optimism Goerli", | ||
// logo: "/chain-logos/eip155-10.png", | ||
// rgb: "235, 0, 25", | ||
// rpc: "https://goerli.optimism.io", | ||
// }, | ||
// }; | ||
|
||
// export const EIP155_CHAINS = { | ||
// ...EIP155_MAINNET_CHAINS, | ||
// ...EIP155_TEST_CHAINS, | ||
// }; | ||
|
||
// /** | ||
// * Methods | ||
// */ | ||
// export const EIP155_SIGNING_METHODS = { | ||
// PERSONAL_SIGN: "personal_sign", | ||
// ETH_SIGN: "eth_sign", | ||
// ETH_SIGN_TRANSACTION: "eth_signTransaction", | ||
// ETH_SIGN_TYPED_DATA: "eth_signTypedData", | ||
// ETH_SIGN_TYPED_DATA_V3: "eth_signTypedData_v3", | ||
// ETH_SIGN_TYPED_DATA_V4: "eth_signTypedData_v4", | ||
// ETH_SEND_RAW_TRANSACTION: "eth_sendRawTransaction", | ||
// ETH_SEND_TRANSACTION: "eth_sendTransaction", | ||
// }; |
72 changes: 72 additions & 0 deletions
72
packages/nextjs/components/wallet/WalletConnect/utils/WalletConnectUtils.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// import { Core } from "@walletconnect/core"; | ||
// import { IWeb3Wallet, Web3Wallet } from "@walletconnect/web3wallet"; | ||
|
||
// export let web3wallet: IWeb3Wallet; | ||
|
||
// export async function createWeb3Wallet() { | ||
// const core = new Core({ | ||
// projectId: process.env.NEXT_PUBLIC_PROJECT_ID, | ||
// // relayUrl: relayerRegionURL ?? process.env.NEXT_PUBLIC_RELAY_URL, | ||
// }); | ||
|
||
// console.log("projectID", process.env.NEXT_PUBLIC_PROJECT_ID); | ||
// web3wallet = await Web3Wallet.init({ | ||
// core, | ||
// metadata: { | ||
// name: "React Wallet Example", | ||
// description: "React Wallet for WalletConnect", | ||
// url: "https://walletconnect.com/", | ||
// icons: ["https://avatars.githubusercontent.com/u/37784886"], | ||
// }, | ||
// }); | ||
|
||
// try { | ||
// const clientId = await web3wallet.engine.signClient.core.crypto.getClientId(); | ||
// console.log("WalletConnect ClientID: ", clientId); | ||
// localStorage.setItem("WALLETCONNECT_CLIENT_ID", clientId); | ||
// } catch (error) { | ||
// console.error("Failed to set WalletConnect clientId in localStorage: ", error); | ||
// } | ||
// } | ||
|
||
// export async function updateSignClientChainId(chainId: string, address: string) { | ||
// console.log("chainId", chainId, address); | ||
// // get most recent session | ||
// const sessions = web3wallet.getActiveSessions(); | ||
// if (!sessions) return; | ||
// const namespace = chainId.split(":")[0]; | ||
// Object.values(sessions).forEach(async session => { | ||
// await web3wallet.updateSession({ | ||
// topic: session.topic, | ||
// namespaces: { | ||
// ...session.namespaces, | ||
// [namespace]: { | ||
// ...session.namespaces[namespace], | ||
// chains: [...new Set([chainId].concat(Array.from(session.namespaces[namespace].chains || [])))], | ||
// accounts: [...new Set([`${chainId}:${address}`].concat(Array.from(session.namespaces[namespace].accounts)))], | ||
// }, | ||
// }, | ||
// }); | ||
// await new Promise(resolve => setTimeout(resolve, 1000)); | ||
|
||
// const chainChanged = { | ||
// topic: session.topic, | ||
// event: { | ||
// name: "chainChanged", | ||
// data: parseInt(chainId.split(":")[1]), | ||
// }, | ||
// chainId: chainId, | ||
// }; | ||
|
||
// const accountsChanged = { | ||
// topic: session.topic, | ||
// event: { | ||
// name: "accountsChanged", | ||
// data: [`${chainId}:${address}`], | ||
// }, | ||
// chainId, | ||
// }; | ||
// await web3wallet.emitSessionEvent(chainChanged); | ||
// await web3wallet.emitSessionEvent(accountsChanged); | ||
// }); | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters