From 9ae5a6b88ef089683ec417890800afd5d7368f28 Mon Sep 17 00:00:00 2001 From: platfowner Date: Tue, 13 Aug 2024 10:21:32 +0900 Subject: [PATCH 1/4] Upgrade ain-js package to v1.13.0 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 10d758e..b41ab85 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "typescript": "^4.6.3" }, "dependencies": { - "@ainblockchain/ain-js": "^1.12.0", + "@ainblockchain/ain-js": "^1.13.0", "axios": "^0.26.1", "express": "^4.18.2", "fast-json-stable-stringify": "^2.1.0", diff --git a/yarn.lock b/yarn.lock index 9192036..ee1f14c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,10 +2,10 @@ # yarn lockfile v1 -"@ainblockchain/ain-js@^1.12.0": - version "1.12.0" - resolved "https://registry.yarnpkg.com/@ainblockchain/ain-js/-/ain-js-1.12.0.tgz#6bd2c051ae200b6a8eee28d175f14fa677f56e04" - integrity sha512-wsipsiVzgtAkNhBR04t/UlQ7nXnIt1MRU11kctYzCbFsz8YrVhrX6WM2kXxWEsm37KnmtsZkt7f6WgfO/JdM4Q== +"@ainblockchain/ain-js@^1.13.0": + version "1.13.0" + resolved "https://registry.yarnpkg.com/@ainblockchain/ain-js/-/ain-js-1.13.0.tgz#547a036385ac8ea2fb9a643cbf8151bf4c4b65ed" + integrity sha512-XFxbxamfoUbgh6iOUjIQZPduotEI32lsRZxYCjD5SGlQ/kXzdrZ9rz0EJCFoE0O/Nu6bawC7h96Jvc8M/xon0w== dependencies: "@ainblockchain/ain-util" "^1.2.1" "@types/node" "^12.7.3" From 9dc961ca42d10923c0b7d27d4dbd15bc83bb7f00 Mon Sep 17 00:00:00 2001 From: platfowner Date: Tue, 13 Aug 2024 10:22:37 +0900 Subject: [PATCH 2/4] Add custom client id parameter to connect() --- src/ainize.ts | 16 +++++++++++----- src/handlers/handler.ts | 8 ++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/ainize.ts b/src/ainize.ts index d85a180..24d19bc 100644 --- a/src/ainize.ts +++ b/src/ainize.ts @@ -36,21 +36,27 @@ export default class Ainize { /** * Login to ainize using AI Network account private key. - * @param {string} privateKey + * @param {string} privateKey The private key to initialize the AinModule with. + * @param {ConnectionCallback} ConnectionCallback The connection callback function. + * @param {DisconnectionCallback} disconnectionCallback The disconnection callback function. + * @param {string} customClientId The custom client id to set. */ - async login(privateKey: string, connectionCb?: ConnectionCallback, disconnectionCb?: DisconnectionCallback) { + async login(privateKey: string, connectionCb?: ConnectionCallback, disconnectionCb?: DisconnectionCallback, customClientId?: string) { this.ain.setDefaultAccount(privateKey); - await this.handler.connect(connectionCb, disconnectionCb); + await this.handler.connect(connectionCb, disconnectionCb, customClientId); console.log('login success! address:', await this.ain.getAddress()); } /** * Login to ainize using AIN Wallet Signer. + * @param {ConnectionCallback} ConnectionCallback The connection callback function. + * @param {DisconnectionCallback} disconnectionCallback The disconnection callback function. + * @param {string} customClientId The custom client id to set. */ - async loginWithSigner(connectionCb?: ConnectionCallback, disconnectionCb?: DisconnectionCallback) { + async loginWithSigner(connectionCb?: ConnectionCallback, disconnectionCb?: DisconnectionCallback, customClientId?: string) { const signer = new AinWalletSigner; this.ain.setSigner(signer); - await this.handler.connect(connectionCb, disconnectionCb); + await this.handler.connect(connectionCb, disconnectionCb, customClientId); console.log('login success! address: ', await this.ain.getAddress()); } diff --git a/src/handlers/handler.ts b/src/handlers/handler.ts index 6724c21..bbde682 100644 --- a/src/handlers/handler.ts +++ b/src/handlers/handler.ts @@ -24,9 +24,9 @@ export default class Handler { return this.ain.getEventManager().isConnected(); } - async connect(connectionCb?: ConnectionCallback, disconnectionCb?: DisconnectionCallback) { + async connect(connectionCb?: ConnectionCallback, disconnectionCb?: DisconnectionCallback, customClientId?: string) { this.checkEventManager(); - await this.ain.getEventManager().connect(connectionCb, this.connectionRetryCb.bind(this, connectionCb, disconnectionCb)); + await this.ain.getEventManager().connect(connectionCb, this.connectionRetryCb.bind(this, connectionCb, disconnectionCb, customClientId)); console.log('connected'); }; @@ -36,7 +36,7 @@ export default class Handler { console.log('Disconnected'); } - private async connectionRetryCb(connectionCb?: ConnectionCallback, disconnectionCb?: DisconnectionCallback, webSocket?: any) { + private async connectionRetryCb(connectionCb?: ConnectionCallback, disconnectionCb?: DisconnectionCallback, customClientId?: string, webSocket?: any) { try { if (disconnectionCb) { disconnectionCb(webSocket); @@ -44,7 +44,7 @@ export default class Handler { const address = await AinModule.getInstance().getAddress(); if (address) { console.log('Disconnected. Reconnecting...'); - await this.connect(connectionCb, disconnectionCb); + await this.connect(connectionCb, disconnectionCb, customClientId); } } catch (_) { return; From 915f939c6904b92297159317c509e578d8ae8f22 Mon Sep 17 00:00:00 2001 From: platfowner Date: Tue, 13 Aug 2024 10:23:31 +0900 Subject: [PATCH 3/4] Deprecate connection retry callback --- src/handlers/handler.ts | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/handlers/handler.ts b/src/handlers/handler.ts index bbde682..9cb81d7 100644 --- a/src/handlers/handler.ts +++ b/src/handlers/handler.ts @@ -26,7 +26,7 @@ export default class Handler { async connect(connectionCb?: ConnectionCallback, disconnectionCb?: DisconnectionCallback, customClientId?: string) { this.checkEventManager(); - await this.ain.getEventManager().connect(connectionCb, this.connectionRetryCb.bind(this, connectionCb, disconnectionCb, customClientId)); + await this.ain.getEventManager().connect(connectionCb, disconnectionCb, customClientId); console.log('connected'); }; @@ -36,21 +36,6 @@ export default class Handler { console.log('Disconnected'); } - private async connectionRetryCb(connectionCb?: ConnectionCallback, disconnectionCb?: DisconnectionCallback, customClientId?: string, webSocket?: any) { - try { - if (disconnectionCb) { - disconnectionCb(webSocket); - } - const address = await AinModule.getInstance().getAddress(); - if (address) { - console.log('Disconnected. Reconnecting...'); - await this.connect(connectionCb, disconnectionCb, customClientId); - } - } catch (_) { - return; - } - } - async subscribe(subscribePath: string, resolve: any) { this.checkEventManager(); From f37ac98b416638f6510d6107b18d32ec9644afa8 Mon Sep 17 00:00:00 2001 From: yoojinko Date: Wed, 14 Aug 2024 07:35:15 +0000 Subject: [PATCH 4/4] Upgrade version to 1.3.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d3e1e2c..b19c74f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ainize-team/ainize-js", - "version": "1.3.0", + "version": "1.3.1", "main": "dist/ainize.js", "types": "dist/ainize.d.ts", "scripts": {