wallet-core: fix coin allocation when doing refresh
This commit is contained in:
parent
566248aec4
commit
cc2122b50c
@ -142,6 +142,8 @@ export async function spendCoins(
|
|||||||
}
|
}
|
||||||
if (alloc.id !== csi.allocationId) {
|
if (alloc.id !== csi.allocationId) {
|
||||||
// FIXME: assign error code
|
// FIXME: assign error code
|
||||||
|
logger.info("conflicting coin allocation ID");
|
||||||
|
logger.info(`old ID: ${alloc.id}, new ID: ${csi.allocationId}`);
|
||||||
throw Error("conflicting coin allocation (id)");
|
throw Error("conflicting coin allocation (id)");
|
||||||
}
|
}
|
||||||
if (0 !== Amounts.cmp(alloc.amount, contrib)) {
|
if (0 !== Amounts.cmp(alloc.amount, contrib)) {
|
||||||
|
@ -890,10 +890,6 @@ export async function createRefreshGroup(
|
|||||||
);
|
);
|
||||||
switch (coin.status) {
|
switch (coin.status) {
|
||||||
case CoinStatus.Dormant:
|
case CoinStatus.Dormant:
|
||||||
coin.spendAllocation = {
|
|
||||||
amount: Amounts.stringify(ocp.amount),
|
|
||||||
id: `txn:refresh:${refreshGroupId}`,
|
|
||||||
};
|
|
||||||
break;
|
break;
|
||||||
case CoinStatus.Fresh: {
|
case CoinStatus.Fresh: {
|
||||||
coin.status = CoinStatus.Dormant;
|
coin.status = CoinStatus.Dormant;
|
||||||
@ -912,15 +908,17 @@ export async function createRefreshGroup(
|
|||||||
// For suspended coins, we don't have to adjust coin
|
// For suspended coins, we don't have to adjust coin
|
||||||
// availability, as they are not counted as available.
|
// availability, as they are not counted as available.
|
||||||
coin.status = CoinStatus.Dormant;
|
coin.status = CoinStatus.Dormant;
|
||||||
coin.spendAllocation = {
|
|
||||||
amount: Amounts.stringify(ocp.amount),
|
|
||||||
id: `txn:refresh:${refreshGroupId}`,
|
|
||||||
};
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
assertUnreachable(coin.status);
|
assertUnreachable(coin.status);
|
||||||
}
|
}
|
||||||
|
if (!coin.spendAllocation) {
|
||||||
|
coin.spendAllocation = {
|
||||||
|
amount: Amounts.stringify(ocp.amount),
|
||||||
|
id: `txn:refresh:${refreshGroupId}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
const refreshAmount = ocp.amount;
|
const refreshAmount = ocp.amount;
|
||||||
inputPerCoin.push(Amounts.parseOrThrow(refreshAmount));
|
inputPerCoin.push(Amounts.parseOrThrow(refreshAmount));
|
||||||
await tx.coins.put(coin);
|
await tx.coins.put(coin);
|
||||||
|
Loading…
Reference in New Issue
Block a user