Skip to content

Commit 02c0fa7

Browse files
author
bay
committed
Fix QT wallet crash is current wallet is not available.
1 parent 47d3459 commit 02c0fa7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

core/appcontext.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,10 +839,13 @@ QPair<QVector<QString>, int> AppContext::getWalletInstances(bool hasSeed) const
839839
}
840840
}
841841

842-
int selectedIdx = -1;
842+
int selectedIdx = 0;
843843
if (!paths.isEmpty()) {
844-
selectedIdx = std::max(static_cast<size_t>(0), static_cast<size_t>(paths.indexOf(walletInstancePaths.value(currentWalletInstanceIdx, ""))));
844+
selectedIdx = paths.indexOf(walletInstancePaths.value(currentWalletInstanceIdx, ""));
845+
if (selectedIdx<0)
846+
selectedIdx = 0;
845847
}
848+
Q_ASSERT(selectedIdx>=0 && selectedIdx<paths.size());
846849

847850
return QPair<QVector<QString>, int> (paths, selectedIdx);
848851
}
@@ -862,6 +865,9 @@ QPair<QVector<QString>, int> AppContext::getWalletInstances(bool hasSeed) const
862865
QString AppContext::getCurrentWalletInstance(bool hasSeed) const {
863866
auto res = getWalletInstances(hasSeed);
864867
Q_ASSERT(!res.first.isEmpty());
868+
if (res.first.isEmpty())
869+
return "";
870+
865871
return res.first[res.second];
866872
}
867873

0 commit comments

Comments
 (0)