Skip to content

Commit

Permalink
fix: make getWalletServiceSupportedMethods a standard method
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Feb 22, 2024
1 parent 3cb549b commit 68f15ce
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 32 deletions.
9 changes: 6 additions & 3 deletions examples/nwc/client/get-wallet-service-supported-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ const nwcUrl =
(await rl.question("Nostr Wallet Connect URL (nostr+walletconnect://...): "));
rl.close();

const response = await nwc.NWCClient.getWalletServiceSupportedMethods(
nwc.NWCClient.parseWalletConnectUrl(nwcUrl),
);
const client = new nwc.NWCClient({
nostrWalletConnectUrl: nwcUrl,
});
const response = await client.getWalletServiceSupportedMethods();

console.info(response);

client.close();
53 changes: 24 additions & 29 deletions src/NWCClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,35 +181,6 @@ export class NWCClient {
return new NWCClient(options);
}

static async getWalletServiceSupportedMethods(
options?: ConstructorParameters<typeof NWCClient>[0],
): Promise<Nip47Method[]> {
const client = NWCClient.withNewSecret(options);
await client.relay.connect();

const events = await client.relay.list(
[
{
kinds: [13194],
limit: 1,
authors: [client.walletPubkey],
},
],
{
eoseSubTimeout: 10000,
},
);

client.relay.close();

if (!events.length) {
throw new Error("no info event (kind 13194) returned from relay");
}
const result = events[0].content;
// delimiter is " " per spec, but Alby NWC originally returned ","
return result.split(/[ |,]/g) as Nip47Method[];
}

constructor(options?: NewNWCClientOptions) {
if (options && options.nostrWalletConnectUrl) {
options = {
Expand Down Expand Up @@ -395,6 +366,30 @@ export class NWCClient {
});
}

async getWalletServiceSupportedMethods(): Promise<Nip47Method[]> {
await this._checkConnected();

const events = await this.relay.list(
[
{
kinds: [13194],
limit: 1,
authors: [this.walletPubkey],
},
],
{
eoseSubTimeout: 10000,
},
);

if (!events.length) {
throw new Error("no info event (kind 13194) returned from relay");
}
const result = events[0].content;
// delimiter is " " per spec, but Alby NWC originally returned ","
return result.split(/[ |,]/g) as Nip47Method[];
}

async getInfo(): Promise<Nip47GetInfoResponse> {
try {
const result = await this.executeNip47Request<Nip47GetInfoResponse>(
Expand Down

0 comments on commit 68f15ce

Please sign in to comment.