Skip to content

Commit

Permalink
api: fix double notif on payment link claim (#1061)
Browse files Browse the repository at this point in the history
  • Loading branch information
nalinbhardwaj authored May 22, 2024
1 parent 73edb73 commit 1185b6c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
40 changes: 19 additions & 21 deletions packages/daimo-api/src/server/pushNotifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
DaimoNoteStatus,
DaimoRequestState,
DaimoRequestV2Status,
PreSwapTransfer,
DisplayOpEvent,
amountToDollars,
assert,
assertNotNull,
Expand Down Expand Up @@ -171,18 +171,14 @@ export class PushNotifier {
from,
to,
-opEvent.amount,
opEvent.type === "transfer" ? opEvent.memo : undefined,
false,
opEvent.type === "transfer" ? opEvent.preSwapTransfer : undefined
opEvent
),
this.getPushMessagesFromTransfer(
log.transactionHash,
to,
from,
opEvent.amount,
opEvent.type === "transfer" ? opEvent.memo : undefined,
opEvent.type === "transfer" && opEvent.requestStatus != null,
opEvent.type === "transfer" ? opEvent.preSwapTransfer : undefined
opEvent
),
]);
messages.push(...a, ...b);
Expand Down Expand Up @@ -229,10 +225,10 @@ export class PushNotifier {
addr: Address,
other: Address,
amount: number,
memo: string | undefined,
receivingRequestedMoney: boolean,
preSwapTransfer: PreSwapTransfer | undefined
opEvent: DisplayOpEvent
): Promise<ExpoPushMessage[]> {
if (opEvent.type !== "transfer") return []; // Only transfer opEvents handled here

const pushTokens = this.pushTokens.get(addr);
if (!pushTokens || pushTokens.length === 0) return [];

Expand All @@ -241,35 +237,37 @@ export class PushNotifier {

// Get the other side
const otherAcc = await this.nameReg.getEAccount(other);
if (otherAcc.label === AddrLabel.PaymentLink) {
// Handled separately, see maybeNotifyPaymentLink
return [];
} else if (otherAcc.label === AddrLabel.Paymaster) {

if (otherAcc.label === AddrLabel.Paymaster) {
// ignore paymaster transfers
return [];
}

const otherStr = getAccountName(otherAcc);

const title = (() => {
if (preSwapTransfer) {
if (opEvent.preSwapTransfer) {
assert(amount > 0); // foreignCoin can only be involved in receiving ends of swaps
return `Accepted $${dollars} from ${otherStr}`;
} else if (amount < 0) return `Sent $${dollars} to ${otherStr}`;
else return `Received $${dollars} from ${otherStr}`;
})();

const body = (() => {
if (memo) return memo;
if (receivingRequestedMoney)
if (opEvent.memo) return opEvent.memo;

if (opEvent.requestStatus)
return `Your ${dollars} ${tokenSymbol} request was fulfilled`;
if (preSwapTransfer) {

if (opEvent.preSwapTransfer) {
assert(amount > 0); // foreignCoin can only be involved in receiving ends of swaps
const readableAmount = getForeignCoinDisplayAmount(
preSwapTransfer.amount,
preSwapTransfer.coin
opEvent.preSwapTransfer.amount,
opEvent.preSwapTransfer.coin
);
return `You accepted ${readableAmount} ${preSwapTransfer.coin.symbol} as $${dollars} ${tokenSymbol}`;
return `You accepted ${readableAmount} ${opEvent.preSwapTransfer.coin.symbol} as $${dollars} ${tokenSymbol}`;
}

if (amount < 0)
return `You sent ${dollars} ${tokenSymbol} to ${otherStr}`;
return `You received ${dollars} ${tokenSymbol} from ${otherStr}`;
Expand Down
10 changes: 6 additions & 4 deletions packages/daimo-common/src/op.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export type DaimoAccountCall = {
// Gets the logical from and to-addresses for a given op
// If the op creates a payment link, to = payment link until claimed, then it's
// the address of the claimer.
// If the op claims a payment link, from = sender, to = claimer.
// If the op is a swap, from = the pre-swap sender.
export function getDisplayFromTo(op: DisplayOpEvent): [Address, Address] {
if (op.type === "transfer") {
Expand All @@ -171,10 +172,11 @@ export function getDisplayFromTo(op: DisplayOpEvent): [Address, Address] {
if (op.noteStatus.claimer?.addr === op.noteStatus.sender.addr) {
// Self-transfer via payment link shows up as two payment link transfers
return [op.from, op.to];
} else {
return [
op.noteStatus.sender.addr,
op.noteStatus.claimer ? op.noteStatus.claimer.addr : op.to,
];
}
return [
op.noteStatus.sender.addr,
op.noteStatus.claimer ? op.noteStatus.claimer.addr : op.to,
];
}
}

0 comments on commit 1185b6c

Please sign in to comment.