get operation plan types
This commit is contained in:
parent
4ac67bbcdb
commit
671342818f
@ -71,7 +71,7 @@ import {
|
|||||||
codecForAbsoluteTime,
|
codecForAbsoluteTime,
|
||||||
codecForTimestamp,
|
codecForTimestamp,
|
||||||
} from "./time.js";
|
} from "./time.js";
|
||||||
import { OrderShortInfo } from "./transactions-types.js";
|
import { OrderShortInfo, TransactionType } from "./transactions-types.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Identifier for a transaction in the wallet.
|
* Identifier for a transaction in the wallet.
|
||||||
@ -159,6 +159,163 @@ export const codecForGetBalanceDetailRequest =
|
|||||||
.property("currency", codecForString())
|
.property("currency", codecForString())
|
||||||
.build("GetBalanceDetailRequest");
|
.build("GetBalanceDetailRequest");
|
||||||
|
|
||||||
|
export type GetPlanForOperationRequest =
|
||||||
|
| GetPlanForWithdrawRequest
|
||||||
|
| GetPlanForDepositRequest;
|
||||||
|
// | GetPlanForPushDebitRequest
|
||||||
|
// | GetPlanForPullCreditRequest
|
||||||
|
// | GetPlanForPaymentRequest
|
||||||
|
// | GetPlanForTipRequest
|
||||||
|
// | GetPlanForRefundRequest
|
||||||
|
// | GetPlanForPullDebitRequest
|
||||||
|
// | GetPlanForPushCreditRequest;
|
||||||
|
|
||||||
|
interface GetPlanForWalletInitiatedOperation {
|
||||||
|
instructedAmount: AmountString;
|
||||||
|
mode: "raw" | "effective";
|
||||||
|
}
|
||||||
|
|
||||||
|
interface GetPlanToCompleteOperation {
|
||||||
|
instructedAmount: AmountString;
|
||||||
|
}
|
||||||
|
|
||||||
|
const codecForGetPlanForWalletInitiatedOperation = <
|
||||||
|
T extends GetPlanForWalletInitiatedOperation,
|
||||||
|
>() =>
|
||||||
|
buildCodecForObject<T>()
|
||||||
|
.property(
|
||||||
|
"mode",
|
||||||
|
codecForEither(
|
||||||
|
codecForConstString("raw"),
|
||||||
|
codecForConstString("effective"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.property("instructedAmount", codecForAmountString());
|
||||||
|
|
||||||
|
interface GetPlanForWithdrawRequest extends GetPlanForWalletInitiatedOperation {
|
||||||
|
type: TransactionType.Withdrawal;
|
||||||
|
exchangeUrl?: string;
|
||||||
|
}
|
||||||
|
interface GetPlanForDepositRequest extends GetPlanForWalletInitiatedOperation {
|
||||||
|
type: TransactionType.Deposit;
|
||||||
|
account: string; //payto string
|
||||||
|
}
|
||||||
|
interface GetPlanForPushDebitRequest
|
||||||
|
extends GetPlanForWalletInitiatedOperation {
|
||||||
|
type: TransactionType.PeerPushDebit;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface GetPlanForPullCreditRequest
|
||||||
|
extends GetPlanForWalletInitiatedOperation {
|
||||||
|
type: TransactionType.PeerPullCredit;
|
||||||
|
exchangeUrl: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const codecForGetPlanForWithdrawRequest =
|
||||||
|
codecForGetPlanForWalletInitiatedOperation<GetPlanForWithdrawRequest>()
|
||||||
|
.property("type", codecForConstString(TransactionType.Withdrawal))
|
||||||
|
.property("exchangeUrl", codecOptional(codecForString()))
|
||||||
|
.build("GetPlanForWithdrawRequest");
|
||||||
|
|
||||||
|
const codecForGetPlanForDepositRequest =
|
||||||
|
codecForGetPlanForWalletInitiatedOperation<GetPlanForDepositRequest>()
|
||||||
|
.property("type", codecForConstString(TransactionType.Deposit))
|
||||||
|
.property("account", codecForString())
|
||||||
|
.build("GetPlanForDepositRequest");
|
||||||
|
|
||||||
|
const codecForGetPlanForPushDebitRequest =
|
||||||
|
codecForGetPlanForWalletInitiatedOperation<GetPlanForPushDebitRequest>()
|
||||||
|
.property("type", codecForConstString(TransactionType.PeerPushDebit))
|
||||||
|
.build("GetPlanForPushDebitRequest");
|
||||||
|
|
||||||
|
const codecForGetPlanForPullCreditRequest =
|
||||||
|
codecForGetPlanForWalletInitiatedOperation<GetPlanForPullCreditRequest>()
|
||||||
|
.property("type", codecForConstString(TransactionType.PeerPullCredit))
|
||||||
|
.property("exchangeUrl", codecForString())
|
||||||
|
.build("GetPlanForPullCreditRequest");
|
||||||
|
|
||||||
|
interface GetPlanForPaymentRequest extends GetPlanToCompleteOperation {
|
||||||
|
type: TransactionType.Payment;
|
||||||
|
wireMethod: string;
|
||||||
|
ageRestriction: number;
|
||||||
|
maxDepositFee: AmountString;
|
||||||
|
maxWireFee: AmountString;
|
||||||
|
}
|
||||||
|
|
||||||
|
// interface GetPlanForTipRequest extends GetPlanForOperationBase {
|
||||||
|
// type: TransactionType.Tip;
|
||||||
|
// }
|
||||||
|
// interface GetPlanForRefundRequest extends GetPlanForOperationBase {
|
||||||
|
// type: TransactionType.Refund;
|
||||||
|
// }
|
||||||
|
interface GetPlanForPullDebitRequest extends GetPlanToCompleteOperation {
|
||||||
|
type: TransactionType.PeerPullDebit;
|
||||||
|
}
|
||||||
|
interface GetPlanForPushCreditRequest extends GetPlanToCompleteOperation {
|
||||||
|
type: TransactionType.PeerPushCredit;
|
||||||
|
}
|
||||||
|
|
||||||
|
const codecForGetPlanForPaymentRequest =
|
||||||
|
buildCodecForObject<GetPlanForPaymentRequest>()
|
||||||
|
.property("type", codecForConstString(TransactionType.Payment))
|
||||||
|
.property("maxDepositFee", codecForAmountString())
|
||||||
|
.property("maxWireFee", codecForAmountString())
|
||||||
|
.build("GetPlanForPaymentRequest");
|
||||||
|
|
||||||
|
const codecForGetPlanForPullDebitRequest =
|
||||||
|
buildCodecForObject<GetPlanForPullDebitRequest>()
|
||||||
|
.property("type", codecForConstString(TransactionType.PeerPullDebit))
|
||||||
|
.build("GetPlanForPullDebitRequest");
|
||||||
|
|
||||||
|
const codecForGetPlanForPushCreditRequest =
|
||||||
|
buildCodecForObject<GetPlanForPushCreditRequest>()
|
||||||
|
.property("type", codecForConstString(TransactionType.PeerPushCredit))
|
||||||
|
.build("GetPlanForPushCreditRequest");
|
||||||
|
|
||||||
|
export const codecForGetPlanForOperationRequest =
|
||||||
|
(): Codec<GetPlanForOperationRequest> =>
|
||||||
|
buildCodecForUnion<GetPlanForOperationRequest>()
|
||||||
|
.discriminateOn("type")
|
||||||
|
.alternative(
|
||||||
|
TransactionType.Withdrawal,
|
||||||
|
codecForGetPlanForWithdrawRequest,
|
||||||
|
)
|
||||||
|
.alternative(TransactionType.Deposit, codecForGetPlanForDepositRequest)
|
||||||
|
// .alternative(
|
||||||
|
// TransactionType.PeerPushDebit,
|
||||||
|
// codecForGetPlanForPushDebitRequest,
|
||||||
|
// )
|
||||||
|
// .alternative(
|
||||||
|
// TransactionType.PeerPullCredit,
|
||||||
|
// codecForGetPlanForPullCreditRequest,
|
||||||
|
// )
|
||||||
|
// .alternative(TransactionType.Payment, codecForGetPlanForPaymentRequest)
|
||||||
|
// .alternative(
|
||||||
|
// TransactionType.PeerPullDebit,
|
||||||
|
// codecForGetPlanForPullDebitRequest,
|
||||||
|
// )
|
||||||
|
// .alternative(
|
||||||
|
// TransactionType.PeerPushCredit,
|
||||||
|
// codecForGetPlanForPushCreditRequest,
|
||||||
|
// )
|
||||||
|
.build("GetPlanForOperationRequest");
|
||||||
|
|
||||||
|
export interface GetPlanForOperationResponse {
|
||||||
|
effectiveAmount: AmountString;
|
||||||
|
rawAmount: AmountString;
|
||||||
|
counterPartyAmount?: AmountString;
|
||||||
|
details: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const codecForGetPlanForOperationResponse =
|
||||||
|
(): Codec<GetPlanForOperationResponse> =>
|
||||||
|
buildCodecForObject<GetPlanForOperationResponse>()
|
||||||
|
.property("effectiveAmount", codecForAmountString())
|
||||||
|
.property("rawAmount", codecForAmountString())
|
||||||
|
.property("details", codecForAny())
|
||||||
|
.property("counterPartyAmount", codecOptional(codecForAmountString()))
|
||||||
|
.build("GetPlanForOperationResponse");
|
||||||
|
|
||||||
export interface Balance {
|
export interface Balance {
|
||||||
scopeInfo: ScopeInfo;
|
scopeInfo: ScopeInfo;
|
||||||
available: AmountString;
|
available: AmountString;
|
||||||
|
Loading…
Reference in New Issue
Block a user