Skip to content

Commit 9c128cf

Browse files
Fix wallet login type and email info regression
1 parent 81bdfab commit 9c128cf

File tree

1 file changed

+33
-16
lines changed

1 file changed

+33
-16
lines changed

packages/wallet/wdk/src/sequence/wallets.ts

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -687,26 +687,42 @@ export class Wallets implements WalletsInterface {
687687
// If there is an existing wallet callback, we check if any wallet already exist for this login signer
688688
if (this.walletSelectionUiHandler) {
689689
const existingWallets = await State.getWalletsFor(this.shared.sequence.stateProvider, loginSigner.signer)
690+
690691
if (existingWallets.length > 0) {
692+
for (const wallet of existingWallets) {
693+
const preliminaryEntry: Wallet = {
694+
address: wallet.wallet,
695+
status: 'logging-in',
696+
loginEmail: loginSigner.loginEmail,
697+
loginType: loginSigner.extra.signerKind,
698+
loginDate: new Date().toISOString(),
699+
device: '' as `0x${string}`,
700+
useGuard: false,
701+
}
702+
await this.shared.databases.manager.set(preliminaryEntry)
703+
}
704+
691705
const result = await this.walletSelectionUiHandler({
692706
existingWallets: existingWallets.map((w) => w.wallet),
693707
signerAddress: await loginSigner.signer.address,
694-
context: isAuthCodeArgs(args)
695-
? {
696-
isRedirect: args.isRedirect,
697-
target: args.target,
698-
}
699-
: {
700-
isRedirect: false,
701-
},
708+
context: isAuthCodeArgs(args) ? { isRedirect: args.isRedirect, target: args.target } : { isRedirect: false },
702709
})
703710

704711
if (result === 'abort-signup') {
712+
for (const wallet of existingWallets) {
713+
const finalEntry = await this.shared.databases.manager.get(wallet.wallet)
714+
if (finalEntry && !finalEntry.device) {
715+
await this.shared.databases.manager.del(wallet.wallet)
716+
}
717+
}
705718
// Abort the signup process
706719
return undefined
707720
}
708721

709722
if (result === 'create-new') {
723+
for (const wallet of existingWallets) {
724+
await this.shared.databases.manager.del(wallet.wallet)
725+
}
710726
// Continue with the signup process
711727
} else {
712728
throw new Error('invalid-result-from-wallet-selector')
@@ -867,8 +883,9 @@ export class Wallets implements WalletsInterface {
867883

868884
async login(args: LoginArgs): Promise<string> {
869885
if (isLoginToWalletArgs(args)) {
870-
const prevWallet = await this.has(args.wallet)
871-
if (prevWallet) {
886+
const existingWallet = await this.get(args.wallet)
887+
888+
if (existingWallet?.status === 'ready') {
872889
throw new Error('wallet-already-logged-in')
873890
}
874891

@@ -898,21 +915,20 @@ export class Wallets implements WalletsInterface {
898915
await this.shared.modules.recovery.addRecoverySignerToModules(modules, device.address)
899916
}
900917

901-
const existingEntry = await this.shared.databases.manager.get(args.wallet)
902-
903-
const walletEntryToUpdate = {
904-
...(existingEntry ?? {}),
918+
const walletEntryToUpdate: Wallet = {
919+
...(existingWallet as Wallet),
905920
address: args.wallet,
906921
status: 'logging-in' as const,
907922
loginDate: new Date().toISOString(),
908923
device: device.address,
909-
loginType: 'wallet' as const,
924+
loginType: existingWallet?.loginType || 'wallet',
925+
loginEmail: existingWallet?.loginEmail,
910926
useGuard: guardTopology !== undefined,
911927
}
912928

913929
await this.shared.databases.manager.set(walletEntryToUpdate)
914930

915-
return this.requestConfigurationUpdate(
931+
const requestId = await this.requestConfigurationUpdate(
916932
args.wallet,
917933
{
918934
devicesTopology: nextDevicesTopology,
@@ -921,6 +937,7 @@ export class Wallets implements WalletsInterface {
921937
'login',
922938
'wallet-webapp',
923939
)
940+
return requestId
924941
}
925942

926943
if (isLoginToMnemonicArgs(args)) {

0 commit comments

Comments
 (0)