11import { ConfigFields } from '@siafoundation/design-system'
22import { Quota } from '@siafoundation/indexd-types'
3- import { humanBytes } from '@siafoundation/units'
3+ import { bytesToGiB , GiBToBytes } from '@siafoundation/units'
44import BigNumber from 'bignumber.js'
55
66export type QuotaData = {
@@ -9,8 +9,10 @@ export type QuotaData = {
99 description : string
1010 maxPinnedData : number
1111 totalUses : number
12+ fundTargetBytes : number
1213 displayFields : {
1314 maxPinnedData : string
15+ fundTargetBytes : string
1416 }
1517}
1618
@@ -21,31 +23,40 @@ export function transformDownData(quota: Quota): QuotaData {
2123 description : quota . description ,
2224 maxPinnedData : quota . maxPinnedData ,
2325 totalUses : quota . totalUses ,
26+ fundTargetBytes : quota . fundTargetBytes ,
2427 displayFields : {
25- maxPinnedData : humanBytes ( quota . maxPinnedData ) ,
28+ maxPinnedData : `${ bytesToGiB ( quota . maxPinnedData ) . toFixed ( 2 ) } GiB` ,
29+ fundTargetBytes : `${ bytesToGiB ( quota . fundTargetBytes ) . toFixed ( 2 ) } GiB` ,
2630 } ,
2731 }
2832}
2933
3034function transformDownForm (
31- quota : Pick < QuotaData , 'description' | 'maxPinnedData' | 'totalUses' > ,
35+ quota : Pick <
36+ QuotaData ,
37+ 'description' | 'maxPinnedData' | 'totalUses' | 'fundTargetBytes'
38+ > ,
3239) : Values {
3340 return {
3441 description : quota . description ,
35- maxPinnedDataGB : new BigNumber ( quota . maxPinnedData ) . div ( 1e9 ) ,
42+ maxPinnedDataGiB : bytesToGiB ( quota . maxPinnedData ) ,
3643 totalUses : new BigNumber ( quota . totalUses ) ,
44+ fundTargetBytesGiB : bytesToGiB ( quota . fundTargetBytes ) ,
3745 }
3846}
3947
4048export function transformUpForm (
4149 values : Values ,
42- ) : Pick < Quota , 'description' | 'maxPinnedData' | 'totalUses' > {
50+ ) : Pick < Quota , 'description' | 'maxPinnedData' | 'totalUses' | 'fundTargetBytes' > {
4351 return {
4452 description : values . description ,
45- maxPinnedData : values . maxPinnedDataGB
46- ? values . maxPinnedDataGB . times ( 1e9 ) . toNumber ( )
53+ maxPinnedData : values . maxPinnedDataGiB
54+ ? GiBToBytes ( values . maxPinnedDataGiB ) . toNumber ( )
4755 : 0 ,
4856 totalUses : values . totalUses ? values . totalUses . toNumber ( ) : 0 ,
57+ fundTargetBytes : values . fundTargetBytesGiB
58+ ? GiBToBytes ( values . fundTargetBytesGiB ) . toNumber ( )
59+ : 0 ,
4960 }
5061}
5162
@@ -63,8 +74,9 @@ export function transformDown(response: Quota): {
6374
6475export const defaultValues = {
6576 description : '' ,
66- maxPinnedDataGB : undefined as undefined | BigNumber ,
77+ maxPinnedDataGiB : undefined as undefined | BigNumber ,
6778 totalUses : undefined as undefined | BigNumber ,
79+ fundTargetBytesGiB : new BigNumber ( 16 ) as undefined | BigNumber ,
6880}
6981
7082export type Values = typeof defaultValues
@@ -79,10 +91,10 @@ export function getFields(): ConfigFields<typeof defaultValues, never> {
7991 required : 'required' ,
8092 } ,
8193 } ,
82- maxPinnedDataGB : {
94+ maxPinnedDataGiB : {
8395 type : 'number' ,
8496 title : 'Max pinned data' ,
85- units : 'GB ' ,
97+ units : 'GiB ' ,
8698 decimalsLimit : 2 ,
8799 placeholder : '100' ,
88100 validation : {
@@ -98,5 +110,15 @@ export function getFields(): ConfigFields<typeof defaultValues, never> {
98110 required : 'required' ,
99111 } ,
100112 } ,
113+ fundTargetBytesGiB : {
114+ type : 'number' ,
115+ title : 'Fund target' ,
116+ units : 'GiB' ,
117+ decimalsLimit : 2 ,
118+ placeholder : '16' ,
119+ validation : {
120+ required : 'required' ,
121+ } ,
122+ } ,
101123 }
102124}
0 commit comments