diff --git a/src/extension/background-script/actions/accounts/add.ts b/src/extension/background-script/actions/accounts/add.ts index 3276a78c7a..df38e0d0ad 100644 --- a/src/extension/background-script/actions/accounts/add.ts +++ b/src/extension/background-script/actions/accounts/add.ts @@ -1,8 +1,13 @@ import { v4 as uuidv4 } from "uuid"; import { encryptData } from "~/common/lib/crypto"; +import { getUniqueAccountName } from "~/common/utils/validations"; +import edit from "~/extension/background-script/actions/accounts/edit"; +import { + generateMnemonic, + setMnemonic, +} from "~/extension/background-script/actions/mnemonic"; import state from "~/extension/background-script/state"; import type { MessageAccountAdd } from "~/types"; -import { getUniqueAccountName } from "~/common/utils/validations"; const add = async (message: MessageAccountAdd) => { const newAccount = message.args; @@ -24,12 +29,34 @@ const add = async (message: MessageAccountAdd) => { name, }; + const mnemonic = await generateMnemonic({ + action: "generateMnemonic", + origin: { internal: true }, + }); + setMnemonic({ + args: { + id: accountId, + mnemonic: mnemonic.data, + }, + action: "setMnemonic", + origin: { internal: true }, + }); + state.setState({ accounts: tmpAccounts }); if (!currentAccountId) { state.setState({ currentAccountId: accountId }); } + edit({ + args: { + id: accountId, + useMnemonicForLnurlAuth: true, + }, + action: "editAccount", + origin: { internal: true }, + }); + // make sure we immediately persist the new account await state.getState().saveToStorage(); return { data: { accountId: accountId } }; diff --git a/src/extension/background-script/actions/accounts/unlock.ts b/src/extension/background-script/actions/accounts/unlock.ts index 16217f93c4..595afd78d0 100644 --- a/src/extension/background-script/actions/accounts/unlock.ts +++ b/src/extension/background-script/actions/accounts/unlock.ts @@ -31,6 +31,7 @@ const unlock = async (message: MessageAccountUnlock) => { // if everything is fine we keep the password in memory await state.getState().password(password); + // load the connector to make sure it is initialized for the future calls // with this we prevent potentially multiple action calls trying to initialize the connector in parallel // we have to be careful here: if the unlock fails (e.g. because of an error in getConnector() the user