Skip to content

Commit

Permalink
add UpgradeToSmartAccountModule
Browse files Browse the repository at this point in the history
  • Loading branch information
llbartekll committed Jan 20, 2025
1 parent 7762c33 commit 1693622
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 13 deletions.
22 changes: 21 additions & 1 deletion Example/ExampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
84AEF01B2D3DD9F1006E43E5 /* SendStableCoinRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AEF01A2D3DD9F1006E43E5 /* SendStableCoinRouter.swift */; };
84AEF01D2D3DDA0A006E43E5 /* SendStableCoinPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AEF01C2D3DDA0A006E43E5 /* SendStableCoinPresenter.swift */; };
84AEF01F2D3DE7A0006E43E5 /* UpgradeToSmartAccountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AEF01E2D3DE7A0006E43E5 /* UpgradeToSmartAccountView.swift */; };
84AEF0222D3DE7C8006E43E5 /* UpgradeToSmartAccountPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AEF0212D3DE7C8006E43E5 /* UpgradeToSmartAccountPresenter.swift */; };
84AEF0242D3DE7D4006E43E5 /* UpgradeToSmartAccountModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AEF0232D3DE7D4006E43E5 /* UpgradeToSmartAccountModule.swift */; };
84AEF0262D3DE7E0006E43E5 /* UpgradeToSmartAccountRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AEF0252D3DE7E0006E43E5 /* UpgradeToSmartAccountRouter.swift */; };
84B8154E2991099000FAD54E /* BuildConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B8154D2991099000FAD54E /* BuildConfiguration.swift */; };
84B8155B2992A18D00FAD54E /* NotifyMessageViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B8155A2992A18D00FAD54E /* NotifyMessageViewModel.swift */; };
84CA52172C88965C0069BB33 /* ReownRouter in Frameworks */ = {isa = PBXBuildFile; productRef = 84CA52162C88965C0069BB33 /* ReownRouter */; };
Expand Down Expand Up @@ -391,6 +394,9 @@
84AEF01A2D3DD9F1006E43E5 /* SendStableCoinRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendStableCoinRouter.swift; sourceTree = "<group>"; };
84AEF01C2D3DDA0A006E43E5 /* SendStableCoinPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendStableCoinPresenter.swift; sourceTree = "<group>"; };
84AEF01E2D3DE7A0006E43E5 /* UpgradeToSmartAccountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpgradeToSmartAccountView.swift; sourceTree = "<group>"; };
84AEF0212D3DE7C8006E43E5 /* UpgradeToSmartAccountPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpgradeToSmartAccountPresenter.swift; sourceTree = "<group>"; };
84AEF0232D3DE7D4006E43E5 /* UpgradeToSmartAccountModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpgradeToSmartAccountModule.swift; sourceTree = "<group>"; };
84AEF0252D3DE7E0006E43E5 /* UpgradeToSmartAccountRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpgradeToSmartAccountRouter.swift; sourceTree = "<group>"; };
84B8154D2991099000FAD54E /* BuildConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuildConfiguration.swift; sourceTree = "<group>"; };
84B8155A2992A18D00FAD54E /* NotifyMessageViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotifyMessageViewModel.swift; sourceTree = "<group>"; };
84CE641C27981DED00142511 /* DApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -855,6 +861,17 @@
path = SendStableCoin;
sourceTree = "<group>";
};
84AEF0202D3DE7B1006E43E5 /* UpgradeToSmartAccount */ = {
isa = PBXGroup;
children = (
84AEF01E2D3DE7A0006E43E5 /* UpgradeToSmartAccountView.swift */,
84AEF0212D3DE7C8006E43E5 /* UpgradeToSmartAccountPresenter.swift */,
84AEF0232D3DE7D4006E43E5 /* UpgradeToSmartAccountModule.swift */,
84AEF0252D3DE7E0006E43E5 /* UpgradeToSmartAccountRouter.swift */,
);
path = UpgradeToSmartAccount;
sourceTree = "<group>";
};
84B815592991217F00FAD54E /* PushMessages */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1206,7 +1223,7 @@
84B815592991217F00FAD54E /* PushMessages */,
84D88C802CE751EE003A6C16 /* CATransactionModal */,
84AEF0172D3DD8D3006E43E5 /* SendStableCoin */,
84AEF01E2D3DE7A0006E43E5 /* UpgradeToSmartAccountView.swift */,
84AEF0202D3DE7B1006E43E5 /* UpgradeToSmartAccount */,
);
path = Wallet;
sourceTree = "<group>";
Expand Down Expand Up @@ -1998,6 +2015,7 @@
C56EE250293F566D004840D1 /* ScanTargetView.swift in Sources */,
C56EE28F293F5757004840D1 /* MigrationConfigurator.swift in Sources */,
A5A0844029D2F626000B9B17 /* DefaultCryptoProvider.swift in Sources */,
84AEF0262D3DE7E0006E43E5 /* UpgradeToSmartAccountRouter.swift in Sources */,
847BD1DD2989494F00076C90 /* TabPage.swift in Sources */,
A50D53C42ABA055700A4FD8B /* NotifyPreferencesInteractor.swift in Sources */,
A50D53C22ABA055700A4FD8B /* NotifyPreferencesPresenter.swift in Sources */,
Expand Down Expand Up @@ -2033,6 +2051,7 @@
A74D32BA2A1E25AD00CB8536 /* QueryParameters.swift in Sources */,
C56EE270293F56D7004840D1 /* String.swift in Sources */,
A51811A12A52E83100A52B15 /* SettingsRouter.swift in Sources */,
84AEF0222D3DE7C8006E43E5 /* UpgradeToSmartAccountPresenter.swift in Sources */,
C56EE279293F56D7004840D1 /* Color.swift in Sources */,
847BD1E6298A806800076C90 /* NotificationsRouter.swift in Sources */,
848BD1DE2D34DF8F007C2AEF /* EOASigner.swift in Sources */,
Expand Down Expand Up @@ -2090,6 +2109,7 @@
A50B6A382B06697B00162B01 /* ProfilingService.swift in Sources */,
A5B4F7C52ABB20AE0099AF7C /* SubscriptionRouter.swift in Sources */,
C55D3496295DFA750004314A /* WelcomeInteractor.swift in Sources */,
84AEF0242D3DE7D4006E43E5 /* UpgradeToSmartAccountModule.swift in Sources */,
C5B2F6FC297055B0000DBA0E /* SOLSigner.swift in Sources */,
A518119F2A52E83100A52B15 /* SettingsModule.swift in Sources */,
84D88C842CE754CC003A6C16 /* CATransactionModule.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class SendStableCoinModule {
importAccount: ImportAccount
) -> UIViewController {
let router = SendStableCoinRouter(app: app)
let presenter = SendStableCoinPresenter()
let presenter = SendStableCoinPresenter(router: router, importAccount: importAccount)
let view = SendStableCoinView(presenter: presenter).environmentObject(presenter)
let viewController = SceneViewController(viewModel: presenter, content: view)
router.viewController = viewController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class SendStableCoinPresenter: ObservableObject, SceneViewModel {
init(router: SendStableCoinRouter,
importAccount: ImportAccount) {
self.router = router

self.importAccount = importAccount
}

func set(network: L2) {
Expand All @@ -28,9 +28,3 @@ final class SendStableCoinPresenter: ObservableObject, SceneViewModel {
router.presentUpgradeToSmartAccount(importAccount: importAccount, network: selectedNetwork)
}
}


UpgradeToSmartAccountPresenter
UpgradeToSmartAccountView
UpgradeToSmartAccountModule
UpgradeToSmartAccountRouter
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ final class SendStableCoinRouter {

func presentUpgradeToSmartAccount(importAccount: ImportAccount, network: L2) {

UpgradeToSmartAccountModule.create(app: app, importAccount: importAccount, network: network)
.present(from: viewController)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct SendStableCoinView: View {
}
Spacer()
Button(action: {
// TODO: handle upgrade to smart account
presenter.upgradeToSmartAccount()
}) {
Text("Upgrade to Smart Account")
.foregroundColor(.blue)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Foundation
import UIKit

final class UpgradeToSmartAccountModule {
@discardableResult
static func create(
app: Application,
importAccount: ImportAccount,
network: L2
) -> UIViewController {
let router = UpgradeToSmartAccountRouter(app: app)
let presenter = UpgradeToSmartAccountPresenter(
router: router,
importAccount: importAccount,
network: network
)

// Build the SwiftUI view, injecting the presenter
let view = UpgradeToSmartAccountView(presenter: presenter)

// Wrap it in your SceneViewController or whichever container
let viewController = SceneViewController(viewModel: presenter, content: view)
router.viewController = viewController

return viewController
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Foundation
import ReownWalletKit

final class UpgradeToSmartAccountPresenter: ObservableObject, SceneViewModel {
@Published var selectedNetwork: L2
@Published var doNotAskAgain = false

let router: UpgradeToSmartAccountRouter
let importAccount: ImportAccount

init(router: UpgradeToSmartAccountRouter,
importAccount: ImportAccount,
network: L2) {
self.router = router
self.importAccount = importAccount
self.selectedNetwork = network
}

/// Called when user taps the 'Sign & Upgrade' button
func signAndUpgrade() {
// TODO: Implement any logic needed before upgrading
// For now, just dismiss or call into router if needed
router.dismiss()
}

/// Called when user taps the 'Cancel' or 'X' button
func cancel() {
router.dismiss()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Foundation
import UIKit

final class UpgradeToSmartAccountRouter {
weak var viewController: UIViewController?
private let app: Application

init(app: Application) {
self.app = app
}

/// Dismiss this screen
func dismiss() {
DispatchQueue.main.async { [weak self] in
self?.viewController?.dismiss(animated: true)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import SwiftUI

struct UpgradeToSmartAccountView: View {
@ObservedObject var presenter: UpgradeToSmartAccountPresenter

var body: some View {
VStack(spacing: 0) {
// Top Header
HStack {
Text("Upgrade to Smart Account")
.font(.headline)
.foregroundColor(.white)
Spacer()
Button(action: {
presenter.cancel()
}) {
Image(systemName: "xmark")
.foregroundColor(.white)
}
}
.padding()

// Explanation text
Text("To upgrade your account, you need to sign a transaction with your wallet.")
.font(.subheadline)
.foregroundColor(.gray)
.multilineTextAlignment(.center)
.padding(.horizontal, 16)
.padding(.bottom, 16)

// Features card
VStack(alignment: .leading, spacing: 12) {
Text("Get access to advanced features")
.font(.body).bold()

Label("Sponsored Transactions", systemImage: "checkmark.circle.fill")
.foregroundColor(.green)
Label("Bundle Transactions", systemImage: "checkmark.circle.fill")
.foregroundColor(.green)

Text("and more in the future...")
.foregroundColor(.gray)
}
.padding()
.background(Color("grey-section"))
.cornerRadius(16)
.padding(.horizontal, 16)
.padding(.bottom, 16)

// Wallet/Network/Fees card
VStack(alignment: .leading, spacing: 8) {
HStack {
Text("Wallet")
.foregroundColor(.gray)
Spacer()
Text(presenter.importAccount.account.address)
.font(.system(.body, design: .monospaced))
}
Divider()
HStack {
Text("Network")
.foregroundColor(.gray)
Spacer()
Text(presenter.selectedNetwork.rawValue)
.foregroundColor(.blue)
}
Divider()
HStack {
Text("Fees")
.foregroundColor(.gray)
Spacer()
Text("FREE")
.foregroundColor(.green)
}
Divider()
HStack {
Text("Sponsored By")
.foregroundColor(.gray)
Spacer()
Text("reown") // Example sponsor
}
}
.padding()
.background(Color("grey-section"))
.cornerRadius(16)
.padding(.horizontal, 16)
.padding(.bottom, 16)

// Do once toggle
Toggle("Do it once and don't ask me again.", isOn: $presenter.doNotAskAgain)
.toggleStyle(SwitchToggleStyle(tint: .blue))
.padding(.horizontal, 16)
.padding(.bottom, 16)
.foregroundColor(.white)

Spacer()

// Bottom actions row
HStack {
Button(action: {
presenter.cancel()
}) {
Text("Cancel")
.foregroundColor(.white)
}
.padding(.horizontal, 24)
.padding(.vertical, 12)
.background(Color(.systemGray3).opacity(0.3))
.cornerRadius(12)

Spacer()

Button(action: {
presenter.signAndUpgrade()
}) {
Text("Sign & Upgrade")
.fontWeight(.semibold)
.foregroundColor(.white)
.padding(.horizontal, 24)
.padding(.vertical, 12)
.background(
LinearGradient(gradient: Gradient(colors: [.purple, .blue]),
startPoint: .leading,
endPoint: .trailing)
)
.cornerRadius(12)
}
}
.padding(.horizontal, 16)
.padding(.bottom, 16)
}
.background(Color.black.edgesIgnoringSafeArea(.all)) // Example dark background
}
}

This file was deleted.

0 comments on commit 1693622

Please sign in to comment.