Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronmgdr committed Oct 24, 2024
1 parent 0c38c0a commit 5014717
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
9 changes: 7 additions & 2 deletions libs/ledger-live-common/src/families/celo/hw-app-celo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import { LedgerEthTransactionResolution } from "@ledgerhq/hw-app-eth/lib/service
}
}

async determinePrice(txParams: CeloTx): Promise<void> {
async determineFees(txParams: CeloTx): Promise<void> {
const isModern = await this.isAppModern();
const {
connection: { setFeeMarketGas, gasPrice },
Expand All @@ -76,6 +76,10 @@ import { LedgerEthTransactionResolution } from "@ledgerhq/hw-app-eth/lib/service
}
}

/*
@dev refers to if the app signing supports modern transactions like eip1559. if not it only can sign
old celo-legacy transactions that no longer work on celo post L2 transition
*/
async isAppModern(): Promise<boolean> {
if (!this.config) {
this.config = this.getAppConfiguration();
Expand All @@ -86,7 +90,8 @@ import { LedgerEthTransactionResolution } from "@ledgerhq/hw-app-eth/lib/service

// this works for celo-legacy
// this is code written a long time ago in a galaxy far far away
// do not touch (pretty please)
// do not touch (pretty please)
// CAN BE REMOVED AFTER FEB 2025 (CELO L2 transition)
private async __dangerous__signTransactionLegacy(
path: string,
rawTxHex: string,
Expand Down
21 changes: 1 addition & 20 deletions libs/ledger-live-common/src/families/celo/signOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const signOperation: AccountBridge<Transaction, CeloAccount>["signOperati

await Promise.all([
celo.verifyTokenInfo(to!, chainId!),
celo.determinePrice(unsignedTransaction),
celo.determineFees(unsignedTransaction),
]);

const rlpEncodedTransaction = await celo.rlpEncodedTxForLedger(unsignedTransaction);
Expand Down Expand Up @@ -123,22 +123,3 @@ const parseSigningResponse = (
};

export default signOperation;

// copied from hw-eth
export const applyEIP155 = (vAsHex: string, chainId: number): number => {
const v = parseInt(vAsHex, 16);

if (v === 0 || v === 1) {
// if v is 0 or 1, it's already representing parity
return chainId * 2 + 35 + v;
} else if (v === 27 || v === 28) {
const parity = v - 27; // transforming v into 0 or 1 to become the parity
return chainId * 2 + 35 + parity;
}
// When chainId is lower than 109, hw-app-eth *can* return a v with EIP155 already applied
// e.g. bsc's chainId is 56 -> v then equals to 147/148
// optimism's chainId is 10 -> v equals to 55/56
// ethereum's chainId is 1 -> v equals to 0/1
// goerli's chainId is 5 -> v equals to 0/1
return v;
};

0 comments on commit 5014717

Please sign in to comment.