provider: wire beacon + return balance + use cached balance
This commit is contained in:
parent
c8ede119d6
commit
8e4a8b2a2a
17 changed files with 307 additions and 92 deletions
|
|
@ -983,6 +983,48 @@ export const BannedAppUserValidate = (o?: BannedAppUser, opts: BannedAppUserOpti
|
|||
return null
|
||||
}
|
||||
|
||||
export type BeaconData = {
|
||||
avatarUrl?: string
|
||||
fees?: CumulativeFees
|
||||
name: string
|
||||
nextRelay?: string
|
||||
type: string
|
||||
}
|
||||
export type BeaconDataOptionalField = 'avatarUrl' | 'fees' | 'nextRelay'
|
||||
export const BeaconDataOptionalFields: BeaconDataOptionalField[] = ['avatarUrl', 'fees', 'nextRelay']
|
||||
export type BeaconDataOptions = OptionsBaseMessage & {
|
||||
checkOptionalsAreSet?: BeaconDataOptionalField[]
|
||||
avatarUrl_CustomCheck?: (v?: string) => boolean
|
||||
fees_Options?: CumulativeFeesOptions
|
||||
name_CustomCheck?: (v: string) => boolean
|
||||
nextRelay_CustomCheck?: (v?: string) => boolean
|
||||
type_CustomCheck?: (v: string) => boolean
|
||||
}
|
||||
export const BeaconDataValidate = (o?: BeaconData, opts: BeaconDataOptions = {}, path: string = 'BeaconData::root.'): Error | null => {
|
||||
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
|
||||
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
|
||||
|
||||
if ((o.avatarUrl || opts.allOptionalsAreSet || opts.checkOptionalsAreSet?.includes('avatarUrl')) && typeof o.avatarUrl !== 'string') return new Error(`${path}.avatarUrl: is not a string`)
|
||||
if (opts.avatarUrl_CustomCheck && !opts.avatarUrl_CustomCheck(o.avatarUrl)) return new Error(`${path}.avatarUrl: custom check failed`)
|
||||
|
||||
if (typeof o.fees === 'object' || opts.allOptionalsAreSet || opts.checkOptionalsAreSet?.includes('fees')) {
|
||||
const feesErr = CumulativeFeesValidate(o.fees, opts.fees_Options, `${path}.fees`)
|
||||
if (feesErr !== null) return feesErr
|
||||
}
|
||||
|
||||
|
||||
if (typeof o.name !== 'string') return new Error(`${path}.name: is not a string`)
|
||||
if (opts.name_CustomCheck && !opts.name_CustomCheck(o.name)) return new Error(`${path}.name: custom check failed`)
|
||||
|
||||
if ((o.nextRelay || opts.allOptionalsAreSet || opts.checkOptionalsAreSet?.includes('nextRelay')) && typeof o.nextRelay !== 'string') return new Error(`${path}.nextRelay: is not a string`)
|
||||
if (opts.nextRelay_CustomCheck && !opts.nextRelay_CustomCheck(o.nextRelay)) return new Error(`${path}.nextRelay: custom check failed`)
|
||||
|
||||
if (typeof o.type !== 'string') return new Error(`${path}.type: is not a string`)
|
||||
if (opts.type_CustomCheck && !opts.type_CustomCheck(o.type)) return new Error(`${path}.type: custom check failed`)
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export type BundleData = {
|
||||
available_chunks: number[]
|
||||
base_64_data: string[]
|
||||
|
|
@ -1256,6 +1298,34 @@ export const CreateOneTimeInviteLinkResponseValidate = (o?: CreateOneTimeInviteL
|
|||
return null
|
||||
}
|
||||
|
||||
export type CumulativeFees = {
|
||||
networkFeeBps: number
|
||||
networkFeeFixed: number
|
||||
serviceFeeBps: number
|
||||
}
|
||||
export const CumulativeFeesOptionalFields: [] = []
|
||||
export type CumulativeFeesOptions = OptionsBaseMessage & {
|
||||
checkOptionalsAreSet?: []
|
||||
networkFeeBps_CustomCheck?: (v: number) => boolean
|
||||
networkFeeFixed_CustomCheck?: (v: number) => boolean
|
||||
serviceFeeBps_CustomCheck?: (v: number) => boolean
|
||||
}
|
||||
export const CumulativeFeesValidate = (o?: CumulativeFees, opts: CumulativeFeesOptions = {}, path: string = 'CumulativeFees::root.'): Error | null => {
|
||||
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
|
||||
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
|
||||
|
||||
if (typeof o.networkFeeBps !== 'number') return new Error(`${path}.networkFeeBps: is not a number`)
|
||||
if (opts.networkFeeBps_CustomCheck && !opts.networkFeeBps_CustomCheck(o.networkFeeBps)) return new Error(`${path}.networkFeeBps: custom check failed`)
|
||||
|
||||
if (typeof o.networkFeeFixed !== 'number') return new Error(`${path}.networkFeeFixed: is not a number`)
|
||||
if (opts.networkFeeFixed_CustomCheck && !opts.networkFeeFixed_CustomCheck(o.networkFeeFixed)) return new Error(`${path}.networkFeeFixed: custom check failed`)
|
||||
|
||||
if (typeof o.serviceFeeBps !== 'number') return new Error(`${path}.serviceFeeBps: is not a number`)
|
||||
if (opts.serviceFeeBps_CustomCheck && !opts.serviceFeeBps_CustomCheck(o.serviceFeeBps)) return new Error(`${path}.serviceFeeBps: custom check failed`)
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export type DebitAuthorization = {
|
||||
authorized: boolean
|
||||
debit_id: string
|
||||
|
|
@ -2112,17 +2182,22 @@ export const LiveManageRequestValidate = (o?: LiveManageRequest, opts: LiveManag
|
|||
}
|
||||
|
||||
export type LiveUserOperation = {
|
||||
latest_balance: number
|
||||
operation: UserOperation
|
||||
}
|
||||
export const LiveUserOperationOptionalFields: [] = []
|
||||
export type LiveUserOperationOptions = OptionsBaseMessage & {
|
||||
checkOptionalsAreSet?: []
|
||||
latest_balance_CustomCheck?: (v: number) => boolean
|
||||
operation_Options?: UserOperationOptions
|
||||
}
|
||||
export const LiveUserOperationValidate = (o?: LiveUserOperation, opts: LiveUserOperationOptions = {}, path: string = 'LiveUserOperation::root.'): Error | null => {
|
||||
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
|
||||
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
|
||||
|
||||
if (typeof o.latest_balance !== 'number') return new Error(`${path}.latest_balance: is not a number`)
|
||||
if (opts.latest_balance_CustomCheck && !opts.latest_balance_CustomCheck(o.latest_balance)) return new Error(`${path}.latest_balance: custom check failed`)
|
||||
|
||||
const operationErr = UserOperationValidate(o.operation, opts.operation_Options, `${path}.operation`)
|
||||
if (operationErr !== null) return operationErr
|
||||
|
||||
|
|
@ -3287,6 +3362,7 @@ export const PayInvoiceRequestValidate = (o?: PayInvoiceRequest, opts: PayInvoic
|
|||
|
||||
export type PayInvoiceResponse = {
|
||||
amount_paid: number
|
||||
latest_balance: number
|
||||
network_fee: number
|
||||
operation_id: string
|
||||
preimage: string
|
||||
|
|
@ -3296,6 +3372,7 @@ export const PayInvoiceResponseOptionalFields: [] = []
|
|||
export type PayInvoiceResponseOptions = OptionsBaseMessage & {
|
||||
checkOptionalsAreSet?: []
|
||||
amount_paid_CustomCheck?: (v: number) => boolean
|
||||
latest_balance_CustomCheck?: (v: number) => boolean
|
||||
network_fee_CustomCheck?: (v: number) => boolean
|
||||
operation_id_CustomCheck?: (v: string) => boolean
|
||||
preimage_CustomCheck?: (v: string) => boolean
|
||||
|
|
@ -3308,6 +3385,9 @@ export const PayInvoiceResponseValidate = (o?: PayInvoiceResponse, opts: PayInvo
|
|||
if (typeof o.amount_paid !== 'number') return new Error(`${path}.amount_paid: is not a number`)
|
||||
if (opts.amount_paid_CustomCheck && !opts.amount_paid_CustomCheck(o.amount_paid)) return new Error(`${path}.amount_paid: custom check failed`)
|
||||
|
||||
if (typeof o.latest_balance !== 'number') return new Error(`${path}.latest_balance: is not a number`)
|
||||
if (opts.latest_balance_CustomCheck && !opts.latest_balance_CustomCheck(o.latest_balance)) return new Error(`${path}.latest_balance: custom check failed`)
|
||||
|
||||
if (typeof o.network_fee !== 'number') return new Error(`${path}.network_fee: is not a number`)
|
||||
if (opts.network_fee_CustomCheck && !opts.network_fee_CustomCheck(o.network_fee)) return new Error(`${path}.network_fee: custom check failed`)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue