Skip to content

Commit

Permalink
Add stripe checkout view
Browse files Browse the repository at this point in the history
  • Loading branch information
0xChqrles committed Jul 3, 2024
1 parent b1a8c59 commit 477f5dc
Show file tree
Hide file tree
Showing 13 changed files with 266 additions and 306 deletions.
15 changes: 15 additions & 0 deletions app/App/Assets.xcassets/SVG/Fun.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "Fun.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
1 change: 1 addition & 0 deletions app/App/Assets.xcassets/SVG/Fun.imageset/Fun.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions app/App/Components/Line.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Line.swift
// Vault
//
// Created by Charles Lanier on 03/07/2024.
//

import SwiftUI

struct Line: Shape {
func path(in rect: CGRect) -> Path {
var path = Path()
path.move(to: CGPoint(x: 0, y: 0))
path.addLine(to: CGPoint(x: rect.width, y: 0))
return path
}
}
39 changes: 30 additions & 9 deletions app/App/Models/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class Model: ObservableObject {
}
@Published var onRampQuoteId: String?
@Published var onRampTotalUsd: String?
@Published var estSubtotalUsd: Double = 0
@Published var stripeRedirectUrl: URL? = nil

// Sending USDC
@Published var recipient: Recipient?
Expand Down Expand Up @@ -108,10 +110,8 @@ class Model: ObservableObject {

private var currentTask: Task<Void, Never>? {
willSet {
print("Setting new task")
if let task = currentTask {
if task.isCancelled { return }
print("Cancelling currnet task")
task.cancel()
// Setting a new task cancelling the current task
}
Expand Down Expand Up @@ -475,13 +475,10 @@ extension Model {
self.currentTask = Task {
let response = try! await withCheckedThrowingContinuation { (continuation: CheckedContinuation<FunkitStripeCheckoutQuote, any Error>) in
VaultService.shared.send(GetFunkitStripeCheckoutQuote(address: self.address, amount: self.amount)) { result in

DispatchQueue.main.async {

switch result {
case .success(let response):
continuation.resume(returning: response)
print(response.quoteId)

case .failure(let error):
// TODO: Handle error
Expand All @@ -492,15 +489,36 @@ extension Model {
}

// task has been cancelled
if Task.isCancelled {
print("Task has been cancelled, do nothing")
return
}
if Task.isCancelled { return }

self.isLoading = false

self.onRampQuoteId = response.quoteId
self.onRampTotalUsd = response.totalUsd
self.estSubtotalUsd = response.estSubtotalUsd
}
}

public func createOnrampCheckout() {
guard let quoteId = self.onRampQuoteId else { return }

VaultService.shared.send(
CreateFunkitStripeCheckout(
quoteId: quoteId,
parsedAmount: self.parsedAmount,
estSubtotalUsd: self.estSubtotalUsd
)
) { result in
DispatchQueue.main.async {
switch result {
case .success(let response):
self.stripeRedirectUrl = URL(string: response.stripeRedirectUrl)

case .failure(let error):
// TODO: Handle error
print(error)
}
}
}
}
}
Expand Down Expand Up @@ -587,5 +605,8 @@ extension Model {
private func initiateOnramp() {
self.amount = "0"
self.onRampQuoteId = nil
self.onRampTotalUsd = nil
self.estSubtotalUsd = 0
self.stripeRedirectUrl = nil
}
}
75 changes: 0 additions & 75 deletions app/App/Navigation/Core/Onramp/AskBirthDateView.swift

This file was deleted.

69 changes: 0 additions & 69 deletions app/App/Navigation/Core/Onramp/AskEmailView.swift

This file was deleted.

67 changes: 0 additions & 67 deletions app/App/Navigation/Core/Onramp/AskFullNameView.swift

This file was deleted.

Loading

0 comments on commit 477f5dc

Please sign in to comment.