From d1e7a579af5b07d803a5685e553e5b4b94cf2619 Mon Sep 17 00:00:00 2001 From: dragosp1011 Date: Thu, 20 Feb 2025 11:58:13 +0200 Subject: [PATCH] feat: add second party wallet address --- ...7140155_second_party_pp_to_transactions.js | 19 +++++++++ .../wallet/backend/src/backfillTrxDetails.ts | 5 ++- packages/wallet/backend/src/rafiki/service.ts | 41 ++++++++++++++----- .../wallet/backend/src/transaction/model.ts | 4 +- .../wallet/backend/src/transaction/service.ts | 9 +++- .../wallet/shared/src/types/transaction.ts | 4 +- 6 files changed, 66 insertions(+), 16 deletions(-) create mode 100644 packages/wallet/backend/migrations/20250217140155_second_party_pp_to_transactions.js diff --git a/packages/wallet/backend/migrations/20250217140155_second_party_pp_to_transactions.js b/packages/wallet/backend/migrations/20250217140155_second_party_pp_to_transactions.js new file mode 100644 index 000000000..e9d6a88c1 --- /dev/null +++ b/packages/wallet/backend/migrations/20250217140155_second_party_pp_to_transactions.js @@ -0,0 +1,19 @@ +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +exports.up = function (knex) { + return knex.schema.table('transactions', function (table) { + table.string('secondPartyWA').nullable() + }) +} + +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +exports.down = function (knex) { + return knex.schema.table('transactions', function (table) { + table.dropColumn('secondPartyWA') + }) +} diff --git a/packages/wallet/backend/src/backfillTrxDetails.ts b/packages/wallet/backend/src/backfillTrxDetails.ts index 56665a441..d90879457 100644 --- a/packages/wallet/backend/src/backfillTrxDetails.ts +++ b/packages/wallet/backend/src/backfillTrxDetails.ts @@ -103,7 +103,10 @@ async function backfillTrxDetails() { } else { secondParty = await getOutgoingPaymentSecondParty(tx.paymentId) } - await Transaction.query().where('id', tx.id).update({ secondParty }) + await Transaction.query().where('id', tx.id).update({ + secondParty: secondParty?.names, + secondPartyWA: secondParty?.walletAddresses + }) console.log('trx updated') } diff --git a/packages/wallet/backend/src/rafiki/service.ts b/packages/wallet/backend/src/rafiki/service.ts index 10c0930ce..4e3330b12 100644 --- a/packages/wallet/backend/src/rafiki/service.ts +++ b/packages/wallet/backend/src/rafiki/service.ts @@ -1,6 +1,6 @@ import { Env } from '@/config/env' import { WalletAddress } from '@/walletAddress/model' -import { TransactionService } from '@/transaction/service' +import { ISecondParty, TransactionService } from '@/transaction/service' import { Logger } from 'winston' import { RafikiClient } from './rafiki-client' import { SocketService } from '@/socket/service' @@ -189,11 +189,16 @@ export class RafikiService implements IRafikiService { await this.rafikiClient.withdrawLiqudity(wh.id) - const senders = await this.getIncomingPaymentSenders(wh.data.id) + const secondParty = await this.getIncomingPaymentSenders(wh.data.id) await this.transactionService.updateTransaction( { paymentId: wh.data.id }, - { status: 'COMPLETED', value: amount.value, secondParty: senders } + { + status: 'COMPLETED', + value: amount.value, + secondParty: secondParty?.names, + secondPartyWA: secondParty?.walletAddresses + } ) const isExchange = NodeCacheInstance.get(wh.data.id) @@ -385,7 +390,7 @@ export class RafikiService implements IRafikiService { } } - async getIncomingPaymentSenders(id: string) { + async getIncomingPaymentSenders(id: string): Promise { try { const outgoingPayments = await this.rafikiClient.getOutgoingPaymentsByReceiver( @@ -398,10 +403,15 @@ export class RafikiService implements IRafikiService { const walletAddresses = await this.walletAddressService.getByIds(walletAddressIds) // return senders - return walletAddresses - .filter((wa) => wa.account?.user) - .map((wa) => `${wa.account.user.firstName} ${wa.account.user.lastName}`) - .join(', ') + return { + names: walletAddresses + .filter((wa) => wa.account?.user) + .map( + (wa) => `${wa.account.user.firstName} ${wa.account.user.lastName}` + ) + .join(', '), + walletAddresses: walletAddresses.map((wa) => wa.url).join(', ') + } } catch (e) { this.logger.warn( 'Error on getting outgoing payments by incoming payment', @@ -417,15 +427,21 @@ export class RafikiService implements IRafikiService { receiver.walletAddressUrl ) + const response: ISecondParty = { + walletAddresses: receiver.walletAddressUrl + } + if (receiverWA?.account?.user) { - return `${receiverWA.account.user.firstName} ${receiverWA.account.user.lastName}` + response.names = `${receiverWA.account.user.firstName} ${receiverWA.account.user.lastName}` } + + return response } catch (e) { this.logger.warn('Error on getting receiver wallet address', e) } } - async getOutgoingPaymentSecondPartyByIncomingPaymentId(paymentId: string) { + async getOutgoingPaymentSecondPartyByIncomingPaymentId(paymentId: string): Promise { try { const receiver = await this.rafikiClient.getIncomingPaymentById(paymentId) @@ -434,7 +450,10 @@ export class RafikiService implements IRafikiService { ) if (receiverWA?.account?.user) { - return `${receiverWA.account.user.firstName} ${receiverWA.account.user.lastName}` + return { + names: `${receiverWA.account.user.firstName} ${receiverWA.account.user.lastName}`, + walletAddresses: receiverWA.url + } } } catch (e) { this.logger.warn('Error on getting receiver wallet address', e) diff --git a/packages/wallet/backend/src/transaction/model.ts b/packages/wallet/backend/src/transaction/model.ts index 5613e684a..9fedae794 100644 --- a/packages/wallet/backend/src/transaction/model.ts +++ b/packages/wallet/backend/src/transaction/model.ts @@ -38,8 +38,10 @@ export class Transaction cardTxType?: number // Merchant name for card transactions - // Receiver or sender WA for ilp payments + // Receiver or sender first + last name for ilp payments secondParty?: string + // Receiver wallet address for ilp payments + secondPartyWA?: string static relationMappings = () => ({ walletAddress: { diff --git a/packages/wallet/backend/src/transaction/service.ts b/packages/wallet/backend/src/transaction/service.ts index f4ea139db..c1fcc2092 100644 --- a/packages/wallet/backend/src/transaction/service.ts +++ b/packages/wallet/backend/src/transaction/service.ts @@ -22,6 +22,10 @@ type ListAllTransactionsInput = { orderByDate: OrderByDirection } +export interface ISecondParty { + names?: string + walletAddresses?: string +} export interface ITransactionService { list: ( userId: string, @@ -232,7 +236,7 @@ export class TransactionService implements ITransactionService { async createOutgoingTransaction( params: OutgoingPayment, walletAddress: WalletAddress, - secondParty?: string + secondParty?: ISecondParty ) { const existentTransaction = await Transaction.query().findOne({ paymentId: params.id @@ -251,7 +255,8 @@ export class TransactionService implements ITransactionService { type: 'OUTGOING', status: 'PENDING', description: params.metadata?.description, - secondParty + secondParty: secondParty?.names, + secondPartyWA: secondParty?.walletAddresses }) } } diff --git a/packages/wallet/shared/src/types/transaction.ts b/packages/wallet/shared/src/types/transaction.ts index 567f0ac2f..9fb7468c3 100644 --- a/packages/wallet/shared/src/types/transaction.ts +++ b/packages/wallet/shared/src/types/transaction.ts @@ -38,8 +38,10 @@ export interface TransactionResponse { type: TransactionType status: TransactionStatus // Merchant name for card transactions - // Receiver or sender WA for ilp payments + // Receiver or sender first + last name for ilp payments secondParty?: string + // Receiver wallet address for ilp payments + secondPartyWA?: string txAmount?: bigint txCurrency?: string conversionRate?: string