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

feat: add biance sort #488

Merged
merged 1 commit into from
Oct 17, 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
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@
{
"command": "leek-fund.toggleStatusBarVisibility",
"title": "LeekFund: Toggle Status Bar Visibility"
},
{
"command": "leek-fund.binanceSort",
"title": "升序/降序/不排序",
"icon": {
"light": "resources/light/sort.svg",
"dark": "resources/dark/sort.svg"
}
}
],
"menus": {
Expand Down Expand Up @@ -377,6 +385,11 @@
"when": "view == leekFundView.binance",
"group": "navigation"
},
{
"command": "leek-fund.binanceSort",
"when": "view == leekFundView.binance",
"group": "navigation"
},
{
"command": "leek-fund.refreshForex",
"when": "view == leekFundView.forex",
Expand Down Expand Up @@ -795,4 +808,4 @@
"ui",
"workspace"
]
}
}
20 changes: 15 additions & 5 deletions src/explorer/binanceProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import { Event, EventEmitter, TreeDataProvider, TreeItem } from 'vscode';
import { LeekFundConfig } from '../shared/leekConfig';
import { LeekTreeItem } from '../shared/leekTreeItem';
import BinanceService from './binanceService';
import { SortType } from '../shared/typed';

export class BinanceProvider implements TreeDataProvider<any> {
private _onDidChangeTreeData: EventEmitter<any> = new EventEmitter<any>();
private service: BinanceService;
readonly onDidChangeTreeData: Event<any> = this._onDidChangeTreeData.event;
// TODO: 未完成排序功能
// private order: SortType;
private order: SortType = SortType.NORMAL;

constructor(service: BinanceService) {
this.service = service;
// this.order = LeekFundConfig.getConfig('leek-fund.binanceSort') || SortType.NORMAL;
this.order = LeekFundConfig.getConfig('leek-fund.binanceSort') || SortType.NORMAL;
}

getTreeItem(element: any): TreeItem | Thenable<TreeItem> {
Expand All @@ -28,7 +28,7 @@ export class BinanceProvider implements TreeDataProvider<any> {

getChildren(): LeekTreeItem[] | Thenable<LeekTreeItem[]> {
const paris = LeekFundConfig.getConfig('leek-fund.binance') || [];
return this.service.getData(paris);
return this.service.getData(paris, this.order);
}

getParent?() {
Expand All @@ -45,6 +45,16 @@ export class BinanceProvider implements TreeDataProvider<any> {
/** Modify order */
changeOrder(): void {
// leek-fund.binanceSort
throw new Error('Method not implemented.');
let order = this.order as number;
order += 1;
if (order > 1) {
this.order = SortType.DESC;
} else if (order === 1) {
this.order = SortType.ASC;
} else if (order === 0) {
this.order = SortType.NORMAL;
}
LeekFundConfig.setConfig('leek-fund.binanceSort', this.order);
this.refresh();
}
}
9 changes: 4 additions & 5 deletions src/explorer/binanceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import Axios from 'axios';
import { ExtensionContext } from 'vscode';
import globalState from '../globalState';
import { LeekTreeItem } from '../shared/leekTreeItem';
import { FundInfo, TreeItemType } from '../shared/typed';
import { randHeader } from '../shared/utils';
import { FundInfo, SortType, TreeItemType } from '../shared/typed';
import { randHeader, sortData } from '../shared/utils';
import { LeekService } from './leekService';

export default class BinanceService extends LeekService {
Expand Down Expand Up @@ -55,7 +55,7 @@ export default class BinanceService extends LeekService {
});
}

async getData(codes: string[]): Promise<LeekTreeItem[]> {
async getData(codes: string[], order: SortType): Promise<LeekTreeItem[]> {
const pairList: Array<LeekTreeItem> = [];

// 20个请求的权重最低
Expand All @@ -80,7 +80,6 @@ export default class BinanceService extends LeekService {
}

const results = await Promise.allSettled(promises);
// console.log(results, 'results')
for (const splitRes of results) {
// @ts-ignore
const { status, value, reason } = splitRes;
Expand Down Expand Up @@ -123,6 +122,6 @@ export default class BinanceService extends LeekService {
}

}
return pairList;
return sortData(pairList, order);
}
}
5 changes: 5 additions & 0 deletions src/registerCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,11 @@ export function registerViewEvent(
});
});

/* 排序 */
commands.registerCommand('leek-fund.binanceSort', () => {
binanceProvider.changeOrder();
});

/**
* Forex command
*/
Expand Down
Loading