11import { AbstractModule } from '../../../core/abstract-module'
2+ import type { Override , RawDecimal } from '../../../utils/types'
23import type { Labrinth } from '../types'
34
5+ type RawPayoutBalance = Override <
6+ Labrinth . Payout . v3 . PayoutBalance ,
7+ {
8+ available : RawDecimal
9+ withdrawn_lifetime : RawDecimal
10+ withdrawn_ytd : RawDecimal
11+ pending : RawDecimal
12+ dates : Record < string , RawDecimal >
13+ }
14+ >
15+
16+ type RawTransactionItem =
17+ | Override <
18+ Extract < Labrinth . Payout . v3 . TransactionItem , { type : 'withdrawal' } > ,
19+ {
20+ amount : RawDecimal
21+ fee : RawDecimal | null
22+ }
23+ >
24+ | Override <
25+ Extract < Labrinth . Payout . v3 . TransactionItem , { type : 'payout_available' } > ,
26+ {
27+ amount : RawDecimal
28+ }
29+ >
30+
431export class LabrinthPayoutV3Module extends AbstractModule {
532 public getModuleID ( ) : string {
633 return 'labrinth_payout_v3'
@@ -12,11 +39,22 @@ export class LabrinthPayoutV3Module extends AbstractModule {
1239 * @returns Promise resolving to the user's payout balance
1340 */
1441 public async getBalance ( ) : Promise < Labrinth . Payout . v3 . PayoutBalance > {
15- return this . client . request < Labrinth . Payout . v3 . PayoutBalance > ( '/payout/balance' , {
42+ const balance = await this . client . request < RawPayoutBalance > ( '/payout/balance' , {
1643 api : 'labrinth' ,
1744 version : 3 ,
1845 method : 'GET' ,
1946 } )
47+
48+ return {
49+ ...balance ,
50+ available : Number ( balance . available ) ,
51+ withdrawn_lifetime : Number ( balance . withdrawn_lifetime ) ,
52+ withdrawn_ytd : Number ( balance . withdrawn_ytd ) ,
53+ pending : Number ( balance . pending ) ,
54+ dates : Object . fromEntries (
55+ Object . entries ( balance . dates ) . map ( ( [ date , amount ] ) => [ date , Number ( amount ) ] ) ,
56+ ) ,
57+ }
2058 }
2159
2260 /**
@@ -25,11 +63,26 @@ export class LabrinthPayoutV3Module extends AbstractModule {
2563 * @returns Promise resolving to an array of transaction items
2664 */
2765 public async getHistory ( ) : Promise < Labrinth . Payout . v3 . TransactionItem [ ] > {
28- return this . client . request < Labrinth . Payout . v3 . TransactionItem [ ] > ( '/payout/history' , {
66+ const history = await this . client . request < RawTransactionItem [ ] > ( '/payout/history' , {
2967 api : 'labrinth' ,
3068 version : 3 ,
3169 method : 'GET' ,
3270 } )
71+
72+ return history . map ( ( transaction ) => {
73+ if ( transaction . type === 'withdrawal' ) {
74+ return {
75+ ...transaction ,
76+ amount : Number ( transaction . amount ) ,
77+ fee : transaction . fee === null ? null : Number ( transaction . fee ) ,
78+ }
79+ }
80+
81+ return {
82+ ...transaction ,
83+ amount : Number ( transaction . amount ) ,
84+ }
85+ } )
3386 }
3487
3588 /**
0 commit comments