Skip to content

Commit

Permalink
fix example
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyapotti committed Jul 9, 2024
1 parent 265ad68 commit d10fa2d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 77 deletions.
72 changes: 36 additions & 36 deletions demo/vite-react-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 29 additions & 33 deletions demo/vite-react-app/src/services/ethProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,36 @@ import { IWalletProvider } from "./walletProvider";
import { erc20Abi, storageSCAbi } from "../config/abi";

const ethProvider = (provider: IProvider, uiConsole: (...args: unknown[]) => void): IWalletProvider => {

const getTokenAddress = () => {
switch (provider.chainId) {
case "0x1":
case "0x89":
return "0x655F2166b0709cd575202630952D71E2bB0d61Af";
case "0x13882": // amoy
return "0x0Fd9e8d3aF1aaee056EB9e802c3A762a667b1904"
case "0xaa36a7": // sepolia
return "0x779877A7B0D9E8603169DdbD7836e478b4624789";
case "0x66eee": // arbitrum
return "0x3a12ea1bEa9b04f5541affBe1F6Dd83a72a9bbd7";
default:
return "";
}
}
const getTokenAddress = () => {
switch (provider.chainId) {
case "0x1":
case "0x89":
return "0x655F2166b0709cd575202630952D71E2bB0d61Af";
case "0x13882": // amoy
return "0x0Fd9e8d3aF1aaee056EB9e802c3A762a667b1904";
case "0xaa36a7": // sepolia
return "0x779877A7B0D9E8603169DdbD7836e478b4624789";
case "0x66eee": // arbitrum
return "0x3a12ea1bEa9b04f5541affBe1F6Dd83a72a9bbd7";
default:
return "";
}
};

const getStorageAddress = () => {
// simple default storage smart contract from remix.ethereum.org
switch (provider.chainId) {
case "0x1":
case "0x89":
return "";
case "0x13882": // amoy
case "0xaa36a7": // sepolia
case "0x66eee": // arbitrum
return "0xAD2709105e2b755b29DA45859d4E42A69cfADa12";
default:
return "";
}
}
switch (provider.chainId) {
case "0x1":
case "0x89":
return "";
case "0x13882": // amoy
case "0xaa36a7": // sepolia
case "0x66eee": // arbitrum
return "0xAD2709105e2b755b29DA45859d4E42A69cfADa12";
default:
return "";
}
};

const getAccounts = async () => {
try {
Expand Down Expand Up @@ -69,7 +68,6 @@ const ethProvider = (provider: IProvider, uiConsole: (...args: unknown[]) => voi
const balance = await contract.methods.balanceOf(accounts[0]).call();
uiConsole("Token balance", balance);
} else uiConsole("No Token Address for this blockchain");

} catch (error) {
console.error("Error", error);
uiConsole("error", error);
Expand All @@ -80,9 +78,8 @@ const ethProvider = (provider: IProvider, uiConsole: (...args: unknown[]) => voi
try {
const web3 = new Web3(provider);
const message = "Some string";
const hash = web3.utils.sha3(message) as string;
const fromAddress = (await web3.eth.getAccounts())[0];
const sig = await web3.eth.personal.sign(hash, fromAddress, "");
const sig = await web3.eth.personal.sign(message, fromAddress, "");
uiConsole("personal sign", sig);
uiConsole("Eth sign message => true", sig);
} catch (error) {
Expand Down Expand Up @@ -135,9 +132,8 @@ const ethProvider = (provider: IProvider, uiConsole: (...args: unknown[]) => voi
if (storageAddress !== "") {
const contract = new web3.eth.Contract(storageSCAbi, storageAddress);
const txRes = await contract.methods.retrieve().call();
uiConsole("txRes", txRes);
uiConsole("txRes", txRes);
} else uiConsole("No Smart Contract for this blockchain.");

} catch (error) {
console.log("error", error);
uiConsole("error", error);
Expand Down
3 changes: 1 addition & 2 deletions demo/vite-react-app/src/services/walletServiceProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ const walletServiceProvider = (provider: TorusInPageProvider, uiConsole: (...arg
try {
const web3 = new Web3(provider);
const message = "Some string";
const hash = web3.utils.sha3(message) as string;
const fromAddress = (await web3.eth.getAccounts())[0];
const sig = await web3.eth.personal.sign(hash, fromAddress, "");
const sig = await web3.eth.personal.sign(message, fromAddress, "");
uiConsole("personal sign", sig);
uiConsole("Eth sign message => true", sig);
} catch (error) {
Expand Down
6 changes: 0 additions & 6 deletions demo/vite-react-app/src/services/web3auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,6 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
walletInitOptions: {
whiteLabel: { showWidgetButton: true },
confirmationStrategy: "modal",
walletUrls: {
production: {
url: "http://localhost:4050",
logLevel: "debug",
},
},
},
});
subscribePluginEvents(walletServicesPlugin);
Expand Down

0 comments on commit d10fa2d

Please sign in to comment.