Skip to content

Commit

Permalink
fix: fix connect waypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
HoangNguyen17193 committed Sep 23, 2024
1 parent b8d4581 commit 708145b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 77 deletions.
10 changes: 7 additions & 3 deletions packages/connect/src/connectors/base/BaseConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ export abstract class BaseConnector<ProviderType = IEIP1193Provider>
autoConnect = async () => {
try {
const shouldConnect = await this.shouldAutoReconnect();
if (shouldConnect) await this.connect();
if (shouldConnect) {
return await this.connect();
}
return null;
} catch (e) {
console.error(e);
return null;
}
};

Expand All @@ -70,8 +74,8 @@ export abstract class BaseConnector<ProviderType = IEIP1193Provider>
this.emit(ConnectorEvent.ACCOUNTS_CHANGED, accounts);
};

onConnect = (results: IConnectResult) => {
this.emit(ConnectorEvent.CONNECT, results);
onConnect = (result: IConnectResult) => {
this.emit(ConnectorEvent.CONNECT, result);
};

onDisconnect = () => {
Expand Down
37 changes: 19 additions & 18 deletions packages/connect/src/connectors/waypoint/WaypointConnector.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { WaypointProvider } from '@sky-mavis/waypoint';

import { DEFAULT_CONNECTORS_CONFIG } from '../../common/connectors';
import { ReconnectStorage } from '../../common/storage';
import { requestWaypointProvider } from '../../providers';
import { IConnectorConfigs } from '../../types/connector';
import { IConnectorConfigs, IConnectResult } from '../../types/connector';
import { ConnectorError, ConnectorErrorType } from '../../types/connector-error';
import { EIP1193Event } from '../../types/eip1193';
import { BaseConnector } from '../base/BaseConnector';
Expand Down Expand Up @@ -45,25 +46,25 @@ export class WaypointConnector extends BaseConnector<WaypointProvider> {
});
}

async connect(chainId?: number) {
const currentChainId = await this.getChainId();
if (currentChainId !== chainId) {
this.provider = await this.requestProvider(chainId);
}

let accounts = await this.getAccounts();
if (accounts.length === 0) {
accounts = await this.requestAccounts();
}

const connectResults = {
provider: this.provider,
chainId: chainId || currentChainId,
account: accounts[0],
async connect() {
const provider = await this.getProvider();
const chainId = await this.getChainId();
const accounts = await this.getAccounts();
const account = accounts[0];
const connectResult: IConnectResult = {
provider,
chainId,
account,
};

this.onConnect(connectResults);
return connectResults;
if (!account) {
const { address, accessToken } = await provider.connect();
connectResult.account = address as string;
connectResult.accessToken = accessToken;
}
this.onConnect(connectResult);
ReconnectStorage.add(this.id);
return connectResult;
}

async disconnect() {
Expand Down
3 changes: 2 additions & 1 deletion packages/connect/src/types/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface IConnectResult {
provider: unknown;
chainId: number;
account: string;
accessToken?: string;
}

export interface IBaseConnector extends IConnectorEventEmitter {
Expand All @@ -29,7 +30,7 @@ export interface IBaseConnector extends IConnectorEventEmitter {
switchChain(chain: any): Promise<boolean>;
requestAccounts(): Promise<readonly string[]>;
shouldAutoReconnect(): Promise<boolean>;
autoConnect(): Promise<void>;
autoConnect(): Promise<IConnectResult | null>;

onChainChanged(chainId: string): void;
onAccountsChanged(accounts: string[]): void;
Expand Down
93 changes: 38 additions & 55 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1263,10 +1263,10 @@
dependencies:
qr-code-styling "^1.6.0-rc.1"

"@metamask/[email protected].4":
version "0.28.4"
resolved "https://registry.yarnpkg.com/@metamask/sdk/-/sdk-0.28.4.tgz#bb5f3849629403ec97c23e1a968c6b893ecf001c"
integrity sha512-RjWBKPNesjeua2SXIDF9IvYALOSsOQyqHv5DPPK0Voskytk7y+2n/33ocbC1BH5hTLI4hDPH+BuCpXJRWs3/Yg==
"@metamask/[email protected].2":
version "0.28.2"
resolved "https://registry.yarnpkg.com/@metamask/sdk/-/sdk-0.28.2.tgz#99995a2cefd4bc6c4459869ee15c3b91ad02c488"
integrity sha512-pylk1uJAZYyO3HcNW/TNfII3+T+Yx6qrFYaC/HmuSIuRJeXsdZuExSbNQ236iQocIy3L7JjI+GQKbv3TbN+HQQ==
dependencies:
"@metamask/onboarding" "^1.0.1"
"@metamask/providers" "16.1.0"
Expand Down Expand Up @@ -3713,7 +3713,7 @@
resolved "https://registry.yarnpkg.com/@tanstack/query-core/-/query-core-5.56.2.tgz#2def2fb0290cd2836bbb08afb0c175595bb8109b"
integrity sha512-gor0RI3/R5rVV3gXfddh1MM+hgl0Z4G7tj6Xxpq6p2I03NGPaJ8dITY9Gz05zYYb/EJq9vPas/T4wn9EaDPd4Q==

"@tanstack/react-query@^5.56.2":
"@tanstack/[email protected]":
version "5.56.2"
resolved "https://registry.yarnpkg.com/@tanstack/react-query/-/react-query-5.56.2.tgz#3a0241b9d010910905382f5e99160997b8795f91"
integrity sha512-SR0GzHVo6yzhN72pnRhkEFRAHMsUo5ZPzAxfTMvUxFIDVS6W9LYUp6nXW3fcHVdg0ZJl8opSH85jqahvm6DSVg==
Expand Down Expand Up @@ -3873,21 +3873,20 @@
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.13.tgz#2af91918ee12d9d32914feb13f5326658461b451"
integrity sha512-hCZTSvwbzWGvhqxp/RqVqwU999pBf2vp7hzIjiYOsl8wqOmUxkQ6ddw1cV3l8811+kdUFus/q4d1Y3E3SyEifA==

"@types/[email protected]":
version "18.2.25"
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-18.2.25.tgz#2946a30081f53e7c8d585eb138277245caedc521"
integrity sha512-o/V48vf4MQh7juIKZU2QGDfli6p1+OOi5oXx36Hffpc9adsHeXjVp8rHuPkjd8VT8sOJ2Zp05HR7CdpGTIUFUA==
dependencies:
"@types/react" "*"

"@types/react@*", "@types/[email protected]", "@types/[email protected]":
version "18.2.79"
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.2.79.tgz#c40efb4f255711f554d47b449f796d1c7756d865"
integrity sha512-RwGAGXPl9kSXwdNTafkOEuFrTBD5SA2B3iEB96xi8+xu5ddUa/cpvyVCSNn+asgLCTHkb5ZxN8gbuibYJi4s1w==
"@types/[email protected]":
version "18.0.12"
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.0.12.tgz#cdaa209d0a542b3fcf69cf31a03976ec4cdd8840"
integrity sha512-duF1OTASSBQtcigUvhuiTB1Ya3OvSy+xORCiEf20H0P0lzx+/KeVsA99U5UjLXSbyo1DRJDlLKqTeM1ngosqtg==
dependencies:
"@types/prop-types" "*"
"@types/scheduler" "*"
csstype "^3.0.2"

"@types/scheduler@*":
version "0.23.0"
resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.23.0.tgz#0a6655b3e2708eaabca00b7372fafd7a792a7b09"
integrity sha512-YIoDCTH3Af6XM5VuwGG/QL/CJqga1Zm3NkU3HZ4ZHK2fRMPYP1VczsTUqtsf43PH/iJNVlPHAo2oWX7BSdB2Hw==

"@types/secp256k1@^4.0.6":
version "4.0.6"
resolved "https://registry.yarnpkg.com/@types/secp256k1/-/secp256k1-4.0.6.tgz#d60ba2349a51c2cbc5e816dcd831a42029d376bf"
Expand Down Expand Up @@ -4216,19 +4215,28 @@
resolved "https://registry.yarnpkg.com/@vanilla-extract/sprinkles/-/sprinkles-1.6.3.tgz#733968d653cc2395538b5c29f04dcdb0a2ca15c5"
integrity sha512-oCHlQeYOBIJIA2yWy2GnY5wE2A7hGHDyJplJo4lb+KEIBcJWRnDJDg8ywDwQS5VfWJrBBO3drzYZPFpWQjAMiQ==

"@wagmi/[email protected].12":
version "5.1.12"
resolved "https://registry.yarnpkg.com/@wagmi/connectors/-/connectors-5.1.12.tgz#a4345eeeda69942b002dd2710a3f755a30738e2c"
integrity sha512-w/MCH+J/sdqfy9ZFoEA3YKnJWlaExTCjMN4qjVNGsRtvy4ADz//zjQsmOZx51oa5xt42hv3fITN36aYZe/rO7g==
"@wagmi/[email protected].10":
version "5.1.10"
resolved "https://registry.yarnpkg.com/@wagmi/connectors/-/connectors-5.1.10.tgz#316dcdbb3924c546c177b0fc287e0f591225c63f"
integrity sha512-ybgKV09PIhgUgQ4atXTs2KOy4Hevd6f972SXfx6HTgsnFXlzxzN6o0aWjhavZOYjvx5tjuL3+8Mgqo0R7uP5Cg==
dependencies:
"@coinbase/wallet-sdk" "4.0.4"
"@metamask/sdk" "0.28.4"
"@metamask/sdk" "0.28.2"
"@safe-global/safe-apps-provider" "0.18.3"
"@safe-global/safe-apps-sdk" "9.1.0"
"@walletconnect/ethereum-provider" "2.16.1"
"@walletconnect/modal" "2.6.2"
cbw-sdk "npm:@coinbase/[email protected]"

"@wagmi/[email protected]":
version "2.13.5"
resolved "https://registry.yarnpkg.com/@wagmi/core/-/core-2.13.5.tgz#20764d88d36c31c4557511309eef7d23fa60c98e"
integrity sha512-lvX/hApJTSA/H2kOklokjIYiUpnT8CpBH80GeOiKxU0CGK1wNHTu20GRTCy0GF1t7jkNwPSG3m0SmnXmgYMmHw==
dependencies:
eventemitter3 "5.0.1"
mipd "0.0.7"
zustand "4.4.1"

"@wagmi/[email protected]":
version "2.13.6"
resolved "https://registry.yarnpkg.com/@wagmi/core/-/core-2.13.6.tgz#532118e60fcb3abde9cabf5318c8986c4ddcacff"
Expand Down Expand Up @@ -9681,16 +9689,7 @@ string-length@^4.0.1:
char-regex "^1.0.2"
strip-ansi "^6.0.0"

"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -9784,14 +9783,7 @@ string_decoder@~1.1.1:
dependencies:
safe-buffer "~5.1.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -10601,13 +10593,13 @@ [email protected], viem@^2.1.1:
webauthn-p256 "0.0.5"
ws "8.17.1"

wagmi@^2.12.13:
version "2.12.13"
resolved "https://registry.yarnpkg.com/wagmi/-/wagmi-2.12.13.tgz#bc3c6ac0480a652c4b81c9beb69507de9b5383fd"
integrity sha512-zgTb2Sb8Yq69X5bxLLIRn2+HjjxU57d7mfCKA2kPo5+RSWsSstj57CncTeVjoR+gKhvLEEl2mmusSzQjT2p5lA==
[email protected].11:
version "2.12.11"
resolved "https://registry.yarnpkg.com/wagmi/-/wagmi-2.12.11.tgz#f2e854032650bfe6fb0eedaa1eafb695e31f800f"
integrity sha512-CtK05Hl5nKVskiwvNEtxMIAMJwI8RF+6qwVqlhypDs+Y1c30gVnNnF7ivAuVs4xzJbAsZ5LUmsrVVxUMIC0KDg==
dependencies:
"@wagmi/connectors" "5.1.12"
"@wagmi/core" "2.13.6"
"@wagmi/connectors" "5.1.10"
"@wagmi/core" "2.13.5"
use-sync-external-store "1.2.0"

walker@^1.0.8:
Expand Down Expand Up @@ -10730,7 +10722,7 @@ wordwrapjs@^4.0.0:
reduce-flatten "^2.0.0"
typical "^5.2.0"

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -10748,15 +10740,6 @@ wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down

0 comments on commit 708145b

Please sign in to comment.