Skip to content

Commit

Permalink
fix: update waypoint provider configs (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaoTrinhSKM authored Sep 25, 2024
1 parent 5c69a49 commit 38fdc52
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 22 additions & 5 deletions packages/connect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
```
2 changes: 2 additions & 0 deletions packages/connect/src/common/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number> = [ChainIds.RoninMainnet, ChainIds.RoninTestnet];

export const WC_RPC_MAP: EthereumRpcMap = {
Expand Down
8 changes: 6 additions & 2 deletions packages/connect/src/connectors/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -57,8 +58,11 @@ export const requestSafeConnector = async (configs?: Partial<IConnectorConfigs>,
return new SafeConnector(configs, provider);
};

export const requestWaypointConnector = (config?: Partial<IConnectorConfigs>, chainId?: number) => {
const waypointProvider = requestWaypointProvider(chainId);
export const requestWaypointConnector = (
config?: Partial<IConnectorConfigs>,
providerConfigs?: IWaypointProviderConfigs,
) => {
const waypointProvider = requestWaypointProvider(providerConfigs);

return new WaypointConnector(config, waypointProvider);
};
5 changes: 3 additions & 2 deletions packages/connect/src/connectors/waypoint/WaypointConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -85,8 +86,8 @@ export class WaypointConnector extends BaseConnector<WaypointProvider> {
this.removeProviderListeners();
}

async requestProvider(chainId?: number) {
return requestWaypointProvider(chainId);
async requestProvider(configs?: IWaypointProviderConfigs) {
return requestWaypointProvider(configs);
}

protected setupProviderListeners() {
Expand Down
13 changes: 11 additions & 2 deletions packages/connect/src/providers/waypoint-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 38fdc52

Please sign in to comment.