-
Notifications
You must be signed in to change notification settings - Fork 1
/
blockfi.ts
46 lines (41 loc) · 1.15 KB
/
blockfi.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import Plugin, { TRANSACTION_TYPE } from './common/plugin';
export default class BlockFi extends Plugin {
public getNames(): string[] {
return ['blockfi'];
}
// Cryptocurrency,Amount,Transaction Type,Confirmed At
async convertRow(line: string[]): Promise<string[] | null> {
const type = this._getType(line[2]);
if (type === TRANSACTION_TYPE.UNKNOWN) {
return Promise.resolve(null);
}
const date = new Date(Date.parse(line[3]));
const amount = parseFloat(line[1]);
const price = await this._api.getPrice(line[0], date);
if (!price) {
return Promise.resolve(null);
}
const row = this.toRow(
date,
type,
'BlockFi',
price.coin.name,
price.coin.symbol,
amount,
price?.price
);
return Promise.resolve(row);
}
private _getType(input: string): TRANSACTION_TYPE {
if (input.includes('Interest Payment')) {
return TRANSACTION_TYPE.LENDING;
}
if (input.includes('Bonus Payment')) {
return TRANSACTION_TYPE.GIFT;
}
if (input.includes('Deposit')) {
return TRANSACTION_TYPE.DEPOSIT;
}
return TRANSACTION_TYPE.UNKNOWN;
}
}