From 6dd76ae4c69097c3e3bf86e6d62562b9eab11e80 Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 18 Jul 2024 09:01:48 +0900 Subject: [PATCH 1/5] Upgrade ain-js package to v1.12.0 --- package.json | 2 +- yarn.lock | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 6236bc8..10d758e 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "typescript": "^4.6.3" }, "dependencies": { - "@ainblockchain/ain-js": "^1.10.2", + "@ainblockchain/ain-js": "^1.12.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 8dba526..9192036 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,12 +2,12 @@ # yarn lockfile v1 -"@ainblockchain/ain-js@^1.10.2": - version "1.10.2" - resolved "https://registry.yarnpkg.com/@ainblockchain/ain-js/-/ain-js-1.10.2.tgz#c0ed1e230a6c2b3703169a5c243c173944004bdd" - integrity sha512-2lHYnvbjEHm3/K5Lw5wCNVBtj61Z1p1u+FbveXMg4vDCwUnuYwvCrtZjTxxv13MXHoJ6izdkkA3X93GWtQhpow== +"@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== dependencies: - "@ainblockchain/ain-util" "^1.1.9" + "@ainblockchain/ain-util" "^1.2.1" "@types/node" "^12.7.3" "@types/randombytes" "^2.0.0" "@types/semver" "^7.3.4" @@ -31,10 +31,10 @@ uuid "^3.3.3" ws "^8.16.0" -"@ainblockchain/ain-util@^1.1.9": - version "1.1.9" - resolved "https://registry.npmjs.org/@ainblockchain/ain-util/-/ain-util-1.1.9.tgz" - integrity sha512-u3q0h0zwWk+vzZ6VpBZiagVKJbNw/Dw4LVjBAhOvgPCx/E3jHHQCufIMDGqD4wjeBuHVtTAQyMTv7LRPSZFBGg== +"@ainblockchain/ain-util@^1.2.1": + version "1.2.1" + resolved "https://registry.yarnpkg.com/@ainblockchain/ain-util/-/ain-util-1.2.1.tgz#c5445f4718da0820c4955be44b07400172a864ef" + integrity sha512-++Sjv4PBT2/sdHeQNCDNb67ZIObxQnRQzILh+E72BUNnaEcS9cf9+4RC9I8JRqWkBiPvsD7oJPpMYYn0xwfECg== dependencies: bip39 "^3.0.4" bn.js "^4.11.8" From 62b0470508b6e577fea2a73328e69cefba966ed3 Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 18 Jul 2024 09:54:22 +0900 Subject: [PATCH 2/5] Support connection / disconnection callbacks in Handler --- src/handlers/handler.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/handlers/handler.ts b/src/handlers/handler.ts index accc820..09507f5 100644 --- a/src/handlers/handler.ts +++ b/src/handlers/handler.ts @@ -1,3 +1,4 @@ +import { ConnectionCallback, DisconnectionCallback } from "@ainblockchain/ain-js/lib/types"; import AinModule from "../ain"; import _ from "lodash"; @@ -23,9 +24,9 @@ export default class Handler { return this.ain.getEventManager().isConnected(); } - async connect() { + async connect(connectionCb?: ConnectionCallback, disconnectionCb?: DisconnectionCallback) { this.checkEventManager(); - await this.ain.getEventManager().connect(this.disconnectedCb.bind(this)); + await this.ain.getEventManager().connect(connectionCb, this.connectionRetry.bind(this, connectionCb, disconnectionCb)); console.log('connected'); }; @@ -35,12 +36,15 @@ export default class Handler { console.log('Disconnected'); } - private async disconnectedCb() { + private async connectionRetry(connectionCb?: ConnectionCallback, disconnectionCb?: DisconnectionCallback, webSocket?: any) { try { + if (disconnectionCb) { + disconnectionCb(webSocket); + } const address = await AinModule.getInstance().getAddress(); if (address) { console.log('Disconnected. Reconnecting...'); - await this.connect(); + await this.connect(connectionCb, disconnectionCb); } } catch (_) { return; From 6297ecf72f31f690f8c795a20c1b91ad57def18d Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 18 Jul 2024 09:59:08 +0900 Subject: [PATCH 3/5] Support connection / disconnection callbacks in Ainize --- src/ainize.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ainize.ts b/src/ainize.ts index ee765bd..d85a180 100644 --- a/src/ainize.ts +++ b/src/ainize.ts @@ -9,6 +9,7 @@ import AinModule from "./ain"; import Internal from "./internal"; import { Account } from "@ainblockchain/ain-util"; import { AinWalletSigner } from "@ainblockchain/ain-js/lib/signer/ain-wallet-signer"; +import { ConnectionCallback, DisconnectionCallback } from "@ainblockchain/ain-js/lib/types"; export default class Ainize { private cache: NodeCache; @@ -37,19 +38,19 @@ export default class Ainize { * Login to ainize using AI Network account private key. * @param {string} privateKey */ - async login(privateKey: string) { + async login(privateKey: string, connectionCb?: ConnectionCallback, disconnectionCb?: DisconnectionCallback) { this.ain.setDefaultAccount(privateKey); - await this.handler.connect(); + await this.handler.connect(connectionCb, disconnectionCb); console.log('login success! address:', await this.ain.getAddress()); } /** * Login to ainize using AIN Wallet Signer. */ - async loginWithSigner() { + async loginWithSigner(connectionCb?: ConnectionCallback, disconnectionCb?: DisconnectionCallback) { const signer = new AinWalletSigner; this.ain.setSigner(signer); - await this.handler.connect(); + await this.handler.connect(connectionCb, disconnectionCb); console.log('login success! address: ', await this.ain.getAddress()); } From 455ca141f30436cd368e0c82a0fa1736d7675679 Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 18 Jul 2024 10:33:11 +0900 Subject: [PATCH 4/5] Tweak a callback function name --- src/handlers/handler.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/handlers/handler.ts b/src/handlers/handler.ts index 09507f5..6724c21 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) { this.checkEventManager(); - await this.ain.getEventManager().connect(connectionCb, this.connectionRetry.bind(this, connectionCb, disconnectionCb)); + await this.ain.getEventManager().connect(connectionCb, this.connectionRetryCb.bind(this, connectionCb, disconnectionCb)); console.log('connected'); }; @@ -36,7 +36,7 @@ export default class Handler { console.log('Disconnected'); } - private async connectionRetry(connectionCb?: ConnectionCallback, disconnectionCb?: DisconnectionCallback, webSocket?: any) { + private async connectionRetryCb(connectionCb?: ConnectionCallback, disconnectionCb?: DisconnectionCallback, webSocket?: any) { try { if (disconnectionCb) { disconnectionCb(webSocket); From c9dd91038087cab7622df4589977e8e3a16b60b7 Mon Sep 17 00:00:00 2001 From: yoojinko Date: Fri, 19 Jul 2024 02:03:00 +0000 Subject: [PATCH 5/5] Upgrade version to 1.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 10d758e..18814c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ainize-team/ainize-js", - "version": "1.2.2", + "version": "1.3.0", "main": "dist/ainize.js", "types": "dist/ainize.d.ts", "scripts": {