diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/cryptoLib.ts | 20 | ||||
| -rw-r--r-- | src/pages/tree.tsx | 2 | ||||
| -rw-r--r-- | src/wallet.ts | 13 | 
3 files changed, 29 insertions, 6 deletions
| diff --git a/src/cryptoLib.ts b/src/cryptoLib.ts index 6473e1b58..fe1d6f36b 100644 --- a/src/cryptoLib.ts +++ b/src/cryptoLib.ts @@ -173,8 +173,16 @@ namespace RpcFunctions {    export function signDeposit(offer: OfferRecord,                                cds: CoinWithDenom[]): PayCoinInfo {      let ret: PayCoinInfo = []; + + +    let feeList: AmountJson[] = cds.map((x) => x.denom.feeDeposit); +    let fees = Amounts.add(Amounts.getZero(feeList[0].currency), ...feeList).amount; +    // okay if saturates +    fees = Amounts.sub(fees, offer.contract.max_fee).amount; +    let total = Amounts.add(fees, offer.contract.amount).amount; +      let amountSpent = native.Amount.getZero(cds[0].coin.currentAmount.currency); -    let amountRemaining = new native.Amount(offer.contract.amount); +    let amountRemaining = new native.Amount(total);      for (let cd of cds) {        let coinSpend: Amount; @@ -191,6 +199,14 @@ namespace RpcFunctions {        amountSpent.add(coinSpend);        amountRemaining.sub(coinSpend); +      let feeDeposit: Amount = new native.Amount(cd.denom.feeDeposit); + +      // Give the merchant at least the deposit fee, otherwise it'll reject +      // the coin. +      if (coinSpend.cmp(feeDeposit) < 0) { +        coinSpend = feeDeposit; +      } +        let newAmount = new native.Amount(cd.coin.currentAmount);        newAmount.sub(coinSpend);        cd.coin.currentAmount = newAmount.toJson(); @@ -342,4 +358,4 @@ namespace RpcFunctions {      const b = native.ByteArray.fromStringWithNull(str);      return b.hash().toCrock();    } -}
\ No newline at end of file +} diff --git a/src/pages/tree.tsx b/src/pages/tree.tsx index 9eca80636..dab637147 100644 --- a/src/pages/tree.tsx +++ b/src/pages/tree.tsx @@ -124,6 +124,8 @@ class CoinView extends React.Component<CoinViewProps, void> {            <li>Current amount: {prettyAmount(c.currentAmount)}</li>            <li>Denomination: <ExpanderText text={c.denomPub} /></li>            <li>Suspended: {(c.suspended || false).toString()}</li> +          <li>Dirty: {(c.dirty || false).toString()}</li> +          <li>Transaction Pending: {(c.transactionPending || false).toString()}</li>            <li><RefreshDialog coin={c} /></li>          </ul>        </div> diff --git a/src/wallet.ts b/src/wallet.ts index 932d61eda..971fa6700 100644 --- a/src/wallet.ts +++ b/src/wallet.ts @@ -632,6 +632,9 @@ export class Wallet {                                              offer.contract.max_fee,                                              offer.contract.exchanges); +    console.log("max_fee", offer.contract.max_fee); +    console.log("coin selection result", res); +      if (!res) {        console.log("not confirming payment, insufficient coins");        return { @@ -1172,7 +1175,7 @@ export class Wallet {                           (e) => e.exchangeBaseUrl)            .reduce((cd: JoinLeftResult<CoinRecord,DenominationRecord>,                     suspendedCoins: CoinRecord[]) => { -            if (!cd.right || !cd.right.isOffered) { +            if ((!cd.right) || (!cd.right.isOffered)) {                return Array.prototype.concat(suspendedCoins, [cd.left]);              }              return Array.prototype.concat(suspendedCoins); @@ -1243,12 +1246,14 @@ export class Wallet {      );      const newDenoms: typeof existingDenoms = {}; +    const newAndUnseenDenoms: typeof existingDenoms = {};      for (let d of newKeys.denoms) { +      let dr = denominationRecordFromKeys(exchangeInfo.baseUrl, d);        if (!(d.denom_pub in existingDenoms)) { -        let dr = denominationRecordFromKeys(exchangeInfo.baseUrl, d); -        newDenoms[dr.denomPub] = dr; +        newAndUnseenDenoms[dr.denomPub] = dr;        } +      newDenoms[dr.denomPub] = dr;      }      for (let oldDenomPub in existingDenoms) { @@ -1260,7 +1265,7 @@ export class Wallet {      await this.q()                .putAll(Stores.denominations, -                      Object.keys(newDenoms).map((d) => newDenoms[d])) +                      Object.keys(newAndUnseenDenoms).map((d) => newAndUnseenDenoms[d]))                .putAll(Stores.denominations,                        Object.keys(existingDenoms).map((d) => existingDenoms[d]))                .finish(); | 
