Skip to content

Commit

Permalink
Feat/approval transaction listener (#8104)
Browse files Browse the repository at this point in the history
* wip

* chore: clean

* chore: lint
  • Loading branch information
CremaFR authored Oct 15, 2024
1 parent 6ef0119 commit 2a9b922
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/six-ligers-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ledger-live-desktop": minor
---

exposed getTransaction to swapliveapp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import {
useRedirectToSwapHistory,
} from "../utils/index";
import FeesDrawerLiveApp from "./FeesDrawerLiveApp";

import { getNodeApi } from "@ledgerhq/coin-evm/api/node/index";
export class UnableToLoadSwapLiveError extends Error {
constructor(message: string) {
const name = "UnableToLoadSwapLiveError";
Expand Down Expand Up @@ -273,6 +273,49 @@ const SwapWebView = ({ manifest, liveAppUnavailable }: SwapWebProps) => {
);
});
},
"custom.getTransactionByHash": async ({
params,
}: {
params: {
transactionHash: string;
fromAccountId: string;
SWAP_VERSION: string;
};
}): Promise<
| {
hash: string;
blockHeight: number | undefined;
blockHash: string | undefined;
nonce: number;
gasUsed: string;
gasPrice: string;
value: string;
}
| {}
> => {
const realFromAccountId = getAccountIdFromWalletAccountId(params.fromAccountId);
if (!realFromAccountId) {
return Promise.reject(new Error(`accountId ${params.fromAccountId} unknown`));
}

const fromAccount = accounts.find(acc => acc.id === realFromAccountId);
if (!fromAccount) {
return Promise.reject(new Error(`accountId ${params.fromAccountId} unknown`));
}

const fromParentAccount = getParentAccount(fromAccount, accounts);
const mainAccount = getMainAccount(fromAccount, fromParentAccount);

const nodeAPI = getNodeApi(mainAccount.currency);

try {
const tx = await nodeAPI.getTransaction(mainAccount.currency, params.transactionHash);
return Promise.resolve(tx);
} catch (error) {
// not a real error, the node just didn't find the transaction yet
return Promise.resolve({});
}
},
"custom.swapRedirectToHistory": () => {
redirectToHistory();
},
Expand Down

0 comments on commit 2a9b922

Please sign in to comment.