diff --git a/modules/sdk-coin-flr/src/flr.ts b/modules/sdk-coin-flr/src/flr.ts index df933eadbe..908700b291 100644 --- a/modules/sdk-coin-flr/src/flr.ts +++ b/modules/sdk-coin-flr/src/flr.ts @@ -176,7 +176,10 @@ export class Flr extends AbstractEthLikeNewCoins { if (!txHex) { throw new Error('missing txHex in explain tx parameters'); } - if (params.crossChainType) { + // Avalanche atomic transactions are identified by their codec prefix (0x00000000). + // Auto-detect them so callers don't need to pass crossChainType explicitly. + const hexWithout0x = txHex.startsWith('0x') ? txHex.slice(2) : txHex; + if (params.crossChainType || hexWithout0x.startsWith('0000')) { return this.explainAtomicTransaction(txHex); } if (!params.feeInfo) { diff --git a/modules/sdk-coin-flr/test/unit/flr.ts b/modules/sdk-coin-flr/test/unit/flr.ts index 5aebc74a43..602fd28d2b 100644 --- a/modules/sdk-coin-flr/test/unit/flr.ts +++ b/modules/sdk-coin-flr/test/unit/flr.ts @@ -249,6 +249,19 @@ describe('flr', function () { txExplain.changeOutputs.should.be.empty(); }); + it('should explain an export in C transaction without crossChainType when hex is atomic', async function () { + const testData = EXPORT_C_TEST_DATA; + // Wallet platform may omit crossChainType; auto-detection via codec prefix must still return + // the recipient P-chain address so the UI can display it. + const txExplain = await tflrCoin.explainTransaction({ + txHex: testData.fullsigntxHex, + }); + txExplain.type.should.equal(TransactionType.Export); + const sortedPAddresses = testData.pAddresses.slice().sort().join('~'); + txExplain.outputs[0].address.should.equal(sortedPAddresses); + txExplain.outputAmount.should.equal(testData.amount); + }); + it('should throw error when missing txHex', async function () { await tflrCoin .explainTransaction({ crossChainType: 'export' } as ExplainTransactionOptions) diff --git a/modules/sdk-coin-flrp/test/unit/flrp.ts b/modules/sdk-coin-flrp/test/unit/flrp.ts index 6bd35b35be..74cb887464 100644 --- a/modules/sdk-coin-flrp/test/unit/flrp.ts +++ b/modules/sdk-coin-flrp/test/unit/flrp.ts @@ -282,6 +282,19 @@ describe('Flrp test cases', function () { txExplain.changeOutputs.should.be.empty(); }); + it('should explain a signed export from C-chain transaction and include recipient P-chain address', async () => { + const txExplain = await basecoin.explainTransaction({ txHex: EXPORT_IN_C.signedHex }); + + txExplain.type.should.equal(TransactionType.Export); + txExplain.outputs.should.be.an.Array(); + txExplain.outputs.length.should.equal(1); + // The recipient address must be the P-chain destination — not empty. + txExplain.outputs[0].address.should.be.a.String(); + txExplain.outputs[0].address.should.not.be.empty(); + txExplain.outputs[0].address.should.startWith('P-'); + txExplain.changeOutputs.should.be.empty(); + }); + it('should fail when transaction hex is not provided', async () => { await basecoin.explainTransaction({}).should.be.rejectedWith('missing transaction hex'); });