Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ASL-4207] upgrade web3 react v8 #169

Merged
merged 1 commit into from
Jun 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions packages/react/src/connector/QubicConnector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import QubicProvider from '@qubic-js/browser';
import { Network, SignInProvider } from '@qubic-js/core';
import type { Actions, ProviderConnectInfo, ProviderRpcError } from '@web3-react/types';
import type { Actions } from '@web3-react/types';
import { Connector } from '@web3-react/types';

export interface QubicConnectorOptions {
Expand Down Expand Up @@ -92,15 +92,6 @@ export default class QubicWalletConnector extends Connector {

this.connected = true;

this.provider.on('connect', ({ chainId }: ProviderConnectInfo): void => {
this.actions.update({ chainId: parseChainId(chainId) });
});

this.provider.on('disconnect', (error: ProviderRpcError): void => {
this.actions.resetState();
this.onError?.(error);
});

this.provider.on('chainChanged', (chainId: string): void => {
this.actions.update({ chainId: parseChainId(chainId) });
});
Expand Down Expand Up @@ -143,16 +134,22 @@ export default class QubicWalletConnector extends Connector {
await this.isomorphicInitialize();
if (!this.provider) throw new Error('No provider');

await this.provider?.request?.({
const accounts = await this.provider?.request?.<string[]>({
method: 'eth_requestAccounts',
});

await this.provider?.request?.({
const chainId = await this.provider?.request?.<string>({
method: 'eth_chainId',
});

if (this.options?.autoHideWelcome) {
this.provider?.hide();
}

// in web js sdk, when iframe or popup start
// it will postMessage chainId and accounts immediately
// but in mobile dapp browser, we have to update manually
this.actions.update({ chainId: parseChainId(chainId), accounts });
} catch (error) {
cancelActivation();
throw error;
Expand Down