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

OK-23670: Lightning Network topup auto select account mismatch #3653

Closed
wants to merge 3 commits into from
Closed
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
29 changes: 24 additions & 5 deletions packages/desktop/src-electron/libs/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,37 @@ export const clearUpdateSettings = () => {
};

export const getSecureItem = (key: string) => {
const available = safeStorage.isEncryptionAvailable();
if (!available) {
console.error('safeStorage is not available');
return undefined;
}
const item = store.get(EncryptedData, {}) as Record<string, string>;
const value = item[key];
if (value) {
const result = safeStorage.decryptString(Buffer.from(value, 'hex'));
return result;
try {
const result = safeStorage.decryptString(Buffer.from(value, 'hex'));
return result;
} catch (e) {
console.error(`failed to decrypt ${key}`, e);
return undefined;
}
originalix marked this conversation as resolved.
Show resolved Hide resolved
}
};

export const setSecureItem = (key: string, value: string): void => {
const items = store.get(EncryptedData, {}) as Record<string, string>;
items[key] = safeStorage.encryptString(value).toString('hex');
store.set(EncryptedData, items);
const available = safeStorage.isEncryptionAvailable();
if (!available) {
console.error('safeStorage is not available');
return undefined;
}
try {
const items = store.get(EncryptedData, {}) as Record<string, string>;
items[key] = safeStorage.encryptString(value).toString('hex');
store.set(EncryptedData, items);
} catch (e) {
console.error(`failed to encrypt ${key} ${value}`, e);
}
};

export const clearSecureItem = (key: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { isLightningNetworkByNetworkId } from '@onekeyhq/shared/src/engine/engin
import backgroundApiProxy from '../../../background/instance/backgroundApiProxy';
import { useAccount, useNavigation, useNetwork } from '../../../hooks';
import { TabRoutes } from '../../../routes/routesEnum';
import { setRecipient } from '../../../store/reducers/swap';

import type { MessageDescriptor } from 'react-intl';

Expand Down Expand Up @@ -55,11 +56,23 @@ function LNSwapMenu({
if (account) {
if (isWithdraw) {
backgroundApiProxy.serviceSwap.setSendingAccountSimple(account);
} else {
backgroundApiProxy.serviceSwap.setRecipientToAccount(
account,
network,
);
} else if (network?.id && account) {
const lnurlMap =
await backgroundApiProxy.serviceLightningNetwork.batchGetLnUrlByAccounts(
{
networkId: network.id,
accounts: [account],
},
);
const address = lnurlMap[account.id] ?? account.address;
const data = {
address,
name: account.name,
accountId: account.id,
networkId: network.id,
networkImpl: network.impl,
};
backgroundApiProxy.dispatch(setRecipient(data));
}
}
navigation.getParent()?.navigate(TabRoutes.Swap);
Expand Down