Skip to content

Commit

Permalink
add a ledger wallet as an option on stellar wallets kit
Browse files Browse the repository at this point in the history
  • Loading branch information
jeesunikim committed Mar 5, 2025
1 parent c34f478 commit c9eae7d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/components/WalletKitContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import { createContext, useEffect, useMemo } from "react";
import { useStore } from "@/store/useStore";

import {
AlbedoModule,
FreighterModule,
HanaModule,
LobstrModule,
RabetModule,
StellarWalletsKit,
XBULL_ID,
allowAllModules,
xBullModule,
} from "@creit.tech/stellar-wallets-kit";
import { LedgerModule } from "@creit.tech/stellar-wallets-kit/modules/ledger.module";

Expand Down Expand Up @@ -79,7 +84,15 @@ export const WalletKitContextProvider = ({
return new StellarWalletsKit({
network: networkType,
selectedWalletId: XBULL_ID,
modules: [...allowAllModules(), new LedgerModule()],
modules: [
new AlbedoModule(),
new xBullModule(),
new FreighterModule(),
new LobstrModule(),
new RabetModule(),
new HanaModule(),
new LedgerModule(),
],
...(theme && {
buttonTheme: isDarkTheme
? {
Expand Down
27 changes: 25 additions & 2 deletions src/hooks/useSignWithExtensionWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,20 @@ export const useSignWithExtensionWallet = ({
setErrorMsg("");
};

const getErrorMsg = (error: any) =>
error?.message || error || "Something went wrong, please try again";
const getErrorMsg = (error: any) => {
const errorMessage =
error?.message || error || "Something went wrong, please try again";
const busyMessage = "is busy";

// Wallets Kit's Ledger returns a busy message as an error when the device is busy
// ex: TransportError: Ledger Device is busy (lock signHash)
// We don't want to show this error to the user
if (errorMessage.includes(busyMessage)) {
return "";
}

return errorMessage;
};

const signTx = useCallback(async () => {
if (isInProgress || !walletKitInstance?.walletKit) {
Expand All @@ -44,6 +56,11 @@ export const useSignWithExtensionWallet = ({

setIsInProgress(true);

const timeoutId = setTimeout(() => {
setErrorMsg("Transaction signing timed out after a minute ");
setIsInProgress(false);
}, 60000);

if (walletKitPubKey) {
try {
const result = await walletKitInstance.walletKit.signTransaction(
Expand All @@ -53,9 +70,12 @@ export const useSignWithExtensionWallet = ({
networkPassphrase,
},
);
clearTimeout(timeoutId);

setSignedTxXdr(result.signedTxXdr);
setSuccessMsg(SUCCESS_MSG);
} catch (error: any) {
clearTimeout(timeoutId);
if (error?.message) {
setErrorMsg(getErrorMsg(error));
}
Expand Down Expand Up @@ -83,6 +103,7 @@ export const useSignWithExtensionWallet = ({
);

if (result?.signedTxXdr) {
clearTimeout(timeoutId);
setSignedTxXdr(result.signedTxXdr);
setSuccessMsg(SUCCESS_MSG);
} else {
Expand All @@ -92,12 +113,14 @@ export const useSignWithExtensionWallet = ({
}
}
} catch (error: any) {
clearTimeout(timeoutId);
if (error?.message) {
setErrorMsg(getErrorMsg(error));
}
}
},
onClosed: () => {
clearTimeout(timeoutId);
setErrorMsg("The user closed the modal.");
},
});
Expand Down

0 comments on commit c9eae7d

Please sign in to comment.