Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/gas fees set by user #1401

Merged
merged 3 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion main/provider/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import store from '../store'
import protectedMethods from '../api/protectedMethods'
import { usesBaseFee, TransactionData, GasFeesSource } from '../../resources/domain/transaction'
import { getAddress } from '../../resources/utils'
import FrameAccount from '../accounts/Account'

const permission = (date: number, method: string) => ({ parentCapability: method, date })

Expand All @@ -43,6 +42,7 @@ export function checkExistingNonceGas(tx: TransactionData) {
const bumpedBase = Math.max(Math.ceil((existingMax - existingFee) * 1.1), Math.ceil(maxInt - feeInt))
tx.maxFeePerGas = '0x' + (bumpedBase + bumpedFee).toString(16)
tx.maxPriorityFeePerGas = '0x' + bumpedFee.toString(16)
tx.gasFeesSource = GasFeesSource.Frame
tx.feesUpdated = true
}
} else if (tx.gasPrice) {
Expand All @@ -52,6 +52,7 @@ export function checkExistingNonceGas(tx: TransactionData) {
// Bump price by 10%
const bumpedPrice = Math.ceil(existingPrice * 1.1)
tx.gasPrice = '0x' + bumpedPrice.toString(16)
tx.gasFeesSource = GasFeesSource.Frame
tx.feesUpdated = true
}
}
Expand Down
2 changes: 1 addition & 1 deletion main/provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ export class Provider extends EventEmitter {
account: (currentAccount as FrameAccount).id,
origin: payload._origin,
approvals: [],
feesUpdatedByUser: feesUpdated || false,
feesUpdatedByUser: false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jamchello can you explain this change? seems like we're changing the functionality here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when the fees are updated by frame internally, this feesUpdated value is set to true - it is not indicative of the user updating the fees!

recipientType,
recognizedActions: []
} as Omit<TransactionRequest, 'classification'>
Expand Down
6 changes: 3 additions & 3 deletions test/main/provider/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ describe('#send', () => {
const replacementRequest = accountRequests[1]
const bumpedPrice = Math.ceil(initialPrice * 1.1)
expect(replacementRequest.data.gasPrice).toBe(intToHex(bumpedPrice))
expect(replacementRequest.feesUpdatedByUser).toBe(true)
expect(replacementRequest.feesUpdatedByUser).toBe(false)
done()
})
})
Expand Down Expand Up @@ -995,7 +995,7 @@ describe('#send', () => {

expect(replacementRequest.data.maxPriorityFeePerGas).toBe(intToHex(bumpedFee))
expect(replacementRequest.data.maxFeePerGas).toBe(intToHex(bumpedMax))
expect(replacementRequest.feesUpdatedByUser).toBe(true)
expect(replacementRequest.feesUpdatedByUser).toBe(false)
done()
})
})
Expand Down Expand Up @@ -1036,7 +1036,7 @@ describe('#send', () => {
const bumpedFee = Math.ceil(initialTip * 1.1)
expect(replacementRequest.data.maxPriorityFeePerGas).toBe(intToHex(bumpedFee))
expect(replacementRequest.data.maxFeePerGas).toBe(intToHex(20 * 1e9 + bumpedFee))
expect(replacementRequest.feesUpdatedByUser).toBe(true)
expect(replacementRequest.feesUpdatedByUser).toBe(false)
done()
})
})
Expand Down