@lombardini.io/dapp
Advanced tools
Comparing version 0.0.37 to 0.0.38
@@ -51,2 +51,3 @@ "use strict"; | ||
exports.broadcastInvoke = void 0; | ||
var dappErorrs_1 = require("./dappErorrs"); | ||
var waitTx_1 = require("./waitTx"); | ||
@@ -84,5 +85,6 @@ var isKeeper = function (signerOrKeeper) { return 'initialPromise' in signerOrKeeper; }; | ||
}); | ||
}); }); | ||
}); }) | ||
.catch(dappErorrs_1.dappErrorHandler); | ||
}; | ||
exports.broadcastInvoke = broadcastInvoke; | ||
//# sourceMappingURL=generic.js.map |
@@ -1,4 +0,4 @@ | ||
export { loginWithKeeper, loginWithKeeperErrors } from './keeper'; | ||
export { onKeeperUserChanged, loginWithKeeper, keeperErrors } from './keeper'; | ||
export { loginWithSigner } from './signer'; | ||
export * from './dappWrite'; | ||
export * from './dappRead'; |
@@ -13,6 +13,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.loginWithSigner = exports.loginWithKeeperErrors = exports.loginWithKeeper = void 0; | ||
exports.loginWithSigner = exports.keeperErrors = exports.loginWithKeeper = exports.onKeeperUserChanged = void 0; | ||
var keeper_1 = require("./keeper"); | ||
Object.defineProperty(exports, "onKeeperUserChanged", { enumerable: true, get: function () { return keeper_1.onKeeperUserChanged; } }); | ||
Object.defineProperty(exports, "loginWithKeeper", { enumerable: true, get: function () { return keeper_1.loginWithKeeper; } }); | ||
Object.defineProperty(exports, "loginWithKeeperErrors", { enumerable: true, get: function () { return keeper_1.loginWithKeeperErrors; } }); | ||
Object.defineProperty(exports, "keeperErrors", { enumerable: true, get: function () { return keeper_1.keeperErrors; } }); | ||
var signer_1 = require("./signer"); | ||
@@ -19,0 +20,0 @@ Object.defineProperty(exports, "loginWithSigner", { enumerable: true, get: function () { return signer_1.loginWithSigner; } }); |
@@ -253,3 +253,3 @@ export declare type KeeperAPI = WavesKeeper.API; | ||
export declare const keeperPromise: Promise<WavesKeeper.API | undefined>; | ||
export declare const loginWithKeeperErrors: { | ||
export declare const keeperErrors: { | ||
noKeeper: string; | ||
@@ -262,2 +262,6 @@ rejectedByUser: string; | ||
}; | ||
export declare const onKeeperUserChanged: (callback: (data: { | ||
oldUser: string | undefined; | ||
newUser: string | undefined; | ||
}) => any) => Promise<void>; | ||
export declare const loginWithKeeper: ({ chainId }: loginWithKeeperParams) => Promise<{ | ||
@@ -264,0 +268,0 @@ address: string; |
@@ -39,3 +39,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.loginWithKeeper = exports.loginWithKeeperErrors = exports.keeperPromise = void 0; | ||
exports.loginWithKeeper = exports.onKeeperUserChanged = exports.keeperErrors = exports.keeperPromise = void 0; | ||
exports.keeperPromise = new Promise(function (resolve) { return setTimeout(resolve, 300); }) | ||
@@ -48,3 +48,3 @@ .then(function () { | ||
}); | ||
exports.loginWithKeeperErrors = { | ||
exports.keeperErrors = { | ||
noKeeper: 'noKeeper', | ||
@@ -54,2 +54,30 @@ rejectedByUser: 'rejectedByUser', | ||
}; | ||
var onKeeperUserChanged = function (callback) { return __awaiter(void 0, void 0, void 0, function () { | ||
var keeper, oldUser; | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, exports.keeperPromise]; | ||
case 1: | ||
keeper = _b.sent(); | ||
if (!keeper) | ||
throw new Error(exports.keeperErrors.noKeeper); | ||
return [4 /*yield*/, keeper.publicState()]; | ||
case 2: | ||
oldUser = (_a = (_b.sent()).account) === null || _a === void 0 ? void 0 : _a.address; | ||
keeper.on("update", function (state) { | ||
var _a, _b, _c; | ||
if (oldUser != ((_a = state.account) === null || _a === void 0 ? void 0 : _a.address)) { | ||
callback({ | ||
oldUser: oldUser, | ||
newUser: (_b = state.account) === null || _b === void 0 ? void 0 : _b.address, | ||
}); | ||
oldUser = (_c = state.account) === null || _c === void 0 ? void 0 : _c.address; | ||
} | ||
}); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }; | ||
exports.onKeeperUserChanged = onKeeperUserChanged; | ||
var loginWithKeeper = function (_a) { | ||
@@ -65,11 +93,10 @@ var chainId = _a.chainId; | ||
if (!keeper) | ||
throw new Error(exports.loginWithKeeperErrors.noKeeper); | ||
throw new Error(exports.keeperErrors.noKeeper); | ||
return [4 /*yield*/, (keeper === null || keeper === void 0 ? void 0 : keeper.publicState().then(function (x) { | ||
console.log({ n: x.network }); | ||
if (chainId !== x.network.code) | ||
return Promise.reject(exports.loginWithKeeperErrors.wrongNetwork); | ||
return Promise.reject(exports.keeperErrors.wrongNetwork); | ||
return x.account; | ||
}).catch(function (e) { | ||
if ((e === null || e === void 0 ? void 0 : e.code) === "10" || (e === null || e === void 0 ? void 0 : e.code) === "12") { | ||
return Promise.reject(exports.loginWithKeeperErrors.rejectedByUser); | ||
return Promise.reject(exports.keeperErrors.rejectedByUser); | ||
} | ||
@@ -76,0 +103,0 @@ if (typeof e === 'string') |
{ | ||
"name": "@lombardini.io/dapp", | ||
"version": "0.0.37", | ||
"version": "0.0.38", | ||
"description": "lombardini.io smart contract interactions", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -106,3 +106,3 @@ ## Breaking change v0.0.26 | ||
```typescript | ||
import { loginWithKeeper, loginWithKeeperErrors, dappWrite, dappRead } from '@lombardini.io/dapp' | ||
import { loginWithKeeper, keeperErrors, dappWrite, dappRead } from '@lombardini.io/dapp' | ||
@@ -122,9 +122,9 @@ function loginWithKeeperAndDeposit() { | ||
}).catch(e => { | ||
if (e === loginWithKeeperErrors.wrongNetwork) { | ||
if (e === keeperErrors.wrongNetwork) { | ||
console.log("Oops wrong network") | ||
} | ||
if (e === loginWithKeeperErrors.rejectedByUser) { | ||
if (e === keeperErrors.rejectedByUser) { | ||
console.log("User rejected") | ||
} | ||
if (e === loginWithKeeperErrors.noKeeper) { | ||
if (e === keeperErrors.noKeeper) { | ||
console.log("Please install keeper") | ||
@@ -136,2 +136,11 @@ } | ||
} | ||
``` | ||
## user changed example | ||
```typescript | ||
import { onKeeperUserChanged } from '@lombardini.io/dapp' | ||
onKeeperUserChanged(data => { | ||
console.log(data) //{oldUser: undefined, newUser: "3MMrvig4ecUF2w4ts7hVpYb65LDdbge5YBH"} | ||
}) | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64785
26
1001
143