Skip to content

Commit

Permalink
export fixes and logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Egge21M committed Jun 17, 2024
1 parent baad729 commit 4c9c1a7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/WSConnection.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { MessageQueue } from './utils';
import { JsonRpcErrorObject, JsonRpcMessage, JsonRpcReqParams, RpcSubId } from './model/types';

type Command = 'check_quote' | 'check_proof';

let _WS: typeof WebSocket;

if (typeof WebSocket !== 'undefined') {
Expand Down Expand Up @@ -49,7 +47,9 @@ export class WSConnection {
sendRequest(params: JsonRpcReqParams) {
const id = this.rpcId;
this.rpcId++;
this.ws?.send(JSON.stringify({ jsonrpc: '2.0', method: 'sub', params, id: id }));
const message = JSON.stringify({ jsonrpc: '2.0', method: 'sub', params, id });
console.log(message);
this.ws?.send(message);
}

closeSubscription(subId: string) {
Expand Down Expand Up @@ -92,6 +92,7 @@ export class WSConnection {
let parsed;
try {
parsed = JSON.parse(message) as JsonRpcMessage;
console.log(parsed);
if ('result' in parsed && parsed.id != undefined) {
if (this.rpcListeners[parsed.id]) {
this.rpcListeners[parsed.id].callback();
Expand Down Expand Up @@ -128,7 +129,7 @@ export class WSConnection {
callback: () => any,
errorCallback: (e: Error) => any
) {
if (this.ws?.readyState === 1) {
if (this.ws?.readyState !== 1) {
return errorCallback(new Error('Socket is not open'));
}
const subId = (Math.random() + 1).toString(36).substring(7);
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CashuMint } from './CashuMint.js';
import { CashuWallet } from './CashuWallet.js';
import { WSConnection } from './WSConnection.js';
import { setGlobalRequestOptions } from './request.js';
import { generateNewMnemonic, deriveSeedFromMnemonic } from './secrets.js';
import { getEncodedToken, getDecodedToken, deriveKeysetId } from './utils.js';
Expand Down
2 changes: 1 addition & 1 deletion src/model/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ type JsonRpcParams = any;

export type JsonRpcReqParams = {
kind: RpcSubKinds;
filter: Array<string>;
filters: Array<string>;
subId: string;
};

Expand Down

0 comments on commit 4c9c1a7

Please sign in to comment.