Skip to content
This repository has been archived by the owner on Dec 31, 2024. It is now read-only.

Commit

Permalink
Merge pull request #52 from FrederikBolding/eip1559-gas
Browse files Browse the repository at this point in the history
EIP 1559 gas estimation / type-2 transactions now generated by dashboard
  • Loading branch information
bowensanders authored Aug 18, 2021
2 parents 89c4cdb + 3ed9be9 commit e69d316
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
17 changes: 15 additions & 2 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@feathersjs/feathers": "^4.5.11",
"@feathersjs/socketio": "^4.5.11",
"@feathersjs/socketio-client": "^4.5.11",
"bignumber.js": "^9.0.1",
"compression": "^1.7.4",
"cors": "^2.8.5",
"ethers": "^4.0.48",
Expand Down
8 changes: 5 additions & 3 deletions src/components/DelayModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Modal from 'react-modal';

import Web3Button from './Web3Button';
import config from '../configuration';
import { sendTx } from '../eip1559';

const style = {
content: {
Expand Down Expand Up @@ -40,9 +41,10 @@ class DelayModal extends React.Component {
onClick={context => {
const contract = config.getContract(context);
if (contract) {
contract.methods
.delayPayment(this.props.delayId, this.state.seconds)
.send({ from: context.account });
sendTx(
context,
contract.methods.delayPayment(this.props.delayId, this.state.seconds),
);
}
this.props.handleClose();
}}
Expand Down
11 changes: 4 additions & 7 deletions src/components/PaymentsTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import config from '../configuration';
import Web3Button from './Web3Button';
import DelayModal from './DelayModal';
import DateLabel from './DateLabel';
import { sendTx } from '../eip1559';

const client = feathers();
client.configure(
Expand Down Expand Up @@ -187,9 +188,7 @@ class PaymentsTable extends Component {
onClick={context => {
const contract = config.getContract(context);
if (contract) {
contract.methods
.disburseAuthorizedPayment(row.ids)
.send({ from: context.account });
sendTx(context, contract.methods.disburseAuthorizedPayment(row.ids));
}
}}
text="Pay"
Expand Down Expand Up @@ -243,7 +242,7 @@ class PaymentsTable extends Component {
onClick={context => {
const contract = config.getContract(context);
if (contract) {
contract.methods.checkIn().send({ from: context.account });
sendTx(context, contract.methods.checkIn());
}
}}
text="Check In"
Expand All @@ -260,9 +259,7 @@ class PaymentsTable extends Component {
onClick={context => {
const contract = config.getContract(context);
if (contract) {
contract.methods
.disburseAuthorizedPayments(pendingPayments)
.send({ from: context.account });
sendTx(context, contract.methods.disburseAuthorizedPayments(pendingPayments));
}
}}
text="Disburse All Payments"
Expand Down
15 changes: 15 additions & 0 deletions src/eip1559.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// eslint-ignore
import BigNumber from 'bignumber.js';

export const estimateGasFees = async context => {
const block = await context.library.eth.getBlock('latest');
const baseFee = block.baseFeePerGas;
const maxFeePerGas = new BigNumber(baseFee).multipliedBy(2);
const maxPriorityFeePerGas = new BigNumber('3000000000');
return { maxFeePerGas, maxPriorityFeePerGas, type: '0x2' };
};

export const sendTx = async (context, tx) => {
const gas = await estimateGasFees(context);
tx.send({ from: context.account, ...gas });
};

0 comments on commit e69d316

Please sign in to comment.