use full amount with wire fees when creating deposit permission
This commit is contained in:
parent
c62ba4986f
commit
d4c2f6f6f9
@ -293,8 +293,9 @@ export class CryptoApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
signDeposit(contractTerms: ContractTerms,
|
signDeposit(contractTerms: ContractTerms,
|
||||||
cds: CoinWithDenom[]): Promise<PayCoinInfo> {
|
cds: CoinWithDenom[],
|
||||||
return this.doRpc<PayCoinInfo>("signDeposit", 3, contractTerms, cds);
|
totalAmount: AmountJson): Promise<PayCoinInfo> {
|
||||||
|
return this.doRpc<PayCoinInfo>("signDeposit", 3, contractTerms, cds, totalAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
createEddsaKeypair(): Promise<{priv: string, pub: string}> {
|
createEddsaKeypair(): Promise<{priv: string, pub: string}> {
|
||||||
|
@ -269,7 +269,8 @@ namespace RpcFunctions {
|
|||||||
* and deposit permissions for each given coin.
|
* and deposit permissions for each given coin.
|
||||||
*/
|
*/
|
||||||
export function signDeposit(contractTerms: ContractTerms,
|
export function signDeposit(contractTerms: ContractTerms,
|
||||||
cds: CoinWithDenom[]): PayCoinInfo {
|
cds: CoinWithDenom[],
|
||||||
|
totalAmount: AmountJson): PayCoinInfo {
|
||||||
const ret: PayCoinInfo = {
|
const ret: PayCoinInfo = {
|
||||||
originalCoins: [],
|
originalCoins: [],
|
||||||
sigs: [],
|
sigs: [],
|
||||||
@ -282,7 +283,7 @@ namespace RpcFunctions {
|
|||||||
let fees = Amounts.add(Amounts.getZero(feeList[0].currency), ...feeList).amount;
|
let fees = Amounts.add(Amounts.getZero(feeList[0].currency), ...feeList).amount;
|
||||||
// okay if saturates
|
// okay if saturates
|
||||||
fees = Amounts.sub(fees, contractTerms.max_fee).amount;
|
fees = Amounts.sub(fees, contractTerms.max_fee).amount;
|
||||||
const total = Amounts.add(fees, contractTerms.amount).amount;
|
const total = Amounts.add(fees, totalAmount).amount;
|
||||||
|
|
||||||
const amountSpent = native.Amount.getZero(cds[0].coin.currentAmount.currency);
|
const amountSpent = native.Amount.getZero(cds[0].coin.currentAmount.currency);
|
||||||
const amountRemaining = new native.Amount(total);
|
const amountRemaining = new native.Amount(total);
|
||||||
|
@ -593,15 +593,23 @@ export class Wallet {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("payment coins: wireFeeLimit", wireFeeLimit);
|
||||||
|
console.log("payment coins: wireFeeAmortization", wireFeeAmortization);
|
||||||
|
console.log("payment coins: fees", fees);
|
||||||
|
console.log("payment coins: wireMethod", wireMethod);
|
||||||
|
console.log("payment coins: wireFeeTime", wireFeeTime);
|
||||||
|
|
||||||
let totalFees = Amounts.getZero(currency);
|
let totalFees = Amounts.getZero(currency);
|
||||||
let wireFee: AmountJson|undefined;
|
let wireFee: AmountJson|undefined;
|
||||||
for (const fee of (fees.feesForType[wireMethod] || [])) {
|
for (const fee of (fees.feesForType[wireMethod] || [])) {
|
||||||
if (fee.startStamp >= wireFeeTime && fee.endStamp <= wireFeeTime) {
|
if (fee.startStamp <= wireFeeTime && fee.endStamp >= wireFeeTime) {
|
||||||
wireFee = fee.wireFee;
|
wireFee = fee.wireFee;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("payment coins: current wire fees", wireFee);
|
||||||
|
|
||||||
if (wireFee) {
|
if (wireFee) {
|
||||||
const amortizedWireFee = Amounts.divide(wireFee, wireFeeAmortization);
|
const amortizedWireFee = Amounts.divide(wireFee, wireFeeAmortization);
|
||||||
if (Amounts.cmp(wireFeeLimit, amortizedWireFee) < 0) {
|
if (Amounts.cmp(wireFeeLimit, amortizedWireFee) < 0) {
|
||||||
@ -616,6 +624,7 @@ export class Wallet {
|
|||||||
return {
|
return {
|
||||||
cds: res.cds,
|
cds: res.cds,
|
||||||
exchangeUrl: exchange.baseUrl,
|
exchangeUrl: exchange.baseUrl,
|
||||||
|
totalAmount: remainingAmount,
|
||||||
totalFees,
|
totalFees,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -766,8 +775,8 @@ export class Wallet {
|
|||||||
|
|
||||||
const sd = await this.getSpeculativePayData(proposalId);
|
const sd = await this.getSpeculativePayData(proposalId);
|
||||||
if (!sd) {
|
if (!sd) {
|
||||||
const { exchangeUrl, cds } = res;
|
const { exchangeUrl, cds, totalAmount } = res;
|
||||||
const payCoinInfo = await this.cryptoApi.signDeposit(proposal.contractTerms, cds);
|
const payCoinInfo = await this.cryptoApi.signDeposit(proposal.contractTerms, cds, totalAmount);
|
||||||
purchase = await this.recordConfirmPay(proposal, payCoinInfo, exchangeUrl);
|
purchase = await this.recordConfirmPay(proposal, payCoinInfo, exchangeUrl);
|
||||||
} else {
|
} else {
|
||||||
purchase = await this.recordConfirmPay(sd.proposal, sd.payCoinInfo, sd.exchangeUrl);
|
purchase = await this.recordConfirmPay(sd.proposal, sd.payCoinInfo, sd.exchangeUrl);
|
||||||
@ -844,8 +853,8 @@ export class Wallet {
|
|||||||
|
|
||||||
// Only create speculative signature if we don't already have one for this proposal
|
// Only create speculative signature if we don't already have one for this proposal
|
||||||
if ((!this.speculativePayData) || (this.speculativePayData && this.speculativePayData.proposalId !== proposalId)) {
|
if ((!this.speculativePayData) || (this.speculativePayData && this.speculativePayData.proposalId !== proposalId)) {
|
||||||
const { exchangeUrl, cds } = res;
|
const { exchangeUrl, cds, totalAmount } = res;
|
||||||
const payCoinInfo = await this.cryptoApi.signDeposit(proposal.contractTerms, cds);
|
const payCoinInfo = await this.cryptoApi.signDeposit(proposal.contractTerms, cds, totalAmount);
|
||||||
this.speculativePayData = {
|
this.speculativePayData = {
|
||||||
exchangeUrl,
|
exchangeUrl,
|
||||||
payCoinInfo,
|
payCoinInfo,
|
||||||
@ -2456,7 +2465,7 @@ export class Wallet {
|
|||||||
|
|
||||||
const contractTermsHash = await this.cryptoApi.hashString(canonicalJson(contractTerms));
|
const contractTermsHash = await this.cryptoApi.hashString(canonicalJson(contractTerms));
|
||||||
|
|
||||||
const payCoinInfo = await this.cryptoApi.signDeposit(contractTerms, cds);
|
const payCoinInfo = await this.cryptoApi.signDeposit(contractTerms, cds, contractTerms.amount);
|
||||||
|
|
||||||
console.log("pci", payCoinInfo);
|
console.log("pci", payCoinInfo);
|
||||||
|
|
||||||
|
@ -415,6 +415,10 @@ export interface CoinSelectionResult {
|
|||||||
exchangeUrl: string;
|
exchangeUrl: string;
|
||||||
cds: CoinWithDenom[];
|
cds: CoinWithDenom[];
|
||||||
totalFees: AmountJson;
|
totalFees: AmountJson;
|
||||||
|
/**
|
||||||
|
* Total amount, including wire fees payed by the customer.
|
||||||
|
*/
|
||||||
|
totalAmount: AmountJson;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user