Skip to content

Commit

Permalink
feat: add second party wallet address
Browse files Browse the repository at this point in the history
  • Loading branch information
dragosp1011 committed Feb 20, 2025
1 parent 43f8c2f commit d1e7a57
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = function (knex) {
return knex.schema.table('transactions', function (table) {
table.string('secondPartyWA').nullable()
})
}

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = function (knex) {
return knex.schema.table('transactions', function (table) {
table.dropColumn('secondPartyWA')
})
}
5 changes: 4 additions & 1 deletion packages/wallet/backend/src/backfillTrxDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}

Expand Down
41 changes: 30 additions & 11 deletions packages/wallet/backend/src/rafiki/service.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -385,7 +390,7 @@ export class RafikiService implements IRafikiService {
}
}

async getIncomingPaymentSenders(id: string) {
async getIncomingPaymentSenders(id: string): Promise<ISecondParty | undefined> {
try {
const outgoingPayments =
await this.rafikiClient.getOutgoingPaymentsByReceiver(
Expand All @@ -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',
Expand All @@ -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<ISecondParty | undefined> {
try {
const receiver = await this.rafikiClient.getIncomingPaymentById(paymentId)

Expand All @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion packages/wallet/backend/src/transaction/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
9 changes: 7 additions & 2 deletions packages/wallet/backend/src/transaction/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ type ListAllTransactionsInput = {
orderByDate: OrderByDirection
}

export interface ISecondParty {
names?: string
walletAddresses?: string
}
export interface ITransactionService {
list: (
userId: string,
Expand Down Expand Up @@ -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
Expand All @@ -251,7 +255,8 @@ export class TransactionService implements ITransactionService {
type: 'OUTGOING',
status: 'PENDING',
description: params.metadata?.description,
secondParty
secondParty: secondParty?.names,
secondPartyWA: secondParty?.walletAddresses
})
}
}
4 changes: 3 additions & 1 deletion packages/wallet/shared/src/types/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d1e7a57

Please sign in to comment.