diff --git a/apps/example/components/wallet-connectors/waypoint/Waypoint.tsx b/apps/example/components/wallet-connectors/waypoint/Waypoint.tsx index 242630f..81907c3 100644 --- a/apps/example/components/wallet-connectors/waypoint/Waypoint.tsx +++ b/apps/example/components/wallet-connectors/waypoint/Waypoint.tsx @@ -21,7 +21,10 @@ const Waypoint: FC = () => { }; useEffect(() => { - const waypointConnector = requestWaypointConnector({}, 2021); + const waypointProviderConfigs = { + chainId: 2021, + }; + const waypointConnector = requestWaypointConnector({}, waypointProviderConfigs); waypointConnector.autoConnect(); setIsConnected(false); setConnector(waypointConnector); diff --git a/packages/connect/README.md b/packages/connect/README.md index 34cc54e..7cf54ad 100644 --- a/packages/connect/README.md +++ b/packages/connect/README.md @@ -31,26 +31,43 @@ const connectorConfigs = { ### Waypoint Connector +The configs that override the default configs of the Waypoint provider. + +```javascript +import { ChainIds } from '@sky-mavis/tanto-connect'; + +const waypointProviderConfigs = { + clientId: "", + chainId: ChainIds.RoninMainnet, +}; +``` + #### _Request a connector_ ```javascript -import { ChainIds, requestWaypointConnector } from '@sky-mavis/tanto-connect'; +import { requestWaypointConnector } from '@sky-mavis/tanto-connect'; // Use your own connector config if needed, if not, we recommend you should leave it as default. const waypointConnectorConfigs = {}; -const waypointConnector = requestWaypointConnector(wayPointConnectorConfigs, ChainIds.RoninMainnet); +const waypointConnector = requestWaypointConnector( + waypointConnectorConfigs, + waypointProviderConfigs +); ``` #### _Request a provider_ ```javascript -import { ChainIds, requestWaypointProvider } from '@sky-mavis/tanto-connect'; +import { requestWaypointProvider } from '@sky-mavis/tanto-connect'; -const waypointProvider = requestWaypointProvider(ChainIds.RoninMainnet); +const waypointProvider = requestWaypointProvider(waypointProviderConfigs); ``` + Or if you have already had a `waypointConnector`: ```javascript -const waypointProvider = waypointConnector.requestProvider(ChainIds.RoninMainnet); +const waypointProvider = waypointConnector.requestProvider( + waypointProviderConfigs +); ``` diff --git a/packages/connect/src/common/constant.ts b/packages/connect/src/common/constant.ts index 32bd02d..8f6df01 100644 --- a/packages/connect/src/common/constant.ts +++ b/packages/connect/src/common/constant.ts @@ -8,6 +8,8 @@ export const DEFAULT_DELAY_TIME = 700; export const WAYPOINT_CLIENT_ID = 'ced25363-9cab-4e50-b1bc-0e583b93c3a2'; +export const WAYPOINT_ORIGIN_STAGING = 'https://id.skymavis.one'; + export const WC_SUPPORTED_CHAIN_IDS: ArrayOneOrMore = [ChainIds.RoninMainnet, ChainIds.RoninTestnet]; export const WC_RPC_MAP: EthereumRpcMap = { diff --git a/packages/connect/src/connectors/index.ts b/packages/connect/src/connectors/index.ts index ffc5e07..3f4c45a 100644 --- a/packages/connect/src/connectors/index.ts +++ b/packages/connect/src/connectors/index.ts @@ -1,6 +1,7 @@ import { ConnectorType, RONIN_WALLET_CONNECT_PROJECT_ID } from '../common/connectors'; import { DEFAULT_DELAY_TIME, RONIN_WALLET_RDNS, WC_SUPPORTED_CHAIN_IDS } from '../common/constant'; import { + IWaypointProviderConfigs, requestProviders, requestRoninProvider, requestRoninWalletConnectProvider, @@ -57,8 +58,11 @@ export const requestSafeConnector = async (configs?: Partial, return new SafeConnector(configs, provider); }; -export const requestWaypointConnector = (config?: Partial, chainId?: number) => { - const waypointProvider = requestWaypointProvider(chainId); +export const requestWaypointConnector = ( + config?: Partial, + providerConfigs?: IWaypointProviderConfigs, +) => { + const waypointProvider = requestWaypointProvider(providerConfigs); return new WaypointConnector(config, waypointProvider); }; diff --git a/packages/connect/src/connectors/waypoint/WaypointConnector.ts b/packages/connect/src/connectors/waypoint/WaypointConnector.ts index 46782f1..eff59c0 100644 --- a/packages/connect/src/connectors/waypoint/WaypointConnector.ts +++ b/packages/connect/src/connectors/waypoint/WaypointConnector.ts @@ -3,6 +3,7 @@ import { WaypointProvider } from '@sky-mavis/waypoint'; import { DEFAULT_CONNECTORS_CONFIG } from '../../common/connectors'; import { LocalStorage, ReconnectStorage, WAYPOINT_ACCESS_TOKEN_STORAGE_KEY } from '../../common/storage'; import { requestWaypointProvider } from '../../providers'; +import { IWaypointProviderConfigs } from '../../providers/waypoint-provider'; import { IConnectorConfigs, IConnectResult } from '../../types/connector'; import { ConnectorError, ConnectorErrorType } from '../../types/connector-error'; import { EIP1193Event } from '../../types/eip1193'; @@ -85,8 +86,8 @@ export class WaypointConnector extends BaseConnector { this.removeProviderListeners(); } - async requestProvider(chainId?: number) { - return requestWaypointProvider(chainId); + async requestProvider(configs?: IWaypointProviderConfigs) { + return requestWaypointProvider(configs); } protected setupProviderListeners() { diff --git a/packages/connect/src/providers/waypoint-provider.ts b/packages/connect/src/providers/waypoint-provider.ts index cba89aa..27d6be2 100644 --- a/packages/connect/src/providers/waypoint-provider.ts +++ b/packages/connect/src/providers/waypoint-provider.ts @@ -4,10 +4,19 @@ import { ChainIds } from '../common/chain'; import { WAYPOINT_CLIENT_ID } from '../common/constant'; import { ConnectorError, ConnectorErrorType } from '../types/connector-error'; -export const requestWaypointProvider = (chainId?: number) => { +export interface IWaypointProviderConfigs { + chainId?: number; + clientId?: string; + waypointOrigin?: string; +} + +export const requestWaypointProvider = (configs?: IWaypointProviderConfigs) => { + const { chainId, clientId, waypointOrigin } = configs || {}; + const waypointProvider = WaypointProvider.create({ - clientId: WAYPOINT_CLIENT_ID, + clientId: clientId || WAYPOINT_CLIENT_ID, chainId: chainId || ChainIds.RoninMainnet, + waypointOrigin, }); if (!waypointProvider) {