Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ManavJain01 committed Apr 29, 2024
1 parent 1723ab4 commit 40c2d08
Show file tree
Hide file tree
Showing 9 changed files with 1,124 additions and 39 deletions.
9 changes: 9 additions & 0 deletions Components/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import NavBar from "./NavBar/NavBar"
import Filter from './Filter/Filter'
import Error from './Error/Error'
import Loader from './Loader/Loader'
import Model from './Model/Model'
import UserCard from './UserCard/UserCard'
import Friend from './Friend/Friend'

export { NavBar, Filter, Error, Loader, Model, UserCard, Friend };
184 changes: 184 additions & 0 deletions Context/ChatApp.json

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions Context/ChatAppContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React, { useState, useEffect } from 'react'
import { useRouter } from 'next/router'

//INTERNAL IMPORT
import { CheckIfWalletConnected, connectWallet, connectingWithContract } from '@/Utils/apiFeature'

export const ChatAppContext = React.createContext();

export const ChatAppProvider = ({children}) => {
const title = "Hey Welcome to blockchain Chat App";

return(
<ChatAppContext.Provider value={{ title }}>
{children}
</ChatAppContext.Provider>
);
};
6 changes: 6 additions & 0 deletions Context/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//0x5FbDB2315678afecb367f032d93F642f64180aa3
import chatAppJSON from './ChatApp.json'

export const ChatAppAdress = "0x5FbDB2315678afecb367f032d93F642f64180aa3"

export const ChatAppABI = chatAppJSON.abi;
64 changes: 64 additions & 0 deletions Utils/apiFeature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { ethers } from 'ethers'
import Web3Modal from 'web3modal'

import { ChatAppAddress, ChatAppABI } from '@/Context/constants'

export const CheckIfWalletConnected = async()=>{
try {
if(!window.ethereum) return console.log("Install MateMask");

const accounts = await window.ethereum.request({
method: "eth_accounts",
});

const firstAccount = accounts[0];
return firstAccount;
}catch(error){
console.log("error");
}
}

export const connectWallet = async()=>{
try{
if(!window.ethereum) return console.log("Install MateMask");

const accounts = await window.ethereum.request({
method: "eth_requestAccounts",
});

const firstAccount = accounts[0];
return firstAccount;
}catch(error){
console.log(error)
}
}

const fetchContract = (signerOrProvider)=>
new ethers.Contract(ChatAppABI, ChatAppAddress, signerOrProvider);

export const connectingWithContract = async()=>{
try{
const web3modal = new Web3Modal();
const connection = await web3modal.connect();
const provider = new ethers.providers.Web3Provider(connection);
const signer = provider.getSigner();
const contract = fetchContract(signer);

return contract;
}catch(error){
console.log(error);
}
}

export const converTime = (time)=>{
const newTime = new Date(time.tonumber());

const realTime = newTime.getHours() + "/" +
newTime.getMinutes() + "/" +
newTime.getSeconds() + " Date:" +
newTime.getDate() + "/" +
(newTime.getMonth() + 1) + "/" +
newTime.getFullYear();

return realTime;
};
Loading

0 comments on commit 40c2d08

Please sign in to comment.