Skip to content

Commit

Permalink
Merge pull request #1116 from WalletConnect/verify-scam-field
Browse files Browse the repository at this point in the history
[Verify] Add 'isScam' field
  • Loading branch information
alexander-lsvk authored Sep 20, 2023
2 parents 8c7fe98 + fb6a7e3 commit 8d3f817
Show file tree
Hide file tree
Showing 13 changed files with 262 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class AuthRequestPresenter: ObservableObject {

let importAccount: ImportAccount
let request: AuthRequest
let verified: Bool?
let validationStatus: VerifyContext.ValidationStatus?

var message: String {
return interactor.formatted(request: request, account: importAccount.account)
Expand All @@ -29,7 +29,7 @@ final class AuthRequestPresenter: ObservableObject {
self.router = router
self.importAccount = importAccount
self.request = request
self.verified = (context?.validation == .valid) ? true : (context?.validation == .unknown ? nil : false)
self.validationStatus = context?.validation
}

@MainActor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,10 @@ struct AuthRequestView: View {
.resizable()
.scaledToFit()

HStack {
Text(presenter.request.payload.domain)
.foregroundColor(.grey8)
.font(.system(size: 22, weight: .bold, design: .rounded))

if let verified = presenter.verified {
if verified {
Image(systemName: "checkmark.shield.fill")
.symbolRenderingMode(.palette)
.foregroundStyle(.white, .green)
} else {
Image(systemName: "xmark.shield.fill")
.symbolRenderingMode(.palette)
.foregroundStyle(.white, .red)
}
} else {
Image(systemName: "exclamationmark.shield.fill")
.symbolRenderingMode(.palette)
.foregroundStyle(.white, .orange)
}
}
.padding(.top, 10)
Text(presenter.request.payload.domain)
.foregroundColor(.grey8)
.font(.system(size: 22, weight: .bold, design: .rounded))
.padding(.top, 10)

Text("would like to connect")
.foregroundColor(.grey8)
Expand All @@ -51,8 +33,41 @@ struct AuthRequestView: View {
.lineSpacing(4)
.padding(.top, 8)

switch presenter.validationStatus {
case .unknown:
verifyBadgeView(imageName: "exclamationmark.circle.fill", title: "Cannot verify", color: .orange)

case .valid:
verifyBadgeView(imageName: "checkmark.seal.fill", title: "Verified domain", color: .blue)

case .invalid:
verifyBadgeView(imageName: "exclamationmark.triangle.fill", title: "Invalid domain", color: .red)

case .scam:
verifyBadgeView(imageName: "exclamationmark.shield.fill", title: "Security risk", color: .red)

default:
EmptyView()
}

authRequestView()

Group {
switch presenter.validationStatus {
case .invalid:
verifyDescriptionView(imageName: "exclamationmark.triangle.fill", title: "Invalid domain", description: "This domain cannot be verified. Check the request carefully before approving.", color: .red)

case .unknown:
verifyDescriptionView(imageName: "exclamationmark.circle.fill", title: "Unknown domain", description: "This domain cannot be verified. Check the request carefully before approving.", color: .orange)

case .scam:
verifyDescriptionView(imageName: "exclamationmark.shield.fill", title: "Security risk", description: "This website is flagged as unsafe by multiple security providers. Leave immediately to protect your assets.", color: .red)

default:
EmptyView()
}
}

HStack(spacing: 20) {
Button {
Task(priority: .userInitiated) { try await
Expand Down Expand Up @@ -143,7 +158,46 @@ struct AuthRequestView: View {
.background(.thinMaterial)
.cornerRadius(25, corners: .allCorners)
}
.padding(.top, 30)
.padding(.vertical, 30)
}

private func verifyBadgeView(imageName: String, title: String, color: Color) -> some View {
HStack(spacing: 5) {
Image(systemName: imageName)
.font(.system(size: 14, weight: .semibold, design: .rounded))
.foregroundColor(color)

Text(title)
.foregroundColor(color)
.font(.system(size: 14, weight: .semibold, design: .rounded))

}
.padding(5)
.background(color.opacity(0.15))
.cornerRadius(10)
.padding(.top, 8)
}

private func verifyDescriptionView(imageName: String, title: String, description: String, color: Color) -> some View {
HStack(spacing: 15) {
Image(systemName: imageName)
.font(.system(size: 20, design: .rounded))
.foregroundColor(color)

VStack(alignment: .leading, spacing: 5) {
Text(title)
.foregroundColor(color)
.font(.system(size: 14, weight: .semibold, design: .rounded))

Text(description)
.foregroundColor(.grey8)
.font(.system(size: 14, weight: .medium, design: .rounded))
}
}
.frame(maxWidth: .infinity)
.padding()
.background(color.opacity(0.15))
.cornerRadius(20)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class SessionProposalPresenter: ObservableObject {

let importAccount: ImportAccount
let sessionProposal: Session.Proposal
let verified: Bool?
let validationStatus: VerifyContext.ValidationStatus?

@Published var showError = false
@Published var errorMessage = "Error"
Expand All @@ -28,7 +28,7 @@ final class SessionProposalPresenter: ObservableObject {
self.router = router
self.sessionProposal = proposal
self.importAccount = importAccount
self.verified = (context?.validation == .valid) ? true : (context?.validation == .unknown ? nil : false)
self.validationStatus = context?.validation
}

@MainActor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,6 @@ struct SessionProposalView: View {
Text(presenter.sessionProposal.proposer.name)
.foregroundColor(.grey8)
.font(.system(size: 22, weight: .bold, design: .rounded))

if let verified = presenter.verified {
if verified {
Image(systemName: "checkmark.shield.fill")
.symbolRenderingMode(.palette)
.foregroundStyle(.white, .green)
} else {
Image(systemName: "xmark.shield.fill")
.symbolRenderingMode(.palette)
.foregroundStyle(.white, .red)
}
} else {
Image(systemName: "exclamationmark.shield.fill")
.symbolRenderingMode(.palette)
.foregroundStyle(.white, .orange)
}
}

.padding(.top, 10)
Expand All @@ -46,13 +30,30 @@ struct SessionProposalView: View {
.foregroundColor(.grey8)
.font(.system(size: 22, weight: .medium, design: .rounded))

Text(presenter.sessionProposal.proposer.name)
Text(presenter.sessionProposal.proposer.url)
.foregroundColor(.grey50)
.font(.system(size: 13, weight: .semibold, design: .rounded))
.multilineTextAlignment(.center)
.lineSpacing(4)
.padding(.top, 8)

switch presenter.validationStatus {
case .unknown:
verifyBadgeView(imageName: "exclamationmark.circle.fill", title: "Cannot verify", color: .orange)

case .valid:
verifyBadgeView(imageName: "checkmark.seal.fill", title: "Verified domain", color: .blue)

case .invalid:
verifyBadgeView(imageName: "exclamationmark.triangle.fill", title: "Invalid domain", color: .red)

case .scam:
verifyBadgeView(imageName: "exclamationmark.shield.fill", title: "Security risk", color: .red)

default:
EmptyView()
}

Divider()
.padding(.top, 12)
.padding(.horizontal, -18)
Expand Down Expand Up @@ -80,7 +81,7 @@ struct SessionProposalView: View {
.lineSpacing(4)
.padding(.vertical, 12)
}

ForEach(optionalNamespaces.keys.sorted(), id: \.self) { chain in
if let namespaces = optionalNamespaces[chain] {
sessionProposalView(namespaces: namespaces)
Expand All @@ -89,7 +90,22 @@ struct SessionProposalView: View {
}
}
.frame(height: 250)
.padding(.top, 12)
.cornerRadius(20)
.padding(.vertical, 12)

switch presenter.validationStatus {
case .invalid:
verifyDescriptionView(imageName: "exclamationmark.triangle.fill", title: "Invalid domain", description: "This domain cannot be verified. Check the request carefully before approving.", color: .red)

case .unknown:
verifyDescriptionView(imageName: "exclamationmark.circle.fill", title: "Unknown domain", description: "This domain cannot be verified. Check the request carefully before approving.", color: .orange)

case .scam:
verifyDescriptionView(imageName: "exclamationmark.shield.fill", title: "Security risk", description: "This website is flagged as unsafe by multiple security providers. Leave immediately to protect your assets.", color: .red)

default:
EmptyView()
}

HStack(spacing: 20) {
Button {
Expand Down Expand Up @@ -151,7 +167,7 @@ struct SessionProposalView: View {
}
.edgesIgnoringSafeArea(.all)
}
//private func sessionProposalView(chain: String) -> some View {

private func sessionProposalView(namespaces: ProposalNamespace) -> some View {
VStack {
VStack(alignment: .leading) {
Expand Down Expand Up @@ -229,6 +245,45 @@ struct SessionProposalView: View {
}
.padding(.bottom, 15)
}

private func verifyBadgeView(imageName: String, title: String, color: Color) -> some View {
HStack(spacing: 5) {
Image(systemName: imageName)
.font(.system(size: 14, weight: .semibold, design: .rounded))
.foregroundColor(color)

Text(title)
.foregroundColor(color)
.font(.system(size: 14, weight: .semibold, design: .rounded))

}
.padding(5)
.background(color.opacity(0.15))
.cornerRadius(10)
.padding(.top, 8)
}

private func verifyDescriptionView(imageName: String, title: String, description: String, color: Color) -> some View {
HStack(spacing: 15) {
Image(systemName: imageName)
.font(.system(size: 20, design: .rounded))
.foregroundColor(color)

VStack(alignment: .leading, spacing: 5) {
Text(title)
.foregroundColor(color)
.font(.system(size: 14, weight: .semibold, design: .rounded))

Text(description)
.foregroundColor(.grey8)
.font(.system(size: 14, weight: .medium, design: .rounded))
}
}
.frame(maxWidth: .infinity)
.padding()
.background(color.opacity(0.15))
.cornerRadius(20)
}
}

#if DEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class SessionRequestPresenter: ObservableObject {
private let importAccount: ImportAccount

let sessionRequest: Request
let verified: Bool?
let validationStatus: VerifyContext.ValidationStatus?

var message: String {
return String(describing: sessionRequest.params.value)
Expand All @@ -32,7 +32,7 @@ final class SessionRequestPresenter: ObservableObject {
self.router = router
self.sessionRequest = sessionRequest
self.importAccount = importAccount
self.verified = (context?.validation == .valid) ? true : (context?.validation == .unknown ? nil : false)
self.validationStatus = context?.validation
}

@MainActor
Expand Down
Loading

0 comments on commit 8d3f817

Please sign in to comment.