Skip to content

Commit

Permalink
Merge pull request #10 from consensys-vertical-apps/MMI-4561-add-sepo…
Browse files Browse the repository at this point in the history
…lia-testnet

chore: Adds sepolia buttons and logic
  • Loading branch information
zone-live authored Feb 21, 2024
2 parents 591782d + 51ca0ef commit 458872f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 30 deletions.
21 changes: 14 additions & 7 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,23 +187,30 @@ <h4 class="card-title">

<button
class="btn btn-primary btn-lg btn-block mb-3"
id="showMeTheMoneyButton_kovan"
id="showMeTheMoneyButton_goerli"
>
Show Me The Money (Kovan)
Show Me The Money (Goerli)
</button>

<button
class="btn btn-primary btn-lg btn-block mb-3"
id="showMeTheMoneyButton_goerli"
id="useSuperPowers_goerli"
>
Show Me The Money (Goerli)
Use Super Powers (Goerli)
</button>

<button
class="btn btn-primary btn-lg btn-block mb-3"
id="useSuperPowers_goerli"
id="showMeTheMoneyButton_sepolia"
>
Show Me The Money (Sepolia)
</button>

<button
class="btn btn-primary btn-lg btn-block mb-3"
id="useSuperPowers_sepolia"
>
Use Super Powers (Gorli)
Use Super Powers (Sepolia)
</button>
<p class="info-text alert alert-secondary">
Contract Status: <span id="contractStatus">Not clicked</span>
Expand Down Expand Up @@ -245,7 +252,7 @@ <h4 class="card-title">
class="btn btn-primary btn-lg btn-block mb-3"
id="approveTokens"
>
Approve Tokens (Goerli)
Approve Tokens
</button>

<button
Expand Down
75 changes: 52 additions & 23 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ let piggybankFactory

const NETWORKS = {
1: 'Mainnet',
4: 'Rinkeby',
5: 'Goerli',
42: 'Kovan',
11155111: 'Sepolia',
}

const currentUrl = new URL(window.location.href)
Expand Down Expand Up @@ -47,9 +46,10 @@ const permissionsResult = document.getElementById('permissionsResult')
const deployButton = document.getElementById('deployButton')
const depositButton = document.getElementById('depositButton')
const showMeTheMoneyButton = document.getElementById('showMeTheMoneyButton')
const showMeTheMoneyButtonKovan = document.getElementById('showMeTheMoneyButton_kovan')
const showMeTheMoneyButtonGoerli = document.getElementById('showMeTheMoneyButton_goerli')
const useSuperPowersGoerli = document.getElementById('useSuperPowers_goerli')
const showMeTheMoneyButtonSepolia = document.getElementById('showMeTheMoneyButton_sepolia')
const useSuperPowersSepolia = document.getElementById('useSuperPowers_sepolia')
const withdrawButton = document.getElementById('withdrawButton')
const contractStatus = document.getElementById('contractStatus')

Expand Down Expand Up @@ -142,20 +142,23 @@ const initialize = async () => {
let accountButtonsInitialized = false

const tstTokenAdress = '0x722dd3F80BAC40c951b51BdD28Dd19d435762180'
const javierCoinAdressKovan = '0xF4312f38f1139C2aa1c1dA54EF38F9ef1628dcB9'
const johannCoinCoinAddressGoerli = '0x7603A62b21A85f5cD02baE3389F35F1AcBaB0Ab2'
const johannCoinCoinAddressSepolia = '0xfe7A0f0c76c136b9B438DCB27de9a1b618c016Fc'

const tokenContract = new ethers.Contract(tstTokenAdress, javierCoinAbi, ethersProvider.getSigner())

// eslint-disable-next-line camelcase
const tokenContract_kovan = new ethers.Contract(javierCoinAdressKovan, javierCoinAbi, ethersProvider.getSigner())

// eslint-disable-next-line camelcase
const tokenContract_goerli = new ethers.Contract(johannCoinCoinAddressGoerli, jhcAbi, ethersProvider.getSigner())

// eslint-disable-next-line camelcase
const hasOwnerContract_goerli = new ethers.Contract(johannCoinCoinAddressGoerli, hasAnOwnerAbi, ethersProvider.getSigner())

// eslint-disable-next-line camelcase
const tokenContract_sepolia = new ethers.Contract(johannCoinCoinAddressSepolia, jhcAbi, ethersProvider.getSigner())

// eslint-disable-next-line camelcase
const hasOwnerContract_sepolia = new ethers.Contract(johannCoinCoinAddressSepolia, hasAnOwnerAbi, ethersProvider.getSigner())

tokenAddress.innerText = tstTokenAdress.toString()

const isMetaMaskConnected = () => accounts && accounts.length > 0
Expand Down Expand Up @@ -202,13 +205,16 @@ const initialize = async () => {
showMeTheMoneyButtonGoerli.disabled = false
useSuperPowersGoerli.disabled = false
approveTokens.disabled = false
} else if (networkId === 42) {
showMeTheMoneyButtonKovan.disabled = false
} else if (networkId === 11155111) {
showMeTheMoneyButtonSepolia.disabled = false
useSuperPowersSepolia.disabled = false
approveTokens.disabled = false
} else {
showMeTheMoneyButton.disabled = NETWORKS[networkId] ? toogle : true
showMeTheMoneyButtonKovan.disabled = NETWORKS[networkId] ? toogle : true
showMeTheMoneyButtonGoerli.disabled = NETWORKS[networkId] ? toogle : true
useSuperPowersGoerli.disabled = NETWORKS[networkId] ? toogle : true
showMeTheMoneyButtonSepolia.disabled = NETWORKS[networkId] ? toogle : true
useSuperPowersSepolia.disabled = NETWORKS[networkId] ? toogle : true
approveTokens.disabled = NETWORKS[networkId] ? toogle : true
}
}
Expand Down Expand Up @@ -271,7 +277,7 @@ const initialize = async () => {
}
}

showMeTheMoneyButtonKovan.onclick = async () => {
showMeTheMoneyButtonGoerli.onclick = async () => {

const _accounts = await ethereum.request({
method: 'eth_accounts',
Expand All @@ -280,7 +286,7 @@ const initialize = async () => {
const toAddress = _accounts[0] // get from input
const actualAmount = '1000000000000000000' // 18 decimals
try {
const result = await tokenContract_kovan.showMeTheMoney(toAddress, actualAmount)
const result = await tokenContract_goerli.showMeTheMoney(toAddress, actualAmount)
console.log(result)
contractStatus.innerHTML = 'Called contract'
} catch (e) {
Expand All @@ -289,7 +295,20 @@ const initialize = async () => {
}
}

showMeTheMoneyButtonGoerli.onclick = async () => {
useSuperPowersGoerli.onclick = async () => {
try {
const result = await hasOwnerContract_goerli.useSuperPowers({
gasLimit: 50000,
})
console.log(result)
contractStatus.innerHTML = 'Called contract'
} catch (e) {
console.log(e)
contractStatus.innerHTML = e.message
}
}

showMeTheMoneyButtonSepolia.onclick = async () => {

const _accounts = await ethereum.request({
method: 'eth_accounts',
Expand All @@ -298,7 +317,7 @@ const initialize = async () => {
const toAddress = _accounts[0] // get from input
const actualAmount = '1000000000000000000' // 18 decimals
try {
const result = await tokenContract_goerli.showMeTheMoney(toAddress, actualAmount)
const result = await tokenContract_sepolia.showMeTheMoney(toAddress, actualAmount)
console.log(result)
contractStatus.innerHTML = 'Called contract'
} catch (e) {
Expand All @@ -307,9 +326,9 @@ const initialize = async () => {
}
}

useSuperPowersGoerli.onclick = async () => {
useSuperPowersSepolia.onclick = async () => {
try {
const result = await hasOwnerContract_goerli.useSuperPowers({
const result = await hasOwnerContract_sepolia.useSuperPowers({
gasLimit: 50000,
})
console.log(result)
Expand Down Expand Up @@ -398,8 +417,18 @@ const initialize = async () => {
*/

approveTokens.onclick = async () => {
let tokenContract = tokenContract_sepolia;

if(
Number(await ethereum.request({
method: 'eth_chainId',
})) === 5
) {
tokenContract = tokenContract_goerli;
}

try {
const result = await tokenContract_goerli.approve('0xfa7d31e376a785837496f2d27454a53520e23994', '70000', {
const result = await tokenContract.approve('0xfa7d31e376a785837496f2d27454a53520e23994', '70000', {
from: accounts[0],
gasLimit: 60000,
gasPrice: '20000000000',
Expand Down Expand Up @@ -938,7 +967,7 @@ const initialize = async () => {
}
}

function handleNewAccounts (newAccounts) {
function handleNewAccounts(newAccounts) {
accounts = newAccounts
accountsDiv.innerHTML = accounts
if (isMetaMaskConnected()) {
Expand All @@ -947,16 +976,16 @@ const initialize = async () => {
updateButtons()
}

function handleNewChain (chainId) {
function handleNewChain(chainId) {
chainIdDiv.innerHTML = chainId
}

function handleNewNetwork (networkId) {
function handleNewNetwork(networkId) {
networkDiv.innerHTML = `Currently on network ${networkId} (${NETWORKS[networkId]})`
updateButtons()
}

async function getNetworkAndChainId () {
async function getNetworkAndChainId() {
try {
const chainId = await ethereum.request({
method: 'eth_chainId',
Expand Down Expand Up @@ -998,14 +1027,14 @@ window.addEventListener('DOMContentLoaded', initialize)

// utils

function getPermissionsDisplayString (permissionsArray) {
function getPermissionsDisplayString(permissionsArray) {
if (permissionsArray.length === 0) {
return 'No permissions found.'
}
const permissionNames = permissionsArray.map((perm) => perm.parentCapability)
return permissionNames.reduce((acc, name) => `${acc}${name}, `, '').replace(/, $/u, '')
}

function stringifiableToHex (value) {
function stringifiableToHex(value) {
return ethers.utils.hexlify(Buffer.from(JSON.stringify(value)))
}

0 comments on commit 458872f

Please sign in to comment.