-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1723ab4
commit 40c2d08
Showing
9 changed files
with
1,124 additions
and
39 deletions.
There are no files selected for viewing
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,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 }; |
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
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> | ||
); | ||
}; |
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,6 @@ | ||
//0x5FbDB2315678afecb367f032d93F642f64180aa3 | ||
import chatAppJSON from './ChatApp.json' | ||
|
||
export const ChatAppAdress = "0x5FbDB2315678afecb367f032d93F642f64180aa3" | ||
|
||
export const ChatAppABI = chatAppJSON.abi; |
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,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; | ||
}; |
Oops, something went wrong.