Skip to content

Commit

Permalink
Merge pull request #9 from ava-labs/fixes
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
rajranjan0608 authored May 24, 2022
2 parents bfeee57 + 6ed8e49 commit 5c38adf
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 20 deletions.
10 changes: 5 additions & 5 deletions client/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />


<meta name="description" content="Avalanche Faucet is a place where you can get free test tokens to play with, on the Avalanche's Fuji Network and other Subnets">
<meta name="description" content="Get testnet tokens to use on the Avalanche Fuji Network (testnet) or a Subnet (WAGMI, Defi Kingdoms, Dexalot, Swimmer, and Castle Crush) in one place.">
<meta name="keywords" content="Avalanche, AVAX, Faucet, Fuji, Testnet">

<meta property="og:title" content="Faucet for the Avalanche Testnet">
<meta property="og:title" content="Avalanche Faucet">
<meta property="og:site_name" content="Faucet | Avalanche">
<meta property="og:url" content="https://faucet.avax-test.network/">
<meta property="og:description" content="Avalanche Faucet is a place where you can get free test tokens to play with, on the Avalanche's Fuji Network and other Subnets">
<meta property="og:url" content="https://faucet.avax.network/">
<meta property="og:description" content="Get testnet tokens to use on the Avalanche Fuji Network (testnet) or a Subnet (WAGMI, Defi Kingdoms, Dexalot, Swimmer, and Castle Crush) in one place.">
<meta property="og:type" content="website">

<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>Faucet | Avalanche</title>
</head>
<body style="background-color: #000000; background-image: linear-gradient(315deg, #000000 0%, #414141 100%);">
<body style="background: no-repeat center center fixed; background-image: linear-gradient(315deg, #000000 0%, #414141 100%);">
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
Expand Down
7 changes: 7 additions & 0 deletions client/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@
display: flex;
justify-content: space-around;
align-items: center;
}

@media screen and (max-width: 1010px) {
.app {
padding-top: 10%;
padding-bottom: 10%;
}
}
2 changes: 1 addition & 1 deletion client/src/components/AddNetwork.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function AddNetwork(props: any) {
<div className='footer-buttons'>
<button className="add-network" onClick={() => {addNetwork(props.config)}}>
<img style={{width: "25px", height: "25px", marginRight: "5px"}} src="/memtamask.png"/>
Add Chain to Metamask
Add Subnet to Metamask
</button>

<button className="add-network" onClick={() => {window.open(`${props.config.EXPLORER}`, '_blank')}}>
Expand Down
11 changes: 9 additions & 2 deletions client/src/components/Contribute.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { useState, useEffect } from 'react';
import './styles/Contribute.css'

const Contribute = () => {
const [hiddenClass, setHiddenClass] = useState('')

setTimeout(() => {
setHiddenClass("hide-button")
}, 2000);

return (
<div className="contribute-button" onClick={() => {window.open('https://github.com/ava-labs/avalanche-faucet', '_blank')}}>
<img style={{width: "25px", height: "25px", marginRight: "10px"}} src="/github.png"/>
<div className={`contribute-button ${hiddenClass}`} onClick={() => {window.open('https://github.com/ava-labs/avalanche-faucet', '_blank')}}>
<img src="/github.png"/>
Contribute on Github
</div>
)
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/FaucetForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ const FaucetForm = (props: any) => {
updateAddress(query?.address);
}

if(typeof query?.chain == "string") {
setChain(chainToIndex(query.chain))
if(typeof query?.subnet == "string") {
setChain(chainToIndex(query.subnet))
} else {
setChain(0)
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/FooterBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function FooterBox(props: any) {
<div className="footer-box">
<div style={{fontSize: "13px", padding: "20px"}}>
Use the buttons below to add <b>{props.chainConfigs[props.chain!]?.NAME}</b> to your browser wallet extension
or visit the chain's block explorer.
or visit the Subnet's block explorer.
<AddNetwork config={props.chainConfigs[props.chain!]}/>
</div>
</div>
Expand Down
36 changes: 34 additions & 2 deletions client/src/components/styles/Contribute.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.contribute-button {
position: absolute;
position: fixed;
top: 30px;
right: 20px;
padding: 10px;
Expand All @@ -9,11 +9,43 @@
align-items: center;
justify-content: center;
border-radius: 15px;
background-color: #333;
background-color: rgb(39, 39, 39);
color: rgba(255, 255, 255, 0.7);
opacity: 0.8;
}

.contribute-button > img {
width: 25px;
height: 25px;
margin-right: 10px;
}

.contribute-button:hover {
background-color: black;
color: white;
}

@media screen and (max-width: 1010px) {
.contribute-button {
position: fixed;
display: flex;
flex-direction: row-reverse;
top: auto;
bottom: 10px;
left: 20px;
}

.contribute-button > img {
margin-right: 0px;
margin-left: 10px;
}

.hide-button {
transition: 4s;
transform: translateX(-190px);
}

.hide-button:hover {
transform: translateX(0px);
}
}
12 changes: 6 additions & 6 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
{
"ID": "WAGMI",
"NAME": "WAGMI",
"NAME": "WAGMI Testnet",
"TOKEN": "WGM",
"RPC": "https://subnets.avax.network/wagmi/wagmi-chain-testnet/rpc",
"CHAINID": 11111,
Expand All @@ -45,7 +45,7 @@
},
{
"ID": "DFK",
"NAME": "Defi Kingdoms",
"NAME": "DeFi Kingdoms Testnet",
"TOKEN": "JEWEL",
"RPC": "https://subnets.avax.network/defi-kingdoms/dfk-chain-testnet/rpc",
"CHAINID": 335,
Expand All @@ -61,7 +61,7 @@
},
{
"ID": "DEXALOT",
"NAME": "Dexalot",
"NAME": "Dexalot Testnet",
"TOKEN": "ALOT",
"RPC": "https://subnets.avax.network/dexalot/testnet/rpc",
"CHAINID": 432201,
Expand All @@ -77,14 +77,14 @@
},
{
"ID": "SWIMMER",
"NAME": "Swimmer",
"NAME": "Swimmer Testnet",
"TOKEN": "TUS",
"RPC": "https://subnets.avax.network/swimmer/testnet/rpc",
"CHAINID": 73771,
"EXPLORER": "https://subnets.avax.network/swimmer/testnet/explorer",
"IMAGE": "https://raw.githubusercontent.com/ava-labs/subnet-assets/main/chains/73771/chain-logo.png",
"MAX_PRIORITY_FEE": "2000000000",
"MAX_FEE": "100000000000",
"MAX_FEE": "4200000000000",
"DRIP_AMOUNT": 2000000000,
"RATELIMIT": {
"MAX_LIMIT": 1,
Expand All @@ -93,7 +93,7 @@
},
{
"ID": "CASTLECRUSH",
"NAME": "Castle Crush",
"NAME": "Castle Crush Testnet",
"TOKEN": "ACS",
"RPC": "https://subnets.avax.network/castle-crush/testnet/rpc",
"CHAINID": 31416,
Expand Down
33 changes: 32 additions & 1 deletion vms/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default class EVM {
account: any;
NAME: string;
DRIP_AMOUNT: number | BN;
LEGACY: boolean;
MAX_PRIORITY_FEE: string;
MAX_FEE: string;
RECALIBRATE: number;
Expand All @@ -31,6 +32,7 @@ export default class EVM {
this.MAX_PRIORITY_FEE = config.MAX_PRIORITY_FEE;
this.MAX_FEE = config.MAX_FEE;
this.RECALIBRATE = config.RECALIBRATE || 30;
this.LEGACY = false;

this.hasNonce = new Map();
this.hasError = new Map();
Expand All @@ -47,13 +49,26 @@ export default class EVM {
this.waitArr = [];
this.queue = [];

this.setupTransactionType();

this.recalibrateNonceAndBalance();

setInterval(() => {
this.recalibrateNonceAndBalance();
}, this.RECALIBRATE * 1000);
}

async setupTransactionType() {
try {
const baseFee = (await this.web3.eth.getBlock('latest')).baseFeePerGas
if(baseFee == undefined) {
this.LEGACY = true;
}
} catch(err: any) {
console.log("Error setting up transaction type")
}
}

async sendToken(receiver: string, cb: (param: SendTokenResponse) => void): Promise<void> {
if (!this.web3.utils.isAddress(receiver)) {
cb({ status: 400, message: "Invalid address! Please try again." });
Expand Down Expand Up @@ -147,7 +162,7 @@ export default class EVM {

async getTransaction(to: string, value: BN | number, nonce: number | undefined): Promise<any> {
const tx: any = {
type: 2,
type: this.LEGACY ? 0 : 2,
gas: "21000",
nonce,
to,
Expand All @@ -156,6 +171,12 @@ export default class EVM {
value
};

if(this.LEGACY) {
delete tx["maxPriorityFeePerGas"];
delete tx["maxFeePerGas"];
tx.gasPrice = await this.getAdjustedGasPrice();
}

let signedTx;
try{
signedTx = await this.account.signTransaction(tx);
Expand All @@ -168,6 +189,16 @@ export default class EVM {
return { txHash, rawTransaction };
}

async getGasPrice(): Promise<number> {
return this.web3.eth.getGasPrice()
}

async getAdjustedGasPrice(): Promise<number> {
const gasPrice = await this.getGasPrice()
const adjustedGas = Math.floor(gasPrice * 1.25)
return Math.min(adjustedGas, parseInt(this.MAX_FEE))
}

async recalibrateNonceAndBalance(): Promise<void> {
this.waitingForRecalibration = true;

Expand Down

0 comments on commit 5c38adf

Please sign in to comment.