Skip to content

Commit a27adee

Browse files
authored
Merge pull request #369 from charlesedeh021-cell/feat/hana-rabet-adapters-233
feat(wallet): add HanaAdapter implementation (#233)
2 parents 62d248b + 2913e53 commit a27adee

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

src/wallet/adapters/hana.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* Hana wallet adapter.
3+
*
4+
* Hana is a Stellar-compatible extension wallet.
5+
* Wraps the SWK instance provided by the consumer.
6+
*/
7+
8+
import { WalletType } from "../types";
9+
import type {
10+
WalletAdapter,
11+
SignTransactionInput,
12+
SWKInstance,
13+
} from "../types";
14+
import { ok, err, SorokitErrorCode } from "../../shared/response";
15+
import type { SorokitResult } from "../../shared/response";
16+
import { isBrowser } from "../../shared";
17+
import { swkSignTransaction, describeSignFailure } from "./swkSign";
18+
19+
function describeHanaFailure(action: "connection" | "signing", cause: unknown): string {
20+
return describeSignFailure("Hana", action, cause);
21+
}
22+
23+
export class HanaAdapter implements WalletAdapter {
24+
readonly walletType = WalletType.HANA;
25+
26+
constructor(private readonly kit: SWKInstance) {}
27+
28+
isAvailable(): boolean {
29+
return isBrowser();
30+
}
31+
32+
async connect(): Promise<SorokitResult<string>> {
33+
if (!this.isAvailable()) {
34+
return err(
35+
SorokitErrorCode.WALLET_BROWSER_ONLY,
36+
"Hana requires a browser environment.",
37+
);
38+
}
39+
try {
40+
const { address } = await this.kit.getAddress();
41+
return ok(address);
42+
} catch (cause) {
43+
return err(
44+
SorokitErrorCode.WALLET_CONNECT_FAILED,
45+
describeHanaFailure("connection", cause),
46+
cause,
47+
);
48+
}
49+
}
50+
51+
async disconnect(): Promise<SorokitResult<undefined>> {
52+
return ok(undefined);
53+
}
54+
55+
async signTransaction(
56+
input: SignTransactionInput,
57+
): Promise<SorokitResult<string>> {
58+
if (!this.isAvailable()) {
59+
return err(
60+
SorokitErrorCode.WALLET_BROWSER_ONLY,
61+
"Hana requires a browser environment.",
62+
);
63+
}
64+
return swkSignTransaction(this.kit, "Hana", input);
65+
}
66+
}

src/wallet/adapters/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { FreighterAdapter } from "./freighter";
22
export { XBullAdapter } from "./xbull";
33
export { LobstrAdapter } from "./lobstr";
4+
export { HanaAdapter } from "./hana";

0 commit comments

Comments
 (0)