Skip to content

Commit

Permalink
add frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
filipviz committed Feb 9, 2024
1 parent c4e350f commit 6498d7b
Show file tree
Hide file tree
Showing 6 changed files with 8,134 additions and 0 deletions.
24 changes: 24 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
13 changes: 13 additions & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Artizen Recovery</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/main.js"></script>
</body>
</html>
87 changes: 87 additions & 0 deletions frontend/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import './style.css'
import { createConfig, http, connect, switchChain, writeContract, waitForTransactionReceipt } from '@wagmi/core'
import { mainnet } from '@wagmi/core/chains'
import { injected } from '@wagmi/connectors'
import { parseAbi } from 'viem'

const currentTerminal = `0x1d9619E10086FdC1065B114298384aAe3F680CC0`
const artizenProjectId = 587n;
const recoveryTerminal = `0x0000000000000000000000000000000000000000`

document.querySelector('#app').innerHTML = `
<h1>Artizen Recovery</h1>
<div class="card">
<button id="connect">1. Connect</button>
<button id="migrate">2. Migrate</button>
<button id="payout">3. Payout</button>
</div>
<p id="statusText"></p>
`

const config = createConfig({
chains: [mainnet],
connectors: [injected()],
transports: {
[mainnet.id]: http(),
},
})

const connectButton = document.getElementById("connect")
const statusText = document.getElementById("statusText")

let result;
connectButton.onclick = async () => {
connectButton.innerText = "Connecting..."
result = await connect(config, {connector: injected()})
connectButton.innerText = "Connected"
statusText.innerText += `\nConnected to ${result.accounts[0]}.`

if (result.chainId !== 1) {
statusText.innerText += `\nWallet connected to wrong network. Switching to Ethereum mainnet...`
await switchChain(config, { chainId: 1 })
statusText.innerText += `\nSwitched to Ethereum mainnet.`
}
}

const migrateButton = document.getElementById("migrate")
migrateButton.onclick = async () => {
if (!result.accounts[0]) {
statusText.innerText += `\nConnect wallet first.`
return
}

statusText.innerText += `\nWaiting for migration transaction approval...`
const migrateTxHash = await writeContract(config, {
abi: parseAbi(["function migrate(uint256,address) returns (uint256)"]),
address: currentTerminal,
functionName: "migrate",
args: [artizenProjectId, recoveryTerminal],
})
statusText.innerText += `\nMigrating...`
const migrateReceipt = await waitForTransactionReceipt(config, {
hash: migrateTxHash
})

statusText.innerText += `\nMigration successful. Hash: ${migrateReceipt.transactionHash}`
}

const payoutButton = document.getElementById("payout")
payoutButton.onclick = async () => {
if (!result.accounts[0]) {
statusText.innerText += `\nConnect wallet first.`
return
}

statusText.innerText += `\nWaiting for payout transaction approval...`
const payoutTxHash = await writeContract(config, {
abi: parseAbi(["function distributePayoutsOf(uint256,uint256,uint256,address,uint256,bytes) returns (uint256)"]),
address: recoveryTerminal,
functionName: "distributePayoutsOf",
args: [artizenProjectId, 0n, 0n, "0x0000000000000000000000000000000000000000", 0n, "0x00"],
})
statusText.innerText += `\nSending payouts...`
const payoutReceipt = await waitForTransactionReceipt(config, {
hash: payoutTxHash
})
statusText.innerText += `\nPayout successful. Hash: ${payoutReceipt.transactionHash}`
}
19 changes: 19 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "frontend",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"vite": "^5.1.0"
},
"dependencies": {
"@wagmi/connectors": "^4.1.13",
"@wagmi/core": "^2.6.4",
"viem": "^2.7.8"
}
}
Loading

0 comments on commit 6498d7b

Please sign in to comment.