Skip to content

Commit

Permalink
fix: #459 修复分组升级无法使用问题
Browse files Browse the repository at this point in the history
  • Loading branch information
giscafer committed Aug 28, 2024
1 parent ff3a5f0 commit 4c975f2
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,21 @@ function setGlobalVariable() {
globalState.stockGroups = LeekFundConfig.getConfig('leek-fund.stockGroups') || [];

const stockLists = LeekFundConfig.getConfig('leek-fund.stocks') || [];
if (typeof stockLists[0] === 'string' || stockLists[0] instanceof String) {
// 迁移用户的股票代码到分组模式
const newStockLists = [stockLists];
// 如果不是分组时,迁移用户的股票代码到分组模式
if (!(Array.isArray(stockLists[0]))) {
// fix: https://github.com/LeekHub/leek-fund/issues/459

const newStockLists = [];
const defaultGroup: string[] = [];
stockLists.forEach((code: string | string[]) => {
if (!code) return;
if (typeof code === 'string') {
defaultGroup.push(code);
} else if (Array.isArray(code)) {
newStockLists.push(code);
}
});
newStockLists.unshift(defaultGroup);
globalState.stockLists = newStockLists;
LeekFundConfig.setConfig('leek-fund.stocks', newStockLists);
LeekFundConfig.setConfig('leek-fund.stockGroups', ['My Stocks']);
Expand Down

0 comments on commit 4c975f2

Please sign in to comment.