Skip to content

Commit f32c665

Browse files
author
camolezi
committed
Created component for changing/displat user name
1 parent 7e55753 commit f32c665

File tree

2 files changed

+101
-53
lines changed

2 files changed

+101
-53
lines changed

packages/react-app/src/App.jsx

+49-53
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useUserAddress } from "eth-hooks";
1010
import { useQuery, gql } from "@apollo/client";
1111
import { formatEther, parseEther } from "@ethersproject/units";
1212
import { useThemeSwitcher } from "react-css-theme-switcher";
13+
import { ethers } from "ethers";
1314
import {
1415
useExchangePrice,
1516
useGasPrice,
@@ -31,18 +32,18 @@ import PostView from "./views/PostView";
3132

3233
import GraphqlSign from "./GraphqlSign";
3334

34-
import { ethers } from 'ethers';
35-
import DecentralisedDonuts from "./contracts/DecentralisedDonuts.abi.js";
36-
import FictionalFinance from "./contracts/FictionalFinance.abi.js";
37-
import InterestingIguanas from "./contracts/InterestingIguanas.abi.js"
35+
import DisplayUser from "./components/User/DisplayUser";
36+
37+
// import DecentralisedDonuts from "./contracts/DecentralisedDonuts.abi.js";
38+
// import FictionalFinance from "./contracts/FictionalFinance.abi.js";
39+
// import InterestingIguanas from "./contracts/InterestingIguanas.abi.js"
3840

3941
const axios = require("axios");
4042

4143
const donutAddress = "0x6e6598Bd833c3ABf05dBb64c0FDfEd11e6881E26";
4244
const fictionalAddress = "0xD5BF303973Fef7B7821378E8aFE890BEd8b102f3";
4345
const iguanaAddress = "0x6845556EAbdB4a535B98746CB4A2ee4BF79C508e";
4446

45-
4647
/*
4748
Welcome to 🏗 scaffold-eth !
4849
@@ -252,48 +253,44 @@ function App(props) {
252253
</div>
253254
);
254255
}
255-
async function mintDonut() {
256-
257-
const provider = new ethers.providers.Web3Provider(window.ethereum);
258-
const signer = provider.getSigner()
259-
const contract = new ethers.Contract(donutAddress, DecentralisedDonuts, signer)
260-
try {
261-
const mint = await contract.mintToken();
262-
await mint.wait();
263-
console.log('1 Decentralised Donut minted')
264-
} catch (error) {
265-
console.error('Transaction Failed. Address already opted in?')
266-
}
267-
}
268-
269-
async function mintFictional() {
270-
271-
const provider = new ethers.providers.Web3Provider(window.ethereum);
272-
const signer = provider.getSigner()
273-
const contract = new ethers.Contract(fictionalAddress, FictionalFinance, signer)
274-
try {
275-
const mint = await contract.mintToken();
276-
await mint.wait();
277-
console.log('1 Fictional Finance Token minted')
278-
} catch (error) {
279-
console.error('Transaction Failed. Address already opted in?')
280-
}
281-
}
282-
283-
async function mintIguana() {
284-
285-
const provider = new ethers.providers.Web3Provider(window.ethereum);
286-
const signer = provider.getSigner()
287-
const contract = new ethers.Contract(iguanaAddress, InterestingIguanas, signer)
288-
try {
289-
const mint = await contract.mintToken();
290-
await mint.wait();
291-
console.log('1 Interesting Iguana minted')
292-
} catch (error) {
293-
console.error('Transaction Failed. Address already opted in?')
294-
}
295-
}
296-
256+
// async function mintDonut() {
257+
// const provider = new ethers.providers.Web3Provider(window.ethereum);
258+
// const signer = provider.getSigner();
259+
// const contract = new ethers.Contract(donutAddress, DecentralisedDonuts, signer);
260+
// try {
261+
// const mint = await contract.mintToken();
262+
// await mint.wait();
263+
// console.log("1 Decentralised Donut minted");
264+
// } catch (error) {
265+
// console.error("Transaction Failed. Address already opted in?");
266+
// }
267+
// }
268+
269+
// async function mintFictional() {
270+
// const provider = new ethers.providers.Web3Provider(window.ethereum);
271+
// const signer = provider.getSigner();
272+
// const contract = new ethers.Contract(fictionalAddress, FictionalFinance, signer);
273+
// try {
274+
// const mint = await contract.mintToken();
275+
// await mint.wait();
276+
// console.log("1 Fictional Finance Token minted");
277+
// } catch (error) {
278+
// console.error("Transaction Failed. Address already opted in?");
279+
// }
280+
// }
281+
282+
// async function mintIguana() {
283+
// const provider = new ethers.providers.Web3Provider(window.ethereum);
284+
// const signer = provider.getSigner();
285+
// const contract = new ethers.Contract(iguanaAddress, InterestingIguanas, signer);
286+
// try {
287+
// const mint = await contract.mintToken();
288+
// await mint.wait();
289+
// console.log("1 Interesting Iguana minted");
290+
// } catch (error) {
291+
// console.error("Transaction Failed. Address already opted in?");
292+
// }
293+
// }
297294

298295
const isSigner = injectedProvider && injectedProvider.getSigner && injectedProvider.getSigner()._isSigner;
299296

@@ -307,7 +304,7 @@ function App(props) {
307304
let extraLink = "";
308305
if (possibleTxId.indexOf("0x") == 0) {
309306
extraLink = (
310-
<a href={blockExplorer + "tx/" + possibleTxId} target="_blank">
307+
<a href={blockExplorer + "tx/" + possibleTxId} target="_blank" rel="noreferrer">
311308
view transaction on etherscan
312309
</a>
313310
);
@@ -460,7 +457,7 @@ function App(props) {
460457

461458
{display}
462459
<GraphqlSign injectedProvider={injectedProvider} userProvider={userProvider} address={address} />
463-
460+
<DisplayUser />
464461
<BrowserRouter>
465462
<Menu style={{ textAlign: "center" }} selectedKeys={[route]} mode="horizontal">
466463
<Menu.Item key="/">
@@ -489,8 +486,7 @@ function App(props) {
489486
setRoute("/faucet");
490487
}}
491488
to="/faucet"
492-
>
493-
</Link>
489+
/>
494490
</Menu.Item>
495491
</Menu>
496492

@@ -505,9 +501,9 @@ function App(props) {
505501

506502
<Route exact path="/faucet">
507503
<span>MINT</span>
508-
<button onClick={mintDonut}>Mint A Decentralised Donut</button>
504+
{/* <button onClick={mintDonut}>Mint A Decentralised Donut</button>
509505
<button onClick={mintFictional}>Mint A Fictional Finance Token</button>
510-
<button onClick={mintIguana}>Mint An Interesting Iguana</button>
506+
<button onClick={mintIguana}>Mint An Interesting Iguana</button> */}
511507
</Route>
512508

513509
<Route path="/">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/* eslint-disable jsx-a11y/control-has-associated-label */
2+
import React from "react";
3+
import { gql, useQuery, useMutation } from "@apollo/client";
4+
5+
const GET_USER_INFO = gql`
6+
query GetUserInfo {
7+
user {
8+
address
9+
name
10+
}
11+
}
12+
`;
13+
14+
const CHANGE_ADDRESS_NAME = gql`
15+
mutation ChangeAddressNameMutation($newName: String!) {
16+
changeAddressName(name: $newName) {
17+
address
18+
name
19+
}
20+
}
21+
`;
22+
23+
function DisplayUser() {
24+
const { loading, error, data } = useQuery(GET_USER_INFO);
25+
26+
const [changeName] = useMutation(CHANGE_ADDRESS_NAME);
27+
28+
if (data) {
29+
console.log("userData", data);
30+
return (
31+
<section>
32+
<h1>{data.user.name}</h1>
33+
<button
34+
type="button"
35+
onClick={() => {
36+
changeName({
37+
variables: {
38+
newName: "NEwUsername",
39+
},
40+
});
41+
}}
42+
>
43+
Change name
44+
</button>
45+
</section>
46+
);
47+
}
48+
49+
return <h1>Not connected</h1>;
50+
}
51+
52+
export default DisplayUser;

0 commit comments

Comments
 (0)