Comparing version 3.3.0-beta.1 to 3.3.0-beta.2
# bitski | ||
## 3.3.0-beta.2 | ||
### Patch Changes | ||
- [#337](https://github.com/BitskiCo/bitski-js/pull/337) [`2cf0f7c`](https://github.com/BitskiCo/bitski-js/commit/2cf0f7c1c166fd9b5f572701017bc2cb9616912a) Thanks [@chronicIntrovert](https://github.com/chronicIntrovert)! - Clear tokens if parse error on SDK updates | ||
- Updated dependencies [[`eda0e52`](https://github.com/BitskiCo/bitski-js/commit/eda0e522110f8c7a7665d67d3a83cd976cd5d42c)]: | ||
- bitski-provider@2.0.0-beta.14 | ||
## 3.3.0-beta.1 | ||
@@ -4,0 +13,0 @@ |
@@ -38,3 +38,4 @@ import { ACCESS_TOKEN_KEY, ID_TOKEN_KEY, REFRESH_TOKEN_KEY } from '../constants'; | ||
loadTokensFromCache() { | ||
this.accessToken = Promise.resolve(this.store.getItem(this.accessTokenKey)).then((accessTokenString) => { | ||
this.accessToken = Promise.resolve(this.store.getItem(this.accessTokenKey)) | ||
.then((accessTokenString) => { | ||
const accessTokenResult = string.decode(accessTokenString); | ||
@@ -44,5 +45,19 @@ if (accessTokenResult.value) { | ||
} | ||
}) | ||
.catch(() => { | ||
console.log('Could not parse accessToken, setting to undefined'); | ||
return undefined; | ||
}); | ||
this.idToken = Promise.resolve(this.store.getItem(this.idTokenKey)).then((token) => string.decode(token).value); | ||
this.refreshToken = Promise.resolve(this.store.getItem(this.refreshTokenKey)).then((token) => string.decode(token).value); | ||
this.idToken = Promise.resolve(this.store.getItem(this.idTokenKey)) | ||
.then((token) => string.decode(token).value) | ||
.catch(() => { | ||
console.log('Could not parse idToken, setting to undefined'); | ||
return undefined; | ||
}); | ||
this.refreshToken = Promise.resolve(this.store.getItem(this.refreshTokenKey)) | ||
.then((token) => string.decode(token).value) | ||
.catch(() => { | ||
console.log('Could not parse refreshToken, setting to undefined'); | ||
return undefined; | ||
}); | ||
} | ||
@@ -49,0 +64,0 @@ persistTokenResponse(response) { |
@@ -139,3 +139,3 @@ import { createBitskiProvider, LocalStorageStore, } from 'bitski-provider'; | ||
createProvider(options = {}) { | ||
return createBitskiProvider(Object.assign(Object.assign({ clientId: this.clientId, getAccessToken: this.getCurrentAccessToken.bind(this), clearAccessToken: this.signOut.bind(this), getUser: async () => this.authProvider.getUserFromCache(), signerBaseUrl: options.webBaseUrl, transactionCallbackUrl: options.callbackURL }, options), { additionalHeaders: Object.assign({ 'X-CLIENT-VERSION': "bitski-sdk-v3.3.0-beta.1" }, options.additionalHeaders), prependMiddleware: undefined })); | ||
return createBitskiProvider(Object.assign(Object.assign({ clientId: this.clientId, getAccessToken: this.getCurrentAccessToken.bind(this), clearAccessToken: this.signOut.bind(this), getUser: async () => this.authProvider.getUserFromCache(), signerBaseUrl: options.webBaseUrl, transactionCallbackUrl: options.callbackURL }, options), { additionalHeaders: Object.assign({ 'X-CLIENT-VERSION': "bitski-sdk-v3.3.0-beta.2" }, options.additionalHeaders), prependMiddleware: undefined })); | ||
} | ||
@@ -142,0 +142,0 @@ onSignOut() { |
@@ -39,3 +39,3 @@ const BITSKI_SDK_URL = 'https://cdn.bitskistatic.com/js/sdk/v3.3/bitski.min.js'; | ||
export const loadScript = () => { | ||
// Ensure that we only attempt to load Stripe.js at most once | ||
// Ensure that we only attempt to load bitski.js at most once | ||
if (bitskiPromise !== null) { | ||
@@ -42,0 +42,0 @@ return bitskiPromise; |
@@ -0,1 +1,2 @@ | ||
import { EthMethod } from 'eth-provider-types'; | ||
import { toHex } from './-private/utils/numbers'; | ||
@@ -75,3 +76,3 @@ // gotta keep it within MAX_SAFE_INTEGER | ||
await provider.request({ | ||
method: "wallet_addEthereumChain" /* wallet_addEthereumChain */, | ||
method: EthMethod.wallet_addEthereumChain, | ||
params: [ | ||
@@ -85,3 +86,3 @@ { | ||
await provider.request({ | ||
method: "wallet_switchEthereumChain" /* wallet_switchEthereumChain */, | ||
method: EthMethod.wallet_switchEthereumChain, | ||
params: [{ chainId: toHex(network.chainId) }], | ||
@@ -88,0 +89,0 @@ }); |
@@ -41,3 +41,4 @@ "use strict"; | ||
loadTokensFromCache() { | ||
this.accessToken = Promise.resolve(this.store.getItem(this.accessTokenKey)).then((accessTokenString) => { | ||
this.accessToken = Promise.resolve(this.store.getItem(this.accessTokenKey)) | ||
.then((accessTokenString) => { | ||
const accessTokenResult = decoders_1.string.decode(accessTokenString); | ||
@@ -47,5 +48,19 @@ if (accessTokenResult.value) { | ||
} | ||
}) | ||
.catch(() => { | ||
console.log('Could not parse accessToken, setting to undefined'); | ||
return undefined; | ||
}); | ||
this.idToken = Promise.resolve(this.store.getItem(this.idTokenKey)).then((token) => decoders_1.string.decode(token).value); | ||
this.refreshToken = Promise.resolve(this.store.getItem(this.refreshTokenKey)).then((token) => decoders_1.string.decode(token).value); | ||
this.idToken = Promise.resolve(this.store.getItem(this.idTokenKey)) | ||
.then((token) => decoders_1.string.decode(token).value) | ||
.catch(() => { | ||
console.log('Could not parse idToken, setting to undefined'); | ||
return undefined; | ||
}); | ||
this.refreshToken = Promise.resolve(this.store.getItem(this.refreshTokenKey)) | ||
.then((token) => decoders_1.string.decode(token).value) | ||
.catch(() => { | ||
console.log('Could not parse refreshToken, setting to undefined'); | ||
return undefined; | ||
}); | ||
} | ||
@@ -52,0 +67,0 @@ persistTokenResponse(response) { |
@@ -145,3 +145,3 @@ "use strict"; | ||
createProvider(options = {}) { | ||
return (0, bitski_provider_1.createBitskiProvider)(Object.assign(Object.assign({ clientId: this.clientId, getAccessToken: this.getCurrentAccessToken.bind(this), clearAccessToken: this.signOut.bind(this), getUser: async () => this.authProvider.getUserFromCache(), signerBaseUrl: options.webBaseUrl, transactionCallbackUrl: options.callbackURL }, options), { additionalHeaders: Object.assign({ 'X-CLIENT-VERSION': "bitski-sdk-v3.3.0-beta.1" }, options.additionalHeaders), prependMiddleware: undefined })); | ||
return (0, bitski_provider_1.createBitskiProvider)(Object.assign(Object.assign({ clientId: this.clientId, getAccessToken: this.getCurrentAccessToken.bind(this), clearAccessToken: this.signOut.bind(this), getUser: async () => this.authProvider.getUserFromCache(), signerBaseUrl: options.webBaseUrl, transactionCallbackUrl: options.callbackURL }, options), { additionalHeaders: Object.assign({ 'X-CLIENT-VERSION': "bitski-sdk-v3.3.0-beta.2" }, options.additionalHeaders), prependMiddleware: undefined })); | ||
} | ||
@@ -148,0 +148,0 @@ onSignOut() { |
@@ -43,3 +43,3 @@ "use strict"; | ||
const loadScript = () => { | ||
// Ensure that we only attempt to load Stripe.js at most once | ||
// Ensure that we only attempt to load bitski.js at most once | ||
if (bitskiPromise !== null) { | ||
@@ -46,0 +46,0 @@ return bitskiPromise; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BitskiProviderShim = exports.createResponse = void 0; | ||
const eth_provider_types_1 = require("eth-provider-types"); | ||
const numbers_1 = require("./-private/utils/numbers"); | ||
@@ -79,3 +80,3 @@ // gotta keep it within MAX_SAFE_INTEGER | ||
await provider.request({ | ||
method: "wallet_addEthereumChain" /* wallet_addEthereumChain */, | ||
method: eth_provider_types_1.EthMethod.wallet_addEthereumChain, | ||
params: [ | ||
@@ -89,3 +90,3 @@ { | ||
await provider.request({ | ||
method: "wallet_switchEthereumChain" /* wallet_switchEthereumChain */, | ||
method: eth_provider_types_1.EthMethod.wallet_switchEthereumChain, | ||
params: [{ chainId: (0, numbers_1.toHex)(network.chainId) }], | ||
@@ -92,0 +93,0 @@ }); |
@@ -12,3 +12,3 @@ { | ||
}, | ||
"version": "3.3.0-beta.1", | ||
"version": "3.3.0-beta.2", | ||
"scripts": { | ||
@@ -26,3 +26,3 @@ "lint": "eslint . --cache", | ||
"@openid/appauth": "^1.2.6", | ||
"bitski-provider": "^2.0.0-beta.2", | ||
"bitski-provider": "^2.0.0-beta.14", | ||
"eth-provider-types": "^0.1.0-beta.1", | ||
@@ -29,0 +29,0 @@ "decoders": "^2.0.1" |
@@ -35,2 +35,5 @@ ## Bitski JS SDK | ||
loginButton.addEventListener('click', async () => { | ||
// This signs the user in for the first time, and sets `window.ethereum` to | ||
// the Bitski provider. After this has been called, you can initialize your | ||
// Dapp's instance of Web3/Ethers | ||
await bitski.signIn(); | ||
@@ -42,2 +45,4 @@ initializeDApp(); | ||
logoutButton.addEventListener('click', async () => { | ||
// This signs the user out and restores `window.ethereum` to whatever value it was | ||
// before (e.g. restoring browser extensions if they had injected themselves previously). | ||
await bitski.signOut(); | ||
@@ -47,2 +52,5 @@ }); | ||
document.addEventListener('load', async () => { | ||
// This signs the user in IF they have signed in before, and sets `window.ethereum` | ||
// to the Bitski provider. This should be called on page load BEFORE you initialize | ||
// your Dapp, so that `window.ethereum` is setup properly. | ||
await bitski.initialize(); | ||
@@ -49,0 +57,0 @@ initializeDApp(); |
@@ -53,4 +53,4 @@ import { TokenResponse } from '@openid/appauth'; | ||
public loadTokensFromCache(): void { | ||
this.accessToken = Promise.resolve(this.store.getItem(this.accessTokenKey)).then( | ||
(accessTokenString) => { | ||
this.accessToken = Promise.resolve(this.store.getItem(this.accessTokenKey)) | ||
.then((accessTokenString) => { | ||
const accessTokenResult = string.decode(accessTokenString); | ||
@@ -60,11 +60,21 @@ if (accessTokenResult.value) { | ||
} | ||
}, | ||
); | ||
}) | ||
.catch(() => { | ||
console.log('Could not parse accessToken, setting to undefined'); | ||
return undefined; | ||
}); | ||
this.idToken = Promise.resolve(this.store.getItem(this.idTokenKey)).then( | ||
(token) => string.decode(token).value, | ||
); | ||
this.refreshToken = Promise.resolve(this.store.getItem(this.refreshTokenKey)).then( | ||
(token) => string.decode(token).value, | ||
); | ||
this.idToken = Promise.resolve(this.store.getItem(this.idTokenKey)) | ||
.then((token) => string.decode(token).value) | ||
.catch(() => { | ||
console.log('Could not parse idToken, setting to undefined'); | ||
return undefined; | ||
}); | ||
this.refreshToken = Promise.resolve(this.store.getItem(this.refreshTokenKey)) | ||
.then((token) => string.decode(token).value) | ||
.catch(() => { | ||
console.log('Could not parse refreshToken, setting to undefined'); | ||
return undefined; | ||
}); | ||
} | ||
@@ -71,0 +81,0 @@ |
@@ -73,3 +73,3 @@ import type { BitskiSDK, ProviderOptions } from './-private/sdk'; | ||
export const loadScript = (): Promise<BitskiSDKConstructor | null> => { | ||
// Ensure that we only attempt to load Stripe.js at most once | ||
// Ensure that we only attempt to load bitski.js at most once | ||
if (bitskiPromise !== null) { | ||
@@ -76,0 +76,0 @@ return bitskiPromise; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1052535
21218
543