From 32b86e347181180aba0d9f40e7b39635e5ed9186 Mon Sep 17 00:00:00 2001 From: Aleix Date: Mon, 18 Sep 2023 12:20:52 +0200 Subject: [PATCH] Bugfix/rainbowkit buffer (#90) --- packages/rainbowkit-wallets/src/lib/oAuthWallet.tsx | 7 +++++-- packages/rainbowkit-wallets/src/oAuthWallet.ts | 4 ++-- .../rainbowkit-wallets/src/wagmi/localStorageConnector.ts | 1 + packages/rainbowkit-wallets/src/wagmi/oAuthConnector.ts | 5 ++++- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/rainbowkit-wallets/src/lib/oAuthWallet.tsx b/packages/rainbowkit-wallets/src/lib/oAuthWallet.tsx index e44319b1..d417cb30 100644 --- a/packages/rainbowkit-wallets/src/lib/oAuthWallet.tsx +++ b/packages/rainbowkit-wallets/src/lib/oAuthWallet.tsx @@ -7,17 +7,20 @@ import localStorageWallet from './localStorageWallet' */ export class oAuthWallet extends localStorageWallet { private oAuthServiceUrl: string + private oAuthServiceProvider: string private data: any private cancel: boolean = false - constructor(oAuthServiceUrl: string) { + constructor(oAuthServiceUrl: string, oAuthServiceProvider: string) { super() this.oAuthServiceUrl = oAuthServiceUrl + this.oAuthServiceProvider = oAuthServiceProvider } async create(): Promise { // Open the login popup - this.openLoginPopup(this.oAuthServiceUrl) + const url = this.oAuthServiceUrl + (this.oAuthServiceProvider ? `?provider=${this.oAuthServiceProvider}` : '') + this.openLoginPopup(url) // Create the event listener to receive the seed from the popup window.addEventListener('message', this.handlePopupMessage.bind(this)) diff --git a/packages/rainbowkit-wallets/src/oAuthWallet.ts b/packages/rainbowkit-wallets/src/oAuthWallet.ts index 693d6fbd..0ef4167f 100644 --- a/packages/rainbowkit-wallets/src/oAuthWallet.ts +++ b/packages/rainbowkit-wallets/src/oAuthWallet.ts @@ -1,9 +1,9 @@ import { oAuthConnector } from './wagmi/oAuthConnector' -export const oAuthWallet = ({ chains, name, options }: any) => ({ +export const oAuthWallet = ({ chains, name, iconUrl, options }: any) => ({ id: 'oAuth', name: name || 'OAuth', - iconUrl: 'https://i.ibb.co/Mh7LXsn/social-login-COLOR-2.png', + iconUrl: iconUrl || 'https://i.ibb.co/Mh7LXsn/social-login-COLOR-2.png', iconBackground: '#fff', createConnector: () => { const connector = new oAuthConnector({ diff --git a/packages/rainbowkit-wallets/src/wagmi/localStorageConnector.ts b/packages/rainbowkit-wallets/src/wagmi/localStorageConnector.ts index 9c9daca4..e5ee450d 100644 --- a/packages/rainbowkit-wallets/src/wagmi/localStorageConnector.ts +++ b/packages/rainbowkit-wallets/src/wagmi/localStorageConnector.ts @@ -81,6 +81,7 @@ export class localStorageConnector extends Connector { } async disconnect(): Promise { + this.wallet = undefined localStorageWallet.deleteWallet() } diff --git a/packages/rainbowkit-wallets/src/wagmi/oAuthConnector.ts b/packages/rainbowkit-wallets/src/wagmi/oAuthConnector.ts index 7df6f096..8f5a66c8 100644 --- a/packages/rainbowkit-wallets/src/wagmi/oAuthConnector.ts +++ b/packages/rainbowkit-wallets/src/wagmi/oAuthConnector.ts @@ -10,18 +10,21 @@ export class oAuthConnector extends localStorageConnector { readonly name = 'OAuth' private oAuthServiceUrl: string = '' + private oAuthServiceProvider: string = '' constructor(config: { chains: Chain[]; options: any }) { super(config) if (!config.options.oAuthServiceUrl) throw new Error('oAuthServiceUrl is required') this.oAuthServiceUrl = config.options.oAuthServiceUrl + + if (config.options.oAuthServiceProvider) this.oAuthServiceProvider = config.options.oAuthServiceProvider } protected async createWallet() { let wallet = await oAuthWallet.getWallet() if (!wallet) { - const w = new oAuthWallet(this.oAuthServiceUrl) + const w = new oAuthWallet(this.oAuthServiceUrl, this.oAuthServiceProvider) wallet = await w.create() }