Skip to content

Commit

Permalink
fix: binance 请求失败会提示错误 data of undefined 问题
Browse files Browse the repository at this point in the history
  • Loading branch information
giscafer committed Jan 6, 2021
1 parent d24004a commit 1f9deea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@
"id": "leekFundView.news",
"name": "XueQiu News"
},
{
"id": "leekFundView.settings",
"visibility": "visible",
"name": "Settings"
},
{
"id": "leekFundView.binance",
"name": "Binance",
"visibility": "hidden"
},
{
"id": "leekFundView.settings",
"visibility": "visible",
"name": "Settings"
}
]
},
Expand Down
14 changes: 7 additions & 7 deletions src/explorer/binanceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default class BinanceService extends LeekService {
constructor(context: ExtensionContext) {
super();
this.context = context;
console.log(this.context);
}

/** 获取支持的交易对 */
Expand All @@ -33,8 +32,10 @@ export default class BinanceService extends LeekService {
error: err,
});
});
// console.log(res);
return res?.data?.symbols?.map((i: any) => `${i.baseAsset}_${i.quoteAsset}`);
if (res && res.data) {
return res.data.symbols?.map((i: any) => `${i.baseAsset}_${i.quoteAsset}`);
}
return [''];
}

async _fetchPairData(symbolWithSplit: string): Promise<any> {
Expand All @@ -59,13 +60,12 @@ export default class BinanceService extends LeekService {
const promises = codes.map((i) => this._fetchPairData(i));
// @ts-ignore
const results = await Promise.allSettled(promises);
console.log(results);
// console.log('results=', results);

for (const item of results) {
// @ts-ignore
const { status, value = {} } = item || {};
if (status === 'fulfilled') {
// status === 'fulfilled'
if (status === 'fulfilled' && value.data) {
const {
data: { data },
symbol,
Expand Down Expand Up @@ -94,7 +94,7 @@ export default class BinanceService extends LeekService {
id: symbol,
code: '',
percent: '0',
name: symbol,
name: symbol + '网络错误',
showLabel: this.showLabel,
_itemType: TreeItemType.BINANCE,
};
Expand Down

0 comments on commit 1f9deea

Please sign in to comment.