-
Notifications
You must be signed in to change notification settings - Fork 45
Added autoFetchWalletKitConfig and fixed manual refreshing #1102
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
Conversation
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit f22b75f:
|
moeodeh3
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all comments apply for both RN and React. This is okay for now until we restructure our config :)
| Record<string, Session> | undefined | ||
| >(undefined); | ||
|
|
||
| const shouldFetchWalletKitConfig = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can simplify, also worth commenting when its enabled or disabled:
// if there is no authProxyConfigId or if autoFetchWalletKitConfig is specifically
// set to false, we don't need to fetch the config
const shouldFetchWalletKitConfig =
!!config.authProxyConfigId &&
(config.autoFetchWalletKitConfig ?? true);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do this since I want empty string to be treated as null too:
const shouldFetchWalletKitConfig =
config.authProxyConfigId != null &&
config.authProxyConfigId !== "" &&
(config.autoFetchWalletKitConfig !== false);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think both treat "" as nullish (false)
|
|
||
| // Warn if they are trying to set auth proxy only settings directly | ||
| if (config.auth?.sessionExpirationSeconds) { | ||
| if (config.auth?.sessionExpirationSeconds && shouldFetchWalletKitConfig) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of adding this in a condition in each if statement its probably cleaner to extract it out into its own if statement:
if (shouldFetchWalletKitConfig) {
if (config.auth?.sessionExpirationSeconds) {
console.warn(
"Turnkey SDK warning. You have set sessionExpirationSeconds directly in the TurnkeyProvider. This setting will be ignored because you are using an auth proxy. Please configure session expiration in the Turnkey dashboard.",
);
}
if (config.auth?.otpAlphanumeric !== undefined) {
console.warn(
"Turnkey SDK warning. You have set otpAlphanumeric directly in the TurnkeyProvider. This setting will be ignored because you are using an auth proxy. Please configure OTP settings in the Turnkey dashboard.",
);
}
if (config.auth?.otpLength) {
console.warn(
"Turnkey SDK warning. You have set otpLength directly in the TurnkeyProvider. This setting will be ignored because you are using an auth proxy. Please configure OTP settings in the Turnkey dashboard.",
);
}
}
| // These are settings that can only be set via the auth proxy config | ||
| const authProxyOnlySettings = { | ||
| sessionExpirationSeconds: proxyAuthConfig?.sessionExpirationSeconds, | ||
| const authProxyPrioSettings = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m a bit confused about why we need to check shouldFetchWalletKitConfig at all
this actually makes me question the purpose of shouldFetchWalletKitConfig in buildConfig(). We shouldn’t need to check that flag here - why not treat the presence or absence of authProxyConfig as the source of truth?
if fetching is disabled, we simply keep authProxyConfig as undefined. When we call buildConfig(), it receives undefined, and that alone should tell us the fetch was skipped. No extra conditional needed
given that, instead of doing something like:
sessionExpirationSeconds: shouldFetchWalletKitConfig
? proxyAuthConfig?.sessionExpirationSeconds
: config.auth?.sessionExpirationSeconds
we could instead do this:
sessionExpirationSeconds:
proxyAuthConfig?.sessionExpirationSeconds ??
config.auth?.sessionExpirationSeconds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm I see you define shouldFetchWalletKitConfig as a global var - I think we should only use this locally in fetchProxyAuthConfig() and make buildConfig()just use whether the config is defined or not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cant define locally. used in "re-build" useEffect too
| "Failed to verify app proofs", | ||
| ); | ||
| const maybeRefreshUser = useCallback( | ||
| // Auto-refresh user only if enabled in config. This is only used internally |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: weird placement of a comment here - can we just have an internal comment header to follow our convention?
| ); | ||
|
|
||
| const maybeRefreshWallets = useCallback( | ||
| // Auto-refresh wallets only if enabled in config. This is only used internally |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same thing here
| } | ||
|
|
||
| if (evt?.type === "initialized") { | ||
| console.log("WalletConnect initialized event received"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this ones is a mb - but can we remove this 🙏
5766dca to
3e7157d
Compare
3e7157d to
f22b75f
Compare
Summary & Motivation
Added
autoFetchWalletKitConfigoption to theTurnkeyProviderconfig. Setting this to false will disable the initialwalletKitConfigfetch, saving on initialization time. If this is disabled and you want to use thehandleLoginmodal with Turnkey's Auth Proxy, you must pass in the enabled auth methods manually into theTurnkeyProviderconfig.Fixed
refreshWalletsandrefreshUsernot working whenautoRefreshManagedStateis disabled.How I Tested These Changes
with-sdk-js and react-wallet-kit examples
Did you add a changeset?
yes