Skip to content

Commit aa05c5c

Browse files
Merge pull request #2090 from Web3Auth/feat/sdk-v10-review-comments
adds review comments for sdk v10 pr
2 parents cfe8370 + c5c1e27 commit aa05c5c

File tree

36 files changed

+196
-555
lines changed

36 files changed

+196
-555
lines changed

demo/vue-app-new/src/MainView.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ const options = computed((): Web3AuthOptions => {
8787
useAAWithExternalWallet: formData.useAAWithExternalWallet,
8888
// TODO: Add more options
8989
// enableLogging?: boolean;
90-
// storageKey?: "session" | "local";
90+
// storageType?: "session" | "local";
9191
// sessionTime?: number;
9292
// useCoreKitKey?: boolean;
9393
chains,
94+
defaultChainId: formData.defaultChainId,
9495
enableLogging: true,
9596
connectors: externalConnectors.value,
9697
plugins,

demo/vue-app-new/src/components/AppSettings.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ const chainOptions = computed(() => {
3737
return allChains;
3838
});
3939
40+
const defaultChainOptions = computed(() => {
41+
return formData.chains.map((chain) => ({ name: chain, value: chain }));
42+
});
43+
4044
const adapterOptions = computed(() =>
4145
formData.chainNamespaces.includes(CHAIN_NAMESPACES.EIP155)
4246
? [
@@ -90,6 +94,7 @@ const isActiveTab = (index: number) => activeTab.value === index;
9094
const onChainNamespaceChange = (value: string[]) => {
9195
log.info("onChainNamespaceChange", value);
9296
formData.chains = value.map((namespace) => chainConfigs[namespace as ChainNamespaceType][0]);
97+
formData.defaultChainId = formData.chains[0];
9398
formData.connectors = [];
9499
};
95100
</script>
@@ -155,6 +160,14 @@ const onChainNamespaceChange = (value: string[]) => {
155160
:multiple="true"
156161
:options="chainOptions"
157162
/>
163+
<Select
164+
v-model="formData.defaultChainId"
165+
data-testid="selectDefaultChainId"
166+
:label="$t('app.defaultChainId')"
167+
:aria-label="$t('app.defaultChainId')"
168+
:placeholder="$t('app.defaultChainId')"
169+
:options="defaultChainOptions"
170+
/>
158171
<Select
159172
v-model="formData.connectors"
160173
data-testid="selectAdapters"

demo/vue-app-new/src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export type FormData = {
102102
network: WEB3AUTH_NETWORK_TYPE;
103103
chainNamespaces: ChainNamespaceType[];
104104
chains: string[];
105+
defaultChainId: string;
105106
whiteLabel: {
106107
enable: boolean;
107108
config: WhiteLabelData;

demo/vue-app-new/src/store/form.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const formDataStore = reactive<FormData>({
99
network: WEB3AUTH_NETWORK.TESTNET,
1010
chainNamespaces: [CHAIN_NAMESPACES.EIP155],
1111
chains: [chainConfigs[CHAIN_NAMESPACES.EIP155][0], chainConfigs[CHAIN_NAMESPACES.EIP155][1]],
12+
defaultChainId: chainConfigs[CHAIN_NAMESPACES.EIP155][0],
1213
whiteLabel: {
1314
enable: false,
1415
config: initWhiteLabel,

demo/vue-app-new/src/translations/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"documentation": "Documentation",
77
"network": "Network",
88
"chains": "Chains",
9+
"defaultChainId": "Default Chain ID",
910
"loginProviders": "Login provider",
1011
"adapters": "Adapters",
1112
"showWalletDiscovery": "Show Wallet Discovery",

packages/modal/src/modalManager.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
6262

6363
public async initModal(params?: ModalConfigParams): Promise<void> {
6464
super.checkInitRequirements();
65-
65+
super.initCachedConnectorAndChainId();
6666
// get project config and wallet registry
6767
const { projectConfig, walletRegistry } = await this.getProjectAndWalletConfig(params);
6868
this.options.uiConfig = deepmerge(cloneDeep(projectConfig.whitelabel || {}), this.options.uiConfig || {});
@@ -80,10 +80,12 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
8080
await this.loginModal.initModal();
8181

8282
// setup common JRPC provider
83-
await this.setupCommonJRPCProvider(projectConfig);
83+
await this.setupCommonJRPCProvider();
8484

8585
// initialize connectors
86-
this.on(CONNECTOR_EVENTS.CONNECTORS_UPDATED, ({ connectors }) => this.initConnectors({ connectors, projectConfig, modalConfig: params }));
86+
this.on(CONNECTOR_EVENTS.CONNECTORS_UPDATED, ({ connectors: newConnectors }) =>
87+
this.initConnectors({ connectors: newConnectors, projectConfig, modalConfig: params })
88+
);
8789
await this.loadConnectors({ projectConfig });
8890

8991
// initialize plugins
@@ -171,6 +173,7 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
171173
// update auth connector config
172174
const { sms_otp_enabled: smsOtpEnabled } = projectConfig;
173175
if (smsOtpEnabled !== undefined) {
176+
// TODO: use the new login config method
174177
const connectorConfig: Record<WALLET_CONNECTOR_TYPE, ModalConfig> = {
175178
[WALLET_CONNECTORS.AUTH]: {
176179
label: WALLET_CONNECTORS.AUTH,

packages/no-modal/src/base/chain/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const getDefaultNetworkId = (chainNamespace: ChainNamespaceType): number => {
1515
}
1616
throw WalletInitializationError.invalidParams(`Chain namespace ${chainNamespace} is not supported`);
1717
};
18-
18+
// TODO: remove this function and get this from dashboard instead
1919
export const getEvmChainConfig = (chainId: number, web3AuthClientId: string = ""): CustomChainConfig | null => {
2020
const chainNamespace = CHAIN_NAMESPACES.EIP155;
2121
const infuraRpcTarget = `${INFURA_PROXY_URL}/${chainId}/${web3AuthClientId}`;

packages/no-modal/src/base/connector/baseConnector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ export abstract class BaseConnector<T> extends SafeEventEmitter<ConnectorEvents>
7979
checkSwitchChainRequirements(params: { chainId: string }, init = false): void {
8080
if (!init && !this.provider) throw WalletLoginError.notConnectedError("Not connected with wallet.");
8181
if (!this.coreOptions.chains) throw WalletInitializationError.invalidParams("chainConfigs is required");
82-
const newChainConfig = this.coreOptions.chains.find(
82+
const doesChainExist = this.coreOptions.chains.some(
8383
(x) =>
8484
x.chainId === params.chainId && (x.chainNamespace === this.connectorNamespace || this.connectorNamespace === CONNECTOR_NAMESPACES.MULTICHAIN)
8585
);
86-
if (!newChainConfig) throw WalletInitializationError.invalidParams("Invalid chainId");
86+
if (!doesChainExist) throw WalletInitializationError.invalidParams("Invalid chainId");
8787
}
8888

8989
updateConnectorData(data: unknown): void {

packages/no-modal/src/base/core/IWeb3Auth.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
type CONNECTOR_STATUS_TYPE,
99
ConnectorEvents,
1010
type ConnectorFn,
11+
type IBaseProvider,
1112
type IConnector,
1213
type IProvider,
1314
type UserAuthInfo,
@@ -56,6 +57,12 @@ export interface IWeb3AuthCoreOptions {
5657
* only provided chains will be used
5758
*/
5859
chains?: CustomChainConfig[];
60+
61+
/**
62+
* default chain Id to use
63+
*/
64+
defaultChainId?: string;
65+
5966
/**
6067
* setting to true will enable logs
6168
*
@@ -67,18 +74,19 @@ export interface IWeb3AuthCoreOptions {
6774
*
6875
* @defaultValue "local"
6976
*/
70-
storageKey?: "session" | "local";
77+
// TODO: rename this to match customauth, sfa
78+
storageType?: "session" | "local";
7179

7280
/**
7381
* sessionTime (in seconds) for idToken issued by Web3Auth for server side verification.
74-
* @defaultValue 86400
82+
* @defaultValue 7 * 86400
7583
*
76-
* Note: max value can be 7 days (86400 * 7) and min can be 1 day (86400)
84+
* Note: max value can be 30 days (86400 * 30) and min can be 1 sec (1)
7785
*/
7886
sessionTime?: number;
7987
/**
8088
* Web3Auth Network to use for the session & the issued idToken
81-
* @defaultValue mainnet
89+
* @defaultValue sapphire_mainnet
8290
*/
8391
web3AuthNetwork?: WEB3AUTH_NETWORK_TYPE;
8492

@@ -123,6 +131,11 @@ export interface IWeb3AuthCoreOptions {
123131
* Wallet services config
124132
*/
125133
walletServicesConfig?: WalletServicesConfig;
134+
135+
/**
136+
* Private key provider for xrpl, mpc cases
137+
*/
138+
privateKeyProvider?: IBaseProvider<string>;
126139
}
127140

128141
export interface IWeb3AuthCore extends SafeEventEmitter {

packages/no-modal/src/base/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface WhitelistResponse {
77
signed_urls: Record<string, string>;
88
}
99

10+
// TODO: add more data from dashboard including chains
1011
export interface PROJECT_CONFIG_RESPONSE {
1112
whitelabel?: WhiteLabelData;
1213
sms_otp_enabled: boolean;

0 commit comments

Comments
 (0)