Skip to content

Commit

Permalink
417 Update evm tx history API (#553)
Browse files Browse the repository at this point in the history
417 Update evm tx history API
#417
  • Loading branch information
jeden authored Dec 19, 2024
1 parent 6cafca4 commit 3e46917
Show file tree
Hide file tree
Showing 39 changed files with 186 additions and 238 deletions.
20 changes: 20 additions & 0 deletions FRW.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,10 @@
4EFF94C52AEEDD0A00365EF7 /* IPResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EFF94C32AEEDD0A00365EF7 /* IPResponse.swift */; };
4EFF94C72AEEE5DD00365EF7 /* DevicesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EFF94C62AEEE5DD00365EF7 /* DevicesViewModel.swift */; };
4EFF94C82AEEE5DD00365EF7 /* DevicesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EFF94C62AEEE5DD00365EF7 /* DevicesViewModel.swift */; };
574943E72CED8E4E00F9040A /* UrlProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 574943E62CED8E4E00F9040A /* UrlProvider.swift */; };
574943E82CED8E4E00F9040A /* UrlProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 574943E62CED8E4E00F9040A /* UrlProvider.swift */; };
57FD54472CEE996700FFDDC5 /* FlowNetworkType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57FD54462CEE996700FFDDC5 /* FlowNetworkType.swift */; };
57FD54482CEE996700FFDDC5 /* FlowNetworkType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57FD54462CEE996700FFDDC5 /* FlowNetworkType.swift */; };
571A806D2CF54C12009112EE /* InsufficientStorageAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 571A806C2CF54C12009112EE /* InsufficientStorageAlert.swift */; };
571A806E2CF54C12009112EE /* InsufficientStorageAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 571A806C2CF54C12009112EE /* InsufficientStorageAlert.swift */; };
57312EC52CFD2833009A344A /* Threading.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57312EC42CFD2833009A344A /* Threading.swift */; };
Expand Down Expand Up @@ -2630,6 +2634,8 @@
4EFF94C02AEEDC1C00365EF7 /* FRWAPI+IP.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FRWAPI+IP.swift"; sourceTree = "<group>"; };
4EFF94C32AEEDD0A00365EF7 /* IPResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPResponse.swift; sourceTree = "<group>"; };
4EFF94C62AEEE5DD00365EF7 /* DevicesViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DevicesViewModel.swift; sourceTree = "<group>"; };
574943E62CED8E4E00F9040A /* UrlProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UrlProvider.swift; sourceTree = "<group>"; };
57FD54462CEE996700FFDDC5 /* FlowNetworkType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowNetworkType.swift; sourceTree = "<group>"; };
571A806C2CF54C12009112EE /* InsufficientStorageAlert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InsufficientStorageAlert.swift; sourceTree = "<group>"; };
57312EC42CFD2833009A344A /* Threading.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Threading.swift; sourceTree = "<group>"; };
573429B52CDC4B2E00BDE016 /* AccountModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountModels.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5293,6 +5299,14 @@
path = Devices;
sourceTree = "<group>";
};
57FD54452CEE987D00FFDDC5 /* Resources */ = {
isa = PBXGroup;
children = (
574943E62CED8E4E00F9040A /* UrlProvider.swift */,
);
path = Resources;
sourceTree = "<group>";
};
6A06CB0828AA483A00C81BE1 /* ViewHandler */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -5897,6 +5911,7 @@
4EC56B28281D381400246878 /* Firebase */,
159A5438275368DA004BCACC /* Network */,
15DE22CC277DBDC300B5EE03 /* Manager */,
57FD54452CEE987D00FFDDC5 /* Resources */,
);
path = Services;
sourceTree = "<group>";
Expand All @@ -5913,6 +5928,7 @@
6A2C560A290BE46800306A6C /* Currency.swift */,
573429B52CDC4B2E00BDE016 /* AccountModels.swift */,
15DFD34B2CE197F9004B0DB8 /* AppExternalLinks.swift */,
57FD54462CEE996700FFDDC5 /* FlowNetworkType.swift */,
57EB45702CFFC36400393FF2 /* TokenType.swift */,
);
path = Model;
Expand Down Expand Up @@ -7173,6 +7189,7 @@
4EFBE5E12BCE68FF0012968A /* WalletConnectChildHandlerProtocol.swift in Sources */,
15DC212127819C56000B187A /* VSpinnerModelDashed.swift in Sources */,
6A63F9F328C9C69100FE96C0 /* ImageAnimated.swift in Sources */,
574943E72CED8E4E00F9040A /* UrlProvider.swift in Sources */,
4EB2C6AF2B49446F00EB899C /* MultiBackupManager.swift in Sources */,
6AE8821F288EB67A00ADF36E /* RouterExtensions.swift in Sources */,
4E63A5722B8BA1F400BBD15F /* EVMEnableViewModel.swift in Sources */,
Expand Down Expand Up @@ -7620,6 +7637,7 @@
4EC26FCB2BFCB312001330DF /* EVMAssetProvider.swift in Sources */,
4EA106772C738BEC00555350 /* PrivateKeyLoginViewModel.swift in Sources */,
6A9CFE492A6931F900AEA847 /* UIDevice.swift in Sources */,
57FD54482CEE996700FFDDC5 /* FlowNetworkType.swift in Sources */,
156E84B2281CF01000415896 /* EventLoop+Future.swift in Sources */,
4EC26FD42BFE31C0001330DF /* MoveSingleNFTViewModel.swift in Sources */,
15DC20D927819C56000B187A /* VPrimaryButtonModel.swift in Sources */,
Expand Down Expand Up @@ -7996,6 +8014,7 @@
4EFBE5E02BCE68FF0012968A /* WalletConnectChildHandlerProtocol.swift in Sources */,
6AE8821E288EB67A00ADF36E /* RouterExtensions.swift in Sources */,
4EB2C6AE2B49446F00EB899C /* MultiBackupManager.swift in Sources */,
574943E82CED8E4E00F9040A /* UrlProvider.swift in Sources */,
15C58B552868A4EE00BD4FC6 /* AddAddressViewModel.swift in Sources */,
154866F328D0FE8900D012B8 /* ViewCondition.swift in Sources */,
4E63A5712B8BA1F400BBD15F /* EVMEnableViewModel.swift in Sources */,
Expand Down Expand Up @@ -8443,6 +8462,7 @@
4EC26FCA2BFCAF5C001330DF /* EVMAssetProvider.swift in Sources */,
4EA106762C738BEC00555350 /* PrivateKeyLoginViewModel.swift in Sources */,
6A9CFE482A6931F900AEA847 /* UIDevice.swift in Sources */,
57FD54472CEE996700FFDDC5 /* FlowNetworkType.swift in Sources */,
15C58C352868A4EE00BD4FC6 /* EventLoop+Future.swift in Sources */,
4EC26FD32BFE31C0001330DF /* MoveSingleNFTViewModel.swift in Sources */,
15C58C362868A4EE00BD4FC6 /* VPrimaryButtonModel.swift in Sources */,
Expand Down
52 changes: 52 additions & 0 deletions FRW/Foundation/Model/FlowNetworkType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// FlowNetworkType.swift
// FRW
//
// Created by Antonio Bello on 11/20/24.
//

import Foundation
import Flow
import struct SwiftUI.Color

enum FlowNetworkType: String, CaseIterable, Codable {
case testnet
case mainnet

// MARK: Lifecycle

init?(chainId: Flow.ChainID) {
switch chainId {
case .testnet:
self = .testnet
case .mainnet:
self = .mainnet
default:
return nil
}
}

// MARK: Internal

var color: Color {
switch self {
case .mainnet:
return Color.LL.Primary.salmonPrimary
case .testnet:
return Color(hex: "#FF8A00")
}
}

var isMainnet: Bool {
self == .mainnet
}

func toFlowType() -> Flow.ChainID {
switch self {
case .testnet:
return Flow.ChainID.testnet
case .mainnet:
return Flow.ChainID.mainnet
}
}
}
13 changes: 3 additions & 10 deletions FRW/Foundation/Model/WalletModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ struct TokenModel: Codable, Identifiable, Mockable {
addressString = address.testnet ?? ""
case .mainnet:
addressString = address.mainnet ?? ""
case .previewnet:
addressString = address.previewnet ?? ""
}

addressString = addressString.stripHexPrefix()
Expand Down Expand Up @@ -154,8 +152,7 @@ struct TokenModel: Codable, Identifiable, Mockable {
address: FlowNetworkModel(
mainnet: nil,
testnet: nil,
crescendo: nil,
previewnet: nil
crescendo: nil
),
contractName: "contractname",
storagePath: FlowTokenStoragePath(balance: "", vault: "", receiver: ""),
Expand Down Expand Up @@ -206,16 +203,13 @@ struct FlowNetworkModel: Codable {
let mainnet: String?
var testnet: String?
let crescendo: String?
var previewnet: String?

func addressByNetwork(_ network: Flow.ChainID) -> String? {
switch network {
case .mainnet:
return mainnet
case .testnet:
return testnet
case .previewnet:
return previewnet
default:
return nil
}
Expand Down Expand Up @@ -260,16 +254,15 @@ struct SingleToken: Codable {
let evmAddress: String?
let flowIdentifier: String?

func toTokenModel(network: LocalUserDefaults.FlowNetworkType) -> TokenModel {
func toTokenModel(network: FlowNetworkType) -> TokenModel {
let logo = URL(string: logoURI ?? "")

let model = TokenModel(
name: name,
address: FlowNetworkModel(
mainnet: network == .mainnet ? address : nil,
testnet: network == .testnet ? address : nil,
crescendo: nil,
previewnet: network == .previewnet ? address : nil
crescendo: nil
),
contractName: contractName ?? "",
storagePath: path ??
Expand Down
3 changes: 1 addition & 2 deletions FRW/Modules/Browser/Handler/JSMessageHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ extension JSMessageHandler {
finishService()

if let network = fcl.network,
let toNetwork = LocalUserDefaults
.FlowNetworkType(rawValue: network.lowercased()) {
let toNetwork = FlowNetworkType(rawValue: network.lowercased()) {
Router.route(to: RouteMap.Explore.switchNetwork(current, toNetwork, nil))
}

Expand Down
12 changes: 6 additions & 6 deletions FRW/Modules/Browser/View/NetworkSwitchPopView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class NetworkSwitchPopViewModel: ObservableObject {
// MARK: Lifecycle

init(
fromNetwork: LocalUserDefaults.FlowNetworkType,
toNetwork: LocalUserDefaults.FlowNetworkType,
fromNetwork: FlowNetworkType,
toNetwork: FlowNetworkType,
callback: SwitchNetworkClosure? = nil
) {
self.fromNetwork = fromNetwork
Expand All @@ -25,9 +25,9 @@ class NetworkSwitchPopViewModel: ObservableObject {
// MARK: Internal

@Published
var fromNetwork: LocalUserDefaults.FlowNetworkType
var fromNetwork: FlowNetworkType
@Published
var toNetwork: LocalUserDefaults.FlowNetworkType
var toNetwork: FlowNetworkType

var callback: SwitchNetworkClosure?

Expand Down Expand Up @@ -67,8 +67,8 @@ struct NetworkSwitchPopView: View {
// MARK: Lifecycle

init(
from: LocalUserDefaults.FlowNetworkType,
to: LocalUserDefaults.FlowNetworkType,
from: FlowNetworkType,
to: FlowNetworkType,
callback: SwitchNetworkClosure? = nil
) {
_vm = StateObject(wrappedValue: NetworkSwitchPopViewModel(
Expand Down
4 changes: 0 additions & 4 deletions FRW/Modules/Explore/Model/DAppModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ struct DAppModel: Codable, Identifiable {
case testnetURL = "testnet_url"
case sandboxnetURL = "sandboxnet_url"
case crescendoURL = "crescendo_url"
case previewnetURL = "previewnet_url"
case description
case logo, category
}
Expand All @@ -23,7 +22,6 @@ struct DAppModel: Codable, Identifiable {
let testnetURL: URL?
let sandboxnetURL: URL?
let crescendoURL: URL?
let previewnetURL: URL?
let description: String
let logo: URL
let category: String
Expand All @@ -38,8 +36,6 @@ struct DAppModel: Codable, Identifiable {
return url
case .testnet:
return testnetURL
case .previewnet:
return previewnetURL
}
}

Expand Down
2 changes: 1 addition & 1 deletion FRW/Modules/Profile/DeveloperMode/DeveloperModeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct DeveloperModeView: RouteableView {
sysImageTuple: (
isTestnet ? .checkmarkSelected :
.checkmarkUnselected,
isTestnet ? LocalUserDefaults.FlowNetworkType.testnet
isTestnet ? FlowNetworkType.testnet
.color : .LL.Neutrals.neutrals1
),
title: "Testnet",
Expand Down
46 changes: 0 additions & 46 deletions FRW/Modules/Profile/DeveloperMode/DeveloperModeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,50 +78,4 @@ extension DeveloperModeViewModel {

LocalUserDefaults.shared.customWatchAddress = address
}

func enablePreviewnetAction() {
HUD.loading()

let failedBlock = {
DispatchQueue.main.async {
HUD.dismissLoading()
HUD.error(title: "enable_previewnet_failed".localized)
FlowNetwork.setup()
}
}

let successBlock = {
DispatchQueue.main.async {
HUD.dismissLoading()
WalletManager.shared.changeNetwork(.previewnet)
}
}

Task {
do {
let request = NetworkRequest(
accountKey: AccountKey(
hashAlgo: WalletManager.shared.hashAlgo.index,
publicKey: WalletManager.shared.getCurrentPublicKey() ?? "",
signAlgo: WalletManager.shared.signatureAlgo.index,
weight: 1000
),
network: "previewnet"
)
let id: String = try await Network.request(FRWAPI.User.previewnet(request))
let txId = Flow.ID(hex: id)
flow.configure(chainID: LocalUserDefaults.FlowNetworkType.previewnet.toFlowType())

let result = try await txId.onceSealed()
if result.isFailed {
failedBlock()
return
}
successBlock()
} catch {
debugPrint("DeveloperModeViewModel -> enablePreviewnetAction failed: \(error)")
failedBlock()
}
}
}
}
7 changes: 5 additions & 2 deletions FRW/Modules/TransactionList/TransactionListHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,11 @@ extension TransactionListHandler: UICollectionViewDelegateFlowLayout, UICollecti
func collectionView(_: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let item = dataList[indexPath.item]
UISelectionFeedbackGenerator().selectionChanged()
if let hash = item.hash, let url = hash.toFlowScanTransactionDetailURL {
Router.route(to: RouteMap.Explore.browser(url))
if let hash = item.hash {
let network = LocalUserDefaults.shared.flowNetwork
let accountType = AccountType.current
let url = network.getTransactionHistoryUrl(accountType: accountType, transactionId: hash)
url.map { Router.route(to: RouteMap.Explore.browser($0)) }
}
}
}
8 changes: 6 additions & 2 deletions FRW/Modules/TransactionList/TransferListHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,12 @@ extension TransferListHandler: UICollectionViewDelegateFlowLayout, UICollectionV
func collectionView(_: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let item = dataList[indexPath.item]
UISelectionFeedbackGenerator().selectionChanged()
if let txid = item.txid, let url = txid.toFlowScanTransactionDetailURL {
Router.route(to: RouteMap.Explore.browser(url))
if let txid = item.txid {
let network = LocalUserDefaults.shared.flowNetwork
let accountType = AccountType.current
let url = network.getTransactionHistoryUrl(accountType: accountType, transactionId: txid)

url.map { Router.route(to: RouteMap.Explore.browser($0)) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ class FlowTransactionViewMoreFooter: UICollectionReusableView {

@objc
private func onTap() {
guard let address = WalletManager.shared.getPrimaryWalletAddress(),
let url = address.toFlowScanAccountDetailURL else {
guard let address = WalletManager.shared.getPrimaryWalletAddress() else {
return
}

UIApplication.shared.open(url)
let network = LocalUserDefaults.shared.flowNetwork
let accountType = AccountType.current
let url = network.getAccountUrl(accountType: accountType, address: address)

url.map { UIApplication.shared.open($0) }
}
}
5 changes: 2 additions & 3 deletions FRW/Modules/TrustProvider/TrustJSMessageHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ class TrustJSMessageHandler: NSObject {
weak var webVC: BrowserViewController?

var supportChainID: [Int: Flow.ChainID] = [
LocalUserDefaults.FlowNetworkType.mainnet.networkID: .mainnet,
LocalUserDefaults.FlowNetworkType.testnet.networkID: .testnet,
LocalUserDefaults.FlowNetworkType.previewnet.networkID: .previewnet,
FlowNetworkType.mainnet.networkID: .mainnet,
FlowNetworkType.testnet.networkID: .testnet,
]
}

Expand Down
2 changes: 1 addition & 1 deletion FRW/Modules/Wallet/CustomToken/CustomTokenManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ struct CustomToken: Codable {

var userId: String
var belongAddress: String
var network: LocalUserDefaults.FlowNetworkType = .mainnet
var network: FlowNetworkType = .mainnet
var belong: CustomToken.Belong = .flow
// not store,
var balance: BigUInt?
Expand Down
2 changes: 1 addition & 1 deletion FRW/Modules/Wallet/MoveAsset/MoveTokenView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ extension MoveTokenView {
MoveTokenView(
tokenModel: TokenModel(
name: "Flow",
address: FlowNetworkModel(mainnet: "", testnet: "", crescendo: "", previewnet: ""),
address: FlowNetworkModel(mainnet: "", testnet: "", crescendo: ""),
contractName: "",
storagePath: FlowTokenStoragePath(balance: "100", vault: "a", receiver: ""),
decimal: 30,
Expand Down
Loading

0 comments on commit 3e46917

Please sign in to comment.