Skip to content
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

⚡️ Simplify login logic and reduce await post login #1917

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions src/mixins/wallet-login.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ export default {
'signLogin',
'openAuthcoreModal',
]),
async connectWallet({
shouldSkipLogin = false,
isOpenAuthcore = false,
isSignUp = false,
} = {}) {
async connectWallet({ isOpenAuthcore = false, isSignUp = false } = {}) {
try {
logTrackerEvent(
this,
Expand Down Expand Up @@ -54,15 +50,13 @@ export default {
1
);

const res = await (shouldSkipLogin
? this.initWallet(connection)
: this.initWalletAndLogin(connection));
const res = await this.initWalletAndLogin(connection);

if (res) {
logTrackerEvent(
this,
'user',
`connect_wallet_done${shouldSkipLogin ? '' : '_with_login'}`,
`connect_wallet_done_with_login`,
'connect_wallet_done',
1
);
Expand Down
43 changes: 13 additions & 30 deletions src/store/modules/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ const actions = {
method: getters.walletMethodType,
event: 'login',
});
dispatch('walletFetchSessionUserData', { shouldSkipUserInfo: true });
dispatch('walletFetchSessionUserData');
} else if (getters.getAddress) {
// Re-login if the wallet address is different from session
await dispatch('signLogin');
Expand All @@ -385,26 +385,11 @@ const actions = {
return connector;
},

async handleConnectorRedirect(
{ dispatch, getters },
{ method, params, isLogin = true }
) {
async handleConnectorRedirect({ dispatch }, { method, params }) {
const connector = await dispatch('getConnector');
const connection = await connector.handleRedirect(method, params);
if (connection) {
if (isLogin) {
await dispatch('initWalletAndLogin', connection);
} else {
await dispatch('initWallet', connection);
if (getters.walletIsMatchedSession) {
await setLoggerUser(this, {
wallet: getters.loginAddress,
method: getters.walletMethodType,
event: 'login',
});
dispatch('walletFetchSessionUserData', { shouldSkipUserInfo: true });
}
}
await dispatch('initWalletAndLogin', connection);
}
return connection;
},
Expand Down Expand Up @@ -496,20 +481,16 @@ const actions = {
await dispatch('initWallet', { accounts, method });
if (getters.walletIsMatchedSession) {
await setLoggerUser(this, { wallet: getters.loginAddress, method });
dispatch('walletFetchSessionUserData', { shouldSkipUserInfo: true });
dispatch('walletFetchSessionUserData');
}
}
},

async initIfNecessary({ dispatch }, { isLogin = true } = {}) {
async initIfNecessary({ dispatch }) {
const connector = await dispatch('getConnector');
const connection = await connector.initIfNecessary();
if (connection) {
if (isLogin) {
await dispatch('initWalletAndLogin', connection);
} else {
await dispatch('initWallet', connection);
}
await dispatch('initWalletAndLogin', connection);
}
},

Expand Down Expand Up @@ -869,15 +850,17 @@ const actions = {
},
async walletFetchSessionUserData(
{ dispatch },
{ shouldSkipUserInfo = false } = {}
{ awaitForWalletEvents = false } = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where does this use?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not used yet, but setting this flag would mimic the original behaviour, which might be useful else where

) {
const promises = [];
if (!shouldSkipUserInfo) {
promises.push(dispatch('walletFetchSessionUserInfo'));
promises.push(dispatch('walletFetchSessionUserInfo'));
const walletEventPromise = dispatch('walletFetchFollowees').then(() =>
dispatch('fetchWalletEvents', { shouldFetchDetails: false })
);
if (awaitForWalletEvents) {
promises.push(walletEventPromise);
}
promises.push(dispatch('walletFetchFollowees'));
await Promise.all(promises);
await dispatch('fetchWalletEvents', { shouldFetchDetails: false });
},
async signLogin({ state, commit, dispatch }) {
// Do not trigger login if the window is not focused
Expand Down
Loading