forked from Prompt-Hash-Stellar/prompt-hash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwallet.ts
More file actions
50 lines (43 loc) · 1.5 KB
/
Copy pathwallet.ts
File metadata and controls
50 lines (43 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import {
StellarWalletsKit,
WalletNetwork,
allowAllModules
} from "@creit.tech/stellar-wallets-kit";
import { Horizon } from "@stellar/stellar-sdk";
import { horizonUrl, stellarNetwork, stellarWalletNetwork } from "../lib/env";
// allowAllModules() returns an array containing albedo, freighter, etc.
// This prevents us from having to import them individually and hitting the "Missing Export" error.
export const kit: StellarWalletsKit = new StellarWalletsKit({
network: stellarWalletNetwork as WalletNetwork,
modules: allowAllModules(),
});
function getHorizonHost(mode: string) {
switch (mode) {
case "LOCAL":
case "FUTURENET":
case "TESTNET":
case "PUBLIC":
return horizonUrl;
default:
throw new Error(`Unknown Stellar network: ${mode}`);
}
}
export const fetchBalance = async (address: string) => {
const horizon = new Horizon.Server(getHorizonHost(stellarNetwork), {
allowHttp: stellarNetwork === "LOCAL",
});
try {
const { balances } = await horizon.accounts().accountId(address).call();
return { ok: true, balances };
} catch (e) {
// Re-throw the error so callers can handle it appropriately
console.error("Error fetching balance:", e);
throw e;
}
};
export type Balance = Awaited<ReturnType<typeof fetchBalance>>["balances"][number];
export const wallet = kit;
// Restore removed connectWallet export for backward compatibility
export const connectWallet = async (...args: any[]) => {
return (kit as any).openModal(...args);
};