-
Notifications
You must be signed in to change notification settings - Fork 1
/
getBalance.ts
43 lines (37 loc) · 963 Bytes
/
getBalance.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
import {isNear} from '@spinfi/shared';
import {getBalanceNear} from './getBalanceNear';
import {getBalanceFt} from './getBalanceFt';
import {createView} from '../utils/createView';
/**
* @category getBalance
*/
export type GetBalanceResponse = string;
/**
* @category getBalance
*/
export interface GetBalanceRequest {
/**
* Account ID
*/
accountId: string;
/**
* Token Address
*/
tokenAddress: string;
}
export const getBalance = createView<GetBalanceRequest, GetBalanceResponse>(({methodify}) => {
const createMethod = methodify((config) => {
const getBalanceNearMethod = getBalanceNear.createMethod(config);
const getBalanceFtMethod = getBalanceFt.createMethod(config);
return async (request) => {
if (isNear(request.tokenAddress)) {
return await getBalanceNearMethod(request);
} else {
return await getBalanceFtMethod(request);
}
};
});
return {
createMethod,
};
});