Skip to content

Commit

Permalink
Update owner page
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusWentz committed Sep 20, 2024
1 parent 703890c commit 03ce0d1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 37 deletions.
12 changes: 6 additions & 6 deletions pages/owner.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</div>
</div>

<div class="container">
<!-- <div class="container">
<div style="min-height: 22vh">
<div class="row">
<div class="col text-center">
Expand All @@ -81,9 +81,9 @@
</div>
</div>
</div>
</div>
</div> -->

<div class="container">
<!-- <div class="container">
<div style="min-height: 10vh">
<div class="row">
<div class="col text-center">
Expand All @@ -92,10 +92,10 @@
</form>
</div>
</div>
</div>
</div> -->


<div class="container">
<!-- <div class="container">
<div style="min-height: 11vh">
<div class="row">
<div class="col text-center">
Expand All @@ -104,7 +104,7 @@
</form>
</div>
</div>
</div>
</div> -->

<div class="container">
<div class="row">
Expand Down
61 changes: 30 additions & 31 deletions scripts/owner.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function enableMetamaskOnGoerli() {
//Get account details from Metamask wallet.
getAccount();
//Check if user is on the Goerli testnet. If not, alert them to change to Goerli.
if(window.ethereum.networkVersion != 80001){
alert("You are not on the Mumbai Testnet! Please switch to Mumbai and refresh page.")
if(window.ethereum.networkVersion != 84532){
alert("You are not on the Base Sepolia Testnet! Please switch to Base Sepolia and refresh page.")
}
}

Expand All @@ -50,15 +50,14 @@ async function getAccount() {
//Make Metamask the client side Web3 provider. Needed for tracking live events.
const web3 = new Web3(window.ethereum)
//Now build the contract with Web3.
const gweiPumpAddress = "0xd27759C36967E299ef16df8FAac24D4adb21665c"
const gweiPumpABI =
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"msgValueTooSmall","type":"error"},{"inputs":[],"name":"notOwner","type":"error"},{"inputs":[],"name":"oraclePriceFeedZero","type":"error"},{"inputs":[],"name":"pumpNotFilled","type":"error"},{"inputs":[],"name":"upKeepNotNeeded","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"id","type":"bytes32"}],"name":"ChainlinkCancelled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"id","type":"bytes32"}],"name":"ChainlinkFulfilled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"id","type":"bytes32"}],"name":"ChainlinkRequested","type":"event"},{"anonymous":false,"inputs":[],"name":"oilBought","type":"event"},{"anonymous":false,"inputs":[],"name":"updateWti","type":"event"},{"inputs":[],"name":"Owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"Wti40Milliliters","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WtiPriceOracle","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"buyOil40Milliliters","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"chainlinkNodeRequestWtiPrice","outputs":[{"internalType":"bytes32","name":"requestId","type":"bytes32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"","type":"bytes"}],"name":"checkUpkeep","outputs":[{"internalType":"bool","name":"upkeepNeeded","type":"bool"},{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"erc20LINK","outputs":[{"internalType":"contract ERC20TokenContract","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_requestId","type":"bytes32"},{"internalType":"uint256","name":"memoryWtiPriceOracle","type":"uint256"}],"name":"fulfill","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getLatestMaticUsd","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLatestWtiMatic","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isPumpFilled","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastWtiPriceCheckUnixTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"manualUpKeep","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"status","type":"uint256"}],"name":"ownerPumpFilledStatus","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"","type":"bytes"}],"name":"performUpkeep","outputs":[],"stateMutability":"nonpayable","type":"function"}]
const gweiPumpAddress = "0x5c9E9e129dE558eCd87DaDa56CA8b058B562ee62";
const gweiPumpABI = [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"EmptyArgs","type":"error"},{"inputs":[],"name":"EmptySource","type":"error"},{"inputs":[],"name":"NoInlineSecrets","type":"error"},{"inputs":[],"name":"OnlyRouterCanFulfill","type":"error"},{"inputs":[{"internalType":"bytes32","name":"requestId","type":"bytes32"}],"name":"UnexpectedRequestID","type":"error"},{"inputs":[],"name":"etherNotSent","type":"error"},{"inputs":[],"name":"msgValueTooSmall","type":"error"},{"inputs":[],"name":"oraclePriceFeedZero","type":"error"},{"inputs":[],"name":"pumpNotFilled","type":"error"},{"inputs":[],"name":"upKeepNotNeeded","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"id","type":"bytes32"}],"name":"RequestFulfilled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"id","type":"bytes32"}],"name":"RequestSent","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"requestId","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"response","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"err","type":"bytes"}],"name":"Response","type":"event"},{"anonymous":false,"inputs":[],"name":"oilBought","type":"event"},{"anonymous":false,"inputs":[],"name":"updateWti","type":"event"},{"inputs":[],"name":"MAX_BPS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SCALE_FEE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"buyOil40Milliliters","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"getLatestEthUsdPennies","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLatestWtiEth","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getWti40Milliliters","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"requestId","type":"bytes32"},{"internalType":"bytes","name":"response","type":"bytes"},{"internalType":"bytes","name":"err","type":"bytes"}],"name":"handleOracleFulfillment","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"isPumpFilled","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastWtiPriceCheckUnixTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"status","type":"uint256"}],"name":"ownerPumpFilledStatus","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"s_lastError","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"s_lastRequestId","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"s_lastResponse","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint64","name":"subscriptionId","type":"uint64"},{"internalType":"string[]","name":"args","type":"string[]"}],"name":"sendRequest","outputs":[{"internalType":"bytes32","name":"requestId","type":"bytes32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"wtiUsdPenniesPriceOracle","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}];
const deployedGweiPump = new web3.eth.Contract(gweiPumpABI, gweiPumpAddress)

//Get the latest value.
deployedGweiPump.methods.isPumpFilled().call((err, isPumpFilledResponse) => {
if(isPumpFilledResponse === undefined){
document.getElementById("getPumpStatus").innerHTML = "Install Metamask and select Mumbai Testnet to have a Web3 provider to read blockchain data."
document.getElementById("getPumpStatus").innerHTML = "Install Metamask and select Base Sepolia Testnet to have a Web3 provider to read blockchain data."
}
else{
if(isPumpFilledResponse == "1"){
Expand All @@ -79,7 +78,7 @@ closePumpButton.addEventListener('click', () => {

async function closePump() {

let ownerAddress = await deployedGweiPump.methods.Owner().call();
let ownerAddress = await deployedGweiPump.methods.owner().call();

if(accounts[0].toLowerCase() != ownerAddress.toLowerCase() ) {
alert("WALLET ADDRESS CONNECTED IS NOT THE OWNER!")
Expand Down Expand Up @@ -118,7 +117,7 @@ openPumpButton.addEventListener('click', () => {

async function openPump() {

let ownerAddress = await deployedGweiPump.methods.Owner().call();
let ownerAddress = await deployedGweiPump.methods.owner().call();

if(accounts[0].toLowerCase() != ownerAddress.toLowerCase() ) {
alert("WALLET ADDRESS CONNECTED IS NOT THE OWNER!")
Expand Down Expand Up @@ -149,26 +148,26 @@ openPumpButton.addEventListener('click', () => {

});

// MODIFY CONTRACT STATE WITH SET FUNCTION WITH PREDEFINED DATA FROM WEB3.JS
const manualUpKeepButton = document.querySelector('.manualUpKeepButton');
manualUpKeepButton.addEventListener('click', () => {
checkAddressMissingMetamask()
manualUpKeep()

async function manualUpKeep() {
ethereum.request({
method: 'eth_sendTransaction',
params: [
{
from: accounts[0],
to: gweiPumpAddress,
data: deployedGweiPump.methods.manualUpKeep().encodeABI(),
},
],
})
.then((txHash) => console.log(txHash))
.catch((error) => console.error);
}


});
// // MODIFY CONTRACT STATE WITH SET FUNCTION WITH PREDEFINED DATA FROM WEB3.JS
// const manualUpKeepButton = document.querySelector('.manualUpKeepButton');
// manualUpKeepButton.addEventListener('click', () => {
// checkAddressMissingMetamask()
// manualUpKeep()

// async function manualUpKeep() {
// ethereum.request({
// method: 'eth_sendTransaction',
// params: [
// {
// from: accounts[0],
// to: gweiPumpAddress,
// data: deployedGweiPump.methods.manualUpKeep().encodeABI(),
// },
// ],
// })
// .then((txHash) => console.log(txHash))
// .catch((error) => console.error);
// }


// });

0 comments on commit 03ce0d1

Please sign in to comment.