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

fix: stop beignet wallet before replace/wipe it #2385

Merged
merged 1 commit into from
Dec 9, 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@synonymdev/slashtags-widget-price-feed": "1.1.0",
"@synonymdev/web-relay": "1.0.7",
"bech32": "2.0.0",
"beignet": "0.0.48",
"beignet": "0.0.49",
"bip21": "2.0.3",
"bip32": "4.0.0",
"bitcoin-address-validation": "2.2.3",
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Settings/AddressViewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ const AddressViewer = ({
if (utxosLength <= 0) {
return;
}
resetSendTransaction();
await resetSendTransaction();
const transactionRes = await setupOnChainTransaction({
utxos: selectedUtxosLength > 0 ? selectedUtxos : utxos,
rbf: true,
Expand Down
8 changes: 7 additions & 1 deletion src/store/utils/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { removePin } from '../../utils/settings';
import { wipeKeychain } from '../../utils/keychain';
import { showToast } from '../../utils/notifications';
import { wipeLdkStorage } from '../../utils/lightning';
import { getSelectedWallet } from '../../utils/wallet';
import { getOnChainWallet, getSelectedWallet } from '../../utils/wallet';
import { TWalletName } from '../types/wallet';
import { __E2E__ } from '../../constants/env';

Expand All @@ -31,6 +31,12 @@ export const wipeApp = async ({
restartApp?: boolean;
} = {}): Promise<Result<string>> => {
try {
// stop onchain wallet if it exists
try {
const wallet = getOnChainWallet();
await wallet.stop();
} catch (e) {}

Comment on lines +34 to +39
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can expect the wallet to exist at this point, so it should be able to be stopped. If it does fail we should probably propagate and return the error. Especially if we're going to remove the restart in the future.

Suggested change
// stop onchain wallet if it exists
try {
const wallet = getOnChainWallet();
await wallet.stop();
} catch (e) {}
// stop onchain wallet if it exists
const wallet = getOnChainWallet();
await wallet.stop();

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We run wipeApp during Onboard/TermsOfUse, at this point wallet does not exists

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right ok let's leave it for now. If we're going to remove the restart later we should probably return the error outside the onboarding though.

// Reset Redux stores & persisted storage
dispatch({ type: actions.WIPE_APP });

Expand Down
10 changes: 2 additions & 8 deletions src/utils/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1108,14 +1108,8 @@ export const setupOnChainWallet = async ({
addressTypesToMonitor?: EAddressType[];
gapLimitOptions?: TGapLimitOptions;
}): Promise<Result<Wallet>> => {
// Disconnect from Electrum before setting up a new wallet
if (globalWallet) {
// If wallet refresh is in progress, wait for it to complete
if (globalWallet.isRefreshing) {
await globalWallet.refreshWallet();
}
await globalWallet.electrum?.disconnect();
}
// if wallet alrady exists, prepare it to be re-created
await globalWallet?.stop();

if (!mnemonic) {
const mnemonicRes = await getMnemonicPhrase(name);
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6351,9 +6351,9 @@ __metadata:
languageName: node
linkType: hard

"beignet@npm:0.0.48":
version: 0.0.48
resolution: "beignet@npm:0.0.48"
"beignet@npm:0.0.49":
version: 0.0.49
resolution: "beignet@npm:0.0.49"
dependencies:
"@bitcoinerlab/secp256k1": 1.0.5
bech32: 2.0.0
Expand All @@ -6367,7 +6367,7 @@ __metadata:
lodash.clonedeep: 4.5.0
net: 1.0.2
rn-electrum-client: 0.0.18
checksum: 4aab9ec50b339bde6ef291fc9e9a2e6845f6f7bac9a07be292cfc0eaac5bcd387ed08d5a54e416f476a40d332cf6a1946c028387eba76a0e81890e33b5e73615
checksum: fef6246edf066cb1dad9a3969d10e7a5497524aa9220fab24b3a11cb0644d04b23bddab48912b9485e67b7b58c58e3da951fa5e349c92a5121a042663def0280
languageName: node
linkType: hard

Expand Down Expand Up @@ -6612,7 +6612,7 @@ __metadata:
babel-jest: ^29.7.0
babel-plugin-transform-remove-console: ^6.9.4
bech32: 2.0.0
beignet: 0.0.48
beignet: 0.0.49
bip21: 2.0.3
bip32: 4.0.0
bitcoin-address-validation: 2.2.3
Expand Down
Loading