Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix receipt management for USD and USDC #44

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions api/src/domain/projectors/projections_for_refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,11 @@
},
_ => (),
},
Event::Project(event) => match event {
ProjectEvent::BudgetLinked { id, budget_id, .. } => {
self.project_budgets_repository.try_insert(ProjectsBudget {
project_id: id,
budget_id,
})?;
},
_ => (),
Event::Project(ProjectEvent::BudgetLinked { id, budget_id, .. }) => {
self.project_budgets_repository.try_insert(ProjectsBudget {
project_id: id,
budget_id,
})?;

Check warning on line 179 in api/src/domain/projectors/projections_for_refresh.rs

View check run for this annotation

Codecov / codecov/patch

api/src/domain/projectors/projections_for_refresh.rs#L175-L179

Added lines #L175 - L179 were not covered by tests
},
_ => (),
}
Expand Down
44 changes: 17 additions & 27 deletions api/src/presentation/http/routes/payment/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,31 +82,12 @@
transaction_reference: String,
) -> anyhow::Result<PaymentReceipt> {
match currency {
currencies::USD => match (recipient_iban, recipient_wallet) {
(Some(recipient_iban), None) => Ok(PaymentReceipt::Sepa {
currencies::USD => match recipient_iban {
Some(recipient_iban) => Ok(PaymentReceipt::Sepa {

Check warning on line 86 in api/src/presentation/http/routes/payment/receipts.rs

View check run for this annotation

Codecov / codecov/patch

api/src/presentation/http/routes/payment/receipts.rs#L85-L86

Added lines #L85 - L86 were not covered by tests
recipient_iban,
transaction_reference,
}),
(None, Some(wallet)) => {
let (recipient_address, recipient_ens) = if wallet.starts_with("0x") {
(wallet.parse()?, None)
} else {
let address = ens.eth_address(&wallet).await?;
(address, Some(evm::Name::new(wallet)))
};

Ok(PaymentReceipt::Ethereum {
recipient_address,
recipient_ens,
transaction_hash: transaction_reference.parse()?,
})
},
(Some(_), Some(_)) => Err(anyhow!(
"You cannot specify both the recipient iban and wallet"
)),
(None, None) => Err(anyhow!(
"You must provide at least the recipient iban or wallet"
)),
_ => Err(anyhow!("You must provide the recipient iban")),

Check warning on line 90 in api/src/presentation/http/routes/payment/receipts.rs

View check run for this annotation

Codecov / codecov/patch

api/src/presentation/http/routes/payment/receipts.rs#L90

Added line #L90 was not covered by tests
},
currencies::OPTIMISM => match recipient_wallet {
Some(recipient_address) => Ok(PaymentReceipt::Optimism {
Expand All @@ -130,11 +111,20 @@
None => Err(anyhow!("You must provide the recipient wallet")),
},
currencies::LORDS | currencies::USDC => match recipient_wallet {
Some(recipient_address) => Ok(PaymentReceipt::Ethereum {
recipient_address: recipient_address.parse()?,
recipient_ens: None,
transaction_hash: transaction_reference.parse()?,
}),
Some(wallet) => {
let (recipient_address, recipient_ens) = if wallet.starts_with("0x") {
(wallet.parse()?, None)

Check warning on line 116 in api/src/presentation/http/routes/payment/receipts.rs

View check run for this annotation

Codecov / codecov/patch

api/src/presentation/http/routes/payment/receipts.rs#L114-L116

Added lines #L114 - L116 were not covered by tests
} else {
let address = ens.eth_address(&wallet).await?;
(address, Some(evm::Name::new(wallet)))

Check warning on line 119 in api/src/presentation/http/routes/payment/receipts.rs

View check run for this annotation

Codecov / codecov/patch

api/src/presentation/http/routes/payment/receipts.rs#L118-L119

Added lines #L118 - L119 were not covered by tests
};

Ok(PaymentReceipt::Ethereum {
recipient_address,
recipient_ens,
transaction_hash: transaction_reference.parse()?,

Check warning on line 125 in api/src/presentation/http/routes/payment/receipts.rs

View check run for this annotation

Codecov / codecov/patch

api/src/presentation/http/routes/payment/receipts.rs#L123-L125

Added lines #L123 - L125 were not covered by tests
})
},
None => Err(anyhow!("You must provide the recipient wallet")),
},
_ => Err(anyhow!("Currency {currency} is not supported")),
Expand Down
4 changes: 2 additions & 2 deletions api/tests/payment_it.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ impl<'a> Test<'a> {

let request = json!({
"amount": 100,
"currency": "USD",
"currency": "USDC",
"recipientWallet": "vitalik.eth",
"transactionReference": "0xe81124e94cf8dad83553eb35f1e50821dba16d145d9c8e3cc43d7681c68e4b2b",
});
Expand Down Expand Up @@ -1036,7 +1036,7 @@ impl<'a> Test<'a> {
processed_at
} => {
assert_eq!(id, payment_id);
assert_eq!(amount, Amount::from_decimal(dec!(100), currencies::USD));
assert_eq!(amount, Amount::from_decimal(dec!(100), currencies::USDC));
assert_eq!(receipt_id, response.receipt_id);
assert_eq!(receipt, PaymentReceipt::Ethereum {
recipient_address: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045".parse().unwrap(),
Expand Down
Loading