Skip to content

Commit

Permalink
Get user on payment request
Browse files Browse the repository at this point in the history
  • Loading branch information
0xChqrles committed Jun 29, 2024
1 parent 82a5c74 commit f319974
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 16 deletions.
31 changes: 17 additions & 14 deletions app/App/Components/Modifiers/Sending/SendingConfirmationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ struct SendingConfirmationView: View {
@AppStorage("surname") var surname: String = ""

var body: some View {
if let recipient = self.model.recipient,
let usdcAmount = Amount.usdc(from: self.model.parsedAmount)
{
if let usdcAmount = Amount.usdc(from: self.model.parsedAmount) {
VStack {
Text("Finalize your transfer")
.textTheme(.headlineSmall)
Expand Down Expand Up @@ -57,17 +55,22 @@ struct SendingConfirmationView: View {
Spacer(minLength: 24)

VStack(spacing: 8) {
Avatar(
salt: recipient.phoneNumber ?? recipient.address?.toHex(),
name: recipient.name,
data: recipient.imageData
)

Text(recipient.name)
.foregroundStyle(.neutral1)
.fontWeight(.semibold)
.textTheme(.subtitle)
.lineLimit(1)
if let recipient = self.model.recipient {
Avatar(
salt: recipient.phoneNumber ?? recipient.address?.toHex(),
name: recipient.name,
data: recipient.imageData
)

Text(recipient.name)
.foregroundStyle(.neutral1)
.fontWeight(.semibold)
.textTheme(.subtitle)
.lineLimit(1)
} else {
// TODO: placeholder
EmptyView()
}
}
.frame(maxWidth: .infinity)
.padding(.vertical, 16)
Expand Down
21 changes: 19 additions & 2 deletions app/App/Models/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,25 @@ extension Model {
return
}

// TODO: get real user name/image
self.recipient = Recipient(name: "Chqrles", address: recipientAddress)
VaultService.shared.send(GetUser(address: recipientAddress)) { result in
DispatchQueue.main.async {
self.isLoading = false

switch result {
case .success(let response):
self.recipient = Recipient(name: response.user, address: recipientAddress)

case .failure(let error):
self.recipient = Recipient(name: "UNKNOWN", address: recipientAddress)

// TODO: Handle error
#if DEBUG
print(error)
#endif
}
}
}

self.amount = parsedAmount.toFixed(2)
self.showRequestingConfirmation = true
}
Expand Down
12 changes: 12 additions & 0 deletions app/App/Services/VaultAPI/Models/User.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// User.swift
// Vault
//
// Created by Charles Lanier on 29/06/2024.
//

import Foundation

public struct RawUser: Decodable {
public let user: String
}
29 changes: 29 additions & 0 deletions app/App/Services/VaultAPI/Requests/GetUser.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// GetUser.swift
// Vault
//
// Created by Charles Lanier on 29/06/2024.
//

import Foundation

public struct GetUser: APIRequest {

public typealias Response = RawUser

// Notice how we create a composed resourceName
public var resourceName: String {
return "get_user"
}

public var httpMethod: HTTPMethod {
return .GET
}

// Parameters
public let address: String

public init(address: String) {
self.address = address
}
}
8 changes: 8 additions & 0 deletions app/Vault.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
9C4F45192BDE949D00D44CBE /* SecureEnclaveManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C4F45182BDE949D00D44CBE /* SecureEnclaveManager.swift */; };
9C4F451B2BDE999000D44CBE /* String+Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C4F451A2BDE999000D44CBE /* String+Error.swift */; };
9C4F451D2BDEEF0E00D44CBE /* Data+from.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C4F451C2BDEEF0E00D44CBE /* Data+from.swift */; };
9C59C9442C30B2790074F23B /* GetUser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C59C9432C30B2790074F23B /* GetUser.swift */; };
9C59C9462C30B35D0074F23B /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C59C9452C30B35D0074F23B /* User.swift */; };
9C5CFDA62BC69446001776E1 /* CountryPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C5CFDA52BC69446001776E1 /* CountryPickerView.swift */; };
9C5CFDA82BC73DB0001776E1 /* SearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C5CFDA72BC73DB0001776E1 /* SearchBar.swift */; };
9C5CFDAE2BC828C9001776E1 /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C5CFDAD2BC828C9001776E1 /* Model.swift */; };
Expand Down Expand Up @@ -151,6 +153,8 @@
9C4F45182BDE949D00D44CBE /* SecureEnclaveManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecureEnclaveManager.swift; sourceTree = "<group>"; };
9C4F451A2BDE999000D44CBE /* String+Error.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Error.swift"; sourceTree = "<group>"; };
9C4F451C2BDEEF0E00D44CBE /* Data+from.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+from.swift"; sourceTree = "<group>"; };
9C59C9432C30B2790074F23B /* GetUser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetUser.swift; sourceTree = "<group>"; };
9C59C9452C30B35D0074F23B /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
9C5CFDA52BC69446001776E1 /* CountryPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CountryPickerView.swift; sourceTree = "<group>"; };
9C5CFDA72BC73DB0001776E1 /* SearchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchBar.swift; sourceTree = "<group>"; };
9C5CFDAD2BC828C9001776E1 /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -411,6 +415,7 @@
9C9F9EE12C22368200620AC6 /* Execution.swift */,
9C9F9EE22C22368200620AC6 /* VaultError.swift */,
9CD0988B2C22E33800FDDD8F /* Transaction.swift */,
9C59C9452C30B35D0074F23B /* User.swift */,
);
path = Models;
sourceTree = "<group>";
Expand All @@ -422,6 +427,7 @@
9C9F9EE62C22368200620AC6 /* GetOTP.swift */,
9C9F9EE72C22368200620AC6 /* VerifyOTP.swift */,
9CD098892C22E32300FDDD8F /* GetTransactionsHistory.swift */,
9C59C9432C30B2790074F23B /* GetUser.swift */,
);
path = Requests;
sourceTree = "<group>";
Expand Down Expand Up @@ -793,6 +799,7 @@
9C1C9D842C0D093F0028C8FD /* P256Signer.swift in Sources */,
9C9F9EF52C22368200620AC6 /* VaultError.swift in Sources */,
9C9F9EFB2C22368200620AC6 /* HTTPParameter.swift in Sources */,
9C59C9442C30B2790074F23B /* GetUser.swift in Sources */,
9C9F9EF32C22368200620AC6 /* Error.swift in Sources */,
9C9F9EF12C22368200620AC6 /* Deployment.swift in Sources */,
9CD0988E2C22EBE500FDDD8F /* History.swift in Sources */,
Expand All @@ -808,6 +815,7 @@
9CE7A75D2BE15C21008509FE /* SpinnerView.swift in Sources */,
9C637CD92BB09710005816B4 /* NotificationsManager.swift in Sources */,
9C9F9EF92C22368200620AC6 /* VerifyOTP.swift in Sources */,
9C59C9462C30B35D0074F23B /* User.swift in Sources */,
9C6259132BFB5A990039DE9C /* SendingAmountView.swift in Sources */,
9C6259192BFCDCEC0039DE9C /* NewRecipientView.swift in Sources */,
9C4F451D2BDEEF0E00D44CBE /* Data+from.swift in Sources */,
Expand Down

0 comments on commit f319974

Please sign in to comment.