diff --git a/package-lock.json b/package-lock.json index fe9a8fa..99816c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8679,8 +8679,9 @@ "integrity": "sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==" }, "bignumber.js": { - "version": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934", - "from": "git+https://github.com/frozeman/bignumber.js-nolookahead.git" + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.1.tgz", + "integrity": "sha512-IdZR9mh6ahOBv/hYGiXyVuyCetmGJhtYkqLBpTStdhEGjegpPlUawydyaF3pbIOFynJTpllEs+NP+CS9jKFLjA==" }, "binary-extensions": { "version": "1.13.0", @@ -13229,6 +13230,12 @@ "utf8": "^2.1.1", "xhr2": "*", "xmlhttprequest": "*" + }, + "dependencies": { + "bignumber.js": { + "version": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934", + "from": "git+https://github.com/frozeman/bignumber.js-nolookahead.git" + } } } } @@ -38674,6 +38681,12 @@ "utf8": "^2.1.1", "xhr2-cookies": "^1.1.0", "xmlhttprequest": "*" + }, + "dependencies": { + "bignumber.js": { + "version": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934", + "from": "git+https://github.com/frozeman/bignumber.js-nolookahead.git" + } } } } diff --git a/package.json b/package.json index 8094d50..7edaf7a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/components/DelayModal.jsx b/src/components/DelayModal.jsx index 5dc8c87..e91dc1d 100644 --- a/src/components/DelayModal.jsx +++ b/src/components/DelayModal.jsx @@ -4,6 +4,7 @@ import Modal from 'react-modal'; import Web3Button from './Web3Button'; import config from '../configuration'; +import { sendTx } from '../eip1559'; const style = { content: { @@ -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(); }} diff --git a/src/components/PaymentsTable.jsx b/src/components/PaymentsTable.jsx index dfc8d4a..15f213b 100644 --- a/src/components/PaymentsTable.jsx +++ b/src/components/PaymentsTable.jsx @@ -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( @@ -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" @@ -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" @@ -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" diff --git a/src/eip1559.js b/src/eip1559.js new file mode 100644 index 0000000..037e7ff --- /dev/null +++ b/src/eip1559.js @@ -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 }); +};