mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-04-15 07:29:04 +03:00
Removed OB socket.io
This commit is contained in:
@@ -7,7 +7,6 @@ import {
|
||||
addPoolSchema, adminPoolsListSchema,
|
||||
atomicSummarySchema,
|
||||
} from './schemas';
|
||||
import { OrionBlockchainSocketIO } from './ws';
|
||||
import redeemOrderSchema from '../OrionAggregator/schemas/redeemOrderSchema';
|
||||
import { sourceAtomicHistorySchema, targetAtomicHistorySchema } from './schemas/atomicHistorySchema';
|
||||
import { makePartial } from '../../utils';
|
||||
@@ -52,11 +51,8 @@ type AtomicSwapHistoryTargetQuery = AtomicSwapHistoryBaseQuery & {
|
||||
class OrionBlockchain {
|
||||
private readonly apiUrl: string;
|
||||
|
||||
readonly ws: OrionBlockchainSocketIO;
|
||||
|
||||
constructor(apiUrl: string) {
|
||||
this.apiUrl = apiUrl;
|
||||
this.ws = new OrionBlockchainSocketIO(`${apiUrl}/`);
|
||||
|
||||
this.getAtomicSwapAssets = this.getAtomicSwapAssets.bind(this);
|
||||
this.getAtomicSwapHistory = this.getAtomicSwapHistory.bind(this);
|
||||
@@ -350,6 +346,5 @@ class OrionBlockchain {
|
||||
);
|
||||
}
|
||||
|
||||
export * as ws from './ws';
|
||||
export * as schemas from './schemas';
|
||||
export { OrionBlockchain };
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
import io from 'socket.io-client';
|
||||
import { z } from 'zod';
|
||||
import balancesSchema from './schemas/balancesSchema';
|
||||
|
||||
const handleBalancesMessage = (
|
||||
rawData: unknown,
|
||||
updateData: (balancesData: z.infer<typeof balancesSchema>) => void,
|
||||
) => {
|
||||
const data = balancesSchema.parse(rawData);
|
||||
updateData(data);
|
||||
};
|
||||
|
||||
type UpdateBalanceDataHandler = (balancesData: z.infer<typeof balancesSchema>) => void;
|
||||
|
||||
export class OrionBlockchainSocketIO {
|
||||
private socket: typeof io.Socket;
|
||||
|
||||
constructor(orionBlockchainWSUrl: string) {
|
||||
const url = new URL(orionBlockchainWSUrl);
|
||||
// https://stackoverflow.com/questions/29511404/connect-to-socket-io-server-with-specific-path-and-namespace
|
||||
this.socket = io(url.origin, {
|
||||
path: `${url.pathname}socket.io`,
|
||||
transports: ['websocket'],
|
||||
autoConnect: false,
|
||||
});
|
||||
}
|
||||
|
||||
connect(updateDataHandler: UpdateBalanceDataHandler) {
|
||||
if (updateDataHandler) {
|
||||
this.socket.on('balanceChange', (data: unknown) => handleBalancesMessage(data, updateDataHandler));
|
||||
this.socket.on('balances', (data: unknown) => handleBalancesMessage(data, updateDataHandler));
|
||||
}
|
||||
this.socket.connect();
|
||||
}
|
||||
|
||||
close() {
|
||||
this.socket.removeAllListeners();
|
||||
this.socket.close();
|
||||
}
|
||||
|
||||
resetConnection() {
|
||||
// Because Orion Blockchain does not have a subscription / unsubscribe system
|
||||
// Only way to "unsubscribe" is reset connection
|
||||
this.socket.disconnect();
|
||||
this.socket.open();
|
||||
}
|
||||
|
||||
subscribeBalancesUpdate(walletAddress: string) {
|
||||
if (this.socket.connected) {
|
||||
this.socket.emit('clientAddress', walletAddress);
|
||||
} else {
|
||||
this.socket.on('connect', () => {
|
||||
this.socket.emit('clientAddress', walletAddress);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
updateAllBalances(walletAddress: string) {
|
||||
this.socket.emit('getAllBalances', walletAddress);
|
||||
}
|
||||
}
|
||||
|
||||
export * as schemas from './schemas';
|
||||
@@ -1,10 +0,0 @@
|
||||
import { z } from 'zod';
|
||||
import { makePartial } from '../../../../utils';
|
||||
|
||||
const balancesSchema = z.object({
|
||||
contractBalances: z.record(z.string()).transform(makePartial).optional(),
|
||||
walletBalances: z.record(z.string()).transform(makePartial),
|
||||
allowances: z.record(z.string()).transform(makePartial).optional(),
|
||||
});
|
||||
|
||||
export default balancesSchema;
|
||||
@@ -1 +0,0 @@
|
||||
export { default as balancesSchema } from './balancesSchema';
|
||||
Reference in New Issue
Block a user