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

add v1 version ledger app support #1437

Merged
merged 6 commits into from
Nov 26, 2024
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
11 changes: 11 additions & 0 deletions .yarn/versions/afe58fcb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
releases:
"@fluent-wallet/cfx_send-transaction": patch
"@fluent-wallet/cfx_sign-transaction": patch
"@fluent-wallet/test-helpers": patch
"@fluent-wallet/wallet_send-transaction": patch
"@fluent-wallet/wallet_send-transaction-with-action": patch
browser-extension: patch
helios-background: patch

declined:
- helios
37 changes: 28 additions & 9 deletions packages/rpcs/cfx_signTransaction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,6 @@ export const main = async args => {
const newTx = {...tx}
const network1559Compatible = await wallet_network1559Compatible()

if (!newTx.type) {
if (network1559Compatible) {
newTx.type = ETH_TX_TYPES.EIP1559
} else {
newTx.type = ETH_TX_TYPES.LEGACY
}
}

const fromAddr = findAddress({
appId: app && app.eid,
selected: _popup && !app ? true : undefined,
Expand All @@ -136,6 +128,33 @@ export const main = async args => {
// from address is not belong to wallet
if (!fromAddr) throw InvalidParams(`Invalid from address ${newTx.from}`)

/**
* ledger app check, v1.x is is not support 1559 transaction
* so we need check this app version
*/
let isV1LedgerAPP = false
if (fromAddr.account.accountGroup.vault.type === 'hw') {
// is hw wallet, we check is 1.x app version
const {Conflux: LedgerConflux} = await import('@fluent-wallet/ledger')
let ledger = new LedgerConflux()
// this call will establish a connection to the ledger device
const {version} = await ledger.getAppConfiguration()
if (version[0] === '1') {
isV1LedgerAPP = true
}
// disconnect from the ledger, if not disconnect will cause error when re-connect
await ledger.cleanUp()
ledger = null
}

if (!newTx.type) {
if (network1559Compatible && !isV1LedgerAPP) {
newTx.type = ETH_TX_TYPES.EIP1559
} else {
newTx.type = ETH_TX_TYPES.LEGACY
}
}

// tx without to must have data (deploy contract)
if (!newTx.to && !newTx.data)
throw InvalidParams(
Expand Down Expand Up @@ -193,7 +212,7 @@ export const main = async args => {
}
}

if (is1559Tx && network1559Compatible) {
if (is1559Tx && network1559Compatible && !isV1LedgerAPP) {
const gasInfoEip1559 = await cfx_estimate1559Fee()
const {suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas} =
gasInfoEip1559?.medium || {}
Expand Down
2 changes: 1 addition & 1 deletion packages/test-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"js-conflux-sdk": "2.1.2"
},
"devDependencies": {
"@xcfx/node": "0.0.7",
"@xcfx/node": "0.3.2",
"hardhat": "2.22.10"
}
}
8 changes: 4 additions & 4 deletions packages/test-helpers/setupNetwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ beforeAll(async () => {
await deployETHBalanceChecker()
confluxServer = await createServer({
// silent: false,
dev_block_interval_ms: 100,
mode: 'dev',
chain_id: CFX_LOCALNET_NETID,
genesis_secrets: [GENESIS_PRI_KEY],
devBlockIntervalMs: 100,
chainId: CFX_LOCALNET_NETID,
genesisSecrets: [GENESIS_PRI_KEY.replace(/^0x/, '')],
jsonrpcHttpPort: 12537,
})
await confluxServer.start()
await new Promise(resolve => setTimeout(resolve, 3000))
Expand Down
Loading
Loading