Skip to content

Commit

Permalink
fix: ledger EVM issues (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
meeh0w authored Oct 21, 2024
1 parent 53d2fda commit 50c351f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/background/services/actions/ActionsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class ActionsService implements OnStorageReady {
const isHandledByModule = pendingMessage[ACTION_HANDLED_BY_MODULE];

if (status === ActionStatus.SUBMITTING && isHandledByModule) {
this.approvalController.onApproved(pendingMessage);
await this.approvalController.onApproved(pendingMessage);
this.removeAction(id);
} else if (status === ActionStatus.SUBMITTING) {
const handler = this.dAppRequestHandlers.find((h) =>
Expand Down Expand Up @@ -183,7 +183,7 @@ export class ActionsService implements OnStorageReady {
status === ActionStatus.ERROR_USER_CANCELED &&
isHandledByModule
) {
this.approvalController.onRejected(pendingMessage);
await this.approvalController.onRejected(pendingMessage);
this.removeAction(id);
} else if (status === ActionStatus.ERROR_USER_CANCELED) {
await this.emitResult(
Expand Down
26 changes: 22 additions & 4 deletions src/pages/ApproveAction/components/DeviceApproval.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { satoshiToBtc } from '@avalabs/core-bridge-sdk';
import { RpcMethod, SigningData } from '@avalabs/vm-module-types';
import { TokenUnit } from '@avalabs/core-utils-sdk';

import { Action, ActionStatus } from '@src/background/services/actions/models';
import { NetworkWithCaipId } from '@src/background/services/network/models';
Expand All @@ -13,7 +14,7 @@ const getTxInfoForLedger = (
signingData: SigningData,
network: NetworkWithCaipId
) => {
if (signingData?.type === RpcMethod.BITCOIN_SEND_TRANSACTION) {
if (signingData.type === RpcMethod.BITCOIN_SEND_TRANSACTION) {
return {
amount: satoshiToBtc(signingData.data.amount).toFixed(8),
fee: satoshiToBtc(signingData.data.fee).toFixed(8),
Expand All @@ -23,9 +24,26 @@ const getTxInfoForLedger = (
};
}

throw new Error(
`Getting tx info for ledger not implemented yet for ${signingData?.type}`
);
if (signingData.type === RpcMethod.ETH_SEND_TRANSACTION) {
const { maxFeePerGas, gasPrice, gasLimit } = signingData.data;
const pricePerGas = maxFeePerGas ?? gasPrice ?? 0;
const feeBigInt = gasLimit ? BigInt(pricePerGas) * BigInt(gasLimit) : 0;
const fee = feeBigInt
? new TokenUnit(
feeBigInt,
network.networkToken.decimals,
network.networkToken.symbol
)
: undefined;

return {
fee: fee?.toString(),
feeSymbol: network.networkToken.symbol,
to: signingData.data.to as string,
};
}

return null;
};

export const DeviceApproval = ({
Expand Down

0 comments on commit 50c351f

Please sign in to comment.