-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,309 additions
and
553 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// AddCustomToken.swift | ||
// FRW | ||
// | ||
// Created by cat on 10/30/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct AddCustomTokenView: RouteableView { | ||
|
||
@StateObject var viewModel = AddCustomTokenViewModel() | ||
|
||
var title: String { | ||
return "Add Custom Token".localized | ||
} | ||
|
||
var body: some View { | ||
VStack { | ||
TitleView(title: "Token Contract Address".localized, isStar: false) | ||
|
||
SingleInputView(content: $viewModel.customAddress) { | ||
viewModel.onSearch() | ||
} | ||
|
||
Button { | ||
viewModel.onPaste() | ||
} label: { | ||
Text("Paste Address".localized) | ||
.font(.inter(size: 16)) | ||
.foregroundStyle(Color.Theme.Text.black8) | ||
.padding(.horizontal, 16) | ||
.padding(.vertical, 8) | ||
.background(Color.Theme.Background.white8) | ||
.cornerRadius(12) | ||
} | ||
|
||
Spacer() | ||
} | ||
.padding(16) | ||
.background(.Theme.Background.bg2) | ||
.applyRouteable(self) | ||
|
||
} | ||
} | ||
|
||
|
||
#Preview { | ||
AddCustomTokenView() | ||
} |
57 changes: 57 additions & 0 deletions
57
FRW/Modules/Wallet/CustomToken/AddCustomTokenViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// AddCustomTokenViewModel.swift | ||
// FRW | ||
// | ||
// Created by cat on 10/30/24. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
import web3swift | ||
import BigInt | ||
import Web3Core | ||
|
||
class AddCustomTokenViewModel: ObservableObject { | ||
@Published var customAddress: String = "" | ||
|
||
func onPaste() { | ||
guard let address = UIPasteboard.general.string else { | ||
return | ||
} | ||
customAddress = address | ||
} | ||
|
||
func onSearch() { | ||
guard isValidAddress(address: customAddress) else { | ||
HUD.error(title: "invalid_address".localized) | ||
return | ||
} | ||
Task { | ||
do { | ||
HUD.loading() | ||
try await fetchInfo(by: customAddress) | ||
HUD.dismissLoading() | ||
} catch { | ||
log.error("[Add Custom Token] \(error.localizedDescription)") | ||
HUD.dismissLoading() | ||
} | ||
} | ||
} | ||
|
||
func isValidAddress(address: String) -> Bool { | ||
let result = address.lowercased().hasPrefix("0x") | ||
return result | ||
} | ||
} | ||
|
||
extension AddCustomTokenViewModel { | ||
func fetchInfo(by address: String) async throws { | ||
let manager = WalletManager.shared.customTokenManager | ||
let token = try await manager.findToken(evmAddress: address) | ||
guard let token = token else { | ||
return | ||
} | ||
Router.route(to: RouteMap.Wallet.showCustomToken(token)) | ||
} | ||
} | ||
|
Oops, something went wrong.