Skip to content

Commit

Permalink
417 Update evm tx history API
Browse files Browse the repository at this point in the history
  • Loading branch information
jeden committed Nov 20, 2024
1 parent 9349947 commit 6fcf278
Show file tree
Hide file tree
Showing 27 changed files with 177 additions and 117 deletions.
20 changes: 20 additions & 0 deletions FRW.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,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 */; };
6A0137662897E7A0009BEF20 /* HalfSheetModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A0137652897E7A0009BEF20 /* HalfSheetModal.swift */; };
6A0137672897E7A0009BEF20 /* HalfSheetModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A0137652897E7A0009BEF20 /* HalfSheetModal.swift */; };
6A0454CD28768E9E00A9131C /* SwiftUIPager in Frameworks */ = {isa = PBXBuildFile; productRef = 6A0454CC28768E9E00A9131C /* SwiftUIPager */; };
Expand Down Expand Up @@ -2568,6 +2572,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>"; };
6A0137652897E7A0009BEF20 /* HalfSheetModal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HalfSheetModal.swift; sourceTree = "<group>"; };
6A06CB0528AA25F400C81BE1 /* NFTUIKitListDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NFTUIKitListDataSource.swift; sourceTree = "<group>"; };
6A06CB0928AA485200C81BE1 /* NFTUIKitListStyleHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NFTUIKitListStyleHandler.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5192,6 +5198,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 @@ -5795,6 +5809,7 @@
4EC56B28281D381400246878 /* Firebase */,
159A5438275368DA004BCACC /* Network */,
15DE22CC277DBDC300B5EE03 /* Manager */,
57FD54452CEE987D00FFDDC5 /* Resources */,
);
path = Services;
sourceTree = "<group>";
Expand All @@ -5810,6 +5825,7 @@
6AC476E728F3C993008503E6 /* WebBookmark.swift */,
6A2C560A290BE46800306A6C /* Currency.swift */,
15DFD34B2CE197F9004B0DB8 /* AppExternalLinks.swift */,
57FD54462CEE996700FFDDC5 /* FlowNetworkType.swift */,
);
path = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -7051,6 +7067,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 @@ -7483,6 +7500,7 @@
15DC219327819C56000B187A /* VCheckBoxModel.swift in Sources */,
4EC26FCB2BFCB312001330DF /* EVMAssetProvider.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 @@ -7848,6 +7866,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 @@ -8280,6 +8299,7 @@
15C58C342868A4EE00BD4FC6 /* VCheckBoxModel.swift in Sources */,
4EC26FCA2BFCAF5C001330DF /* EVMAssetProvider.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
59 changes: 59 additions & 0 deletions FRW/Foundation/Model/FlowNetworkType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// 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
case previewnet

// MARK: Lifecycle

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

// MARK: Internal

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

var isMainnet: Bool {
self == .mainnet
}

func toFlowType() -> Flow.ChainID {
switch self {
case .testnet:
return Flow.ChainID.testnet
case .mainnet:
return Flow.ChainID.mainnet
case .previewnet:
return Flow.ChainID.previewnet
}
}
}
2 changes: 1 addition & 1 deletion FRW/Foundation/Model/WalletModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ 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(
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 @@ -219,8 +219,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
2 changes: 1 addition & 1 deletion FRW/Modules/Profile/DeveloperMode/DeveloperModeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct DeveloperModeView: RouteableView {
sysImageTuple: (
isTestnet ? .checkmarkSelected :
.checkmarkUnselected,
isTestnet ? LocalUserDefaults.FlowNetworkType.testnet
isTestnet ? FlowNetworkType.testnet
.color : .LL.Neutrals.neutrals1
),
title: "Testnet",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ extension DeveloperModeViewModel {
)
let id: String = try await Network.request(FRWAPI.User.previewnet(request))
let txId = Flow.ID(hex: id)
flow.configure(chainID: LocalUserDefaults.FlowNetworkType.previewnet.toFlowType())
flow.configure(chainID: FlowNetworkType.previewnet.toFlowType())

let result = try await txId.onceSealed()
if result.isFailed {
Expand Down
5 changes: 4 additions & 1 deletion FRW/Modules/TransactionList/TransactionListHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ 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 {
if let hash = item.hash {
let network = LocalUserDefaults.shared.flowNetwork
let accountType = AccountType.current
let url = network.getTransactionHistoryUrl(accountType: accountType, transactionId: hash)
Router.route(to: RouteMap.Explore.browser(url))
}
}
Expand Down
6 changes: 5 additions & 1 deletion FRW/Modules/TransactionList/TransferListHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,11 @@ 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 {
if let txid = item.txid {
let network = LocalUserDefaults.shared.flowNetwork
let accountType = AccountType.current
let url = network.getTransactionHistoryUrl(accountType: accountType, transactionId: txid)

Router.route(to: RouteMap.Explore.browser(url))
}
}
Expand Down
6 changes: 3 additions & 3 deletions FRW/Modules/TrustProvider/TrustJSMessageHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ 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,
FlowNetworkType.previewnet.networkID: .previewnet,
]
}

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 @@ -249,7 +249,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/SideMenu/AccountSideCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ struct AccountSideCell: View {

// MARK: Private

private var network: LocalUserDefaults.FlowNetworkType {
private var network: FlowNetworkType {
LocalUserDefaults.shared.flowNetwork
}

Expand Down
4 changes: 2 additions & 2 deletions FRW/Modules/Wallet/SideMenu/NetworkMenuItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import SwiftUI

struct NetworkMenuItem: View {
var network: LocalUserDefaults.FlowNetworkType
var currentNetwork: LocalUserDefaults.FlowNetworkType
var network: FlowNetworkType
var currentNetwork: FlowNetworkType

var isSelected: Bool {
network == currentNetwork
Expand Down
6 changes: 5 additions & 1 deletion FRW/Modules/Wallet/TokenDetail/TokenDetailViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,11 @@ extension TokenDetailViewModel {
}

func transferDetailAction(_ model: FlowScanTransfer) {
if let txid = model.txid, let url = txid.toFlowScanTransactionDetailURL {
if let txid = model.txid {
let network = LocalUserDefaults.shared.flowNetwork
let accountType = AccountType.current
let url = network.getTransactionHistoryUrl(accountType: accountType, transactionId: txid)

UIApplication.shared.open(url)
}
}
Expand Down
4 changes: 2 additions & 2 deletions FRW/Modules/Wallet/WalletAccount/WalletAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ extension WalletAccount {
forKey: WalletAccount.User.CodingKeys.address
)
self.network = try container.decode(
LocalUserDefaults.FlowNetworkType.self,
FlowNetworkType.self,
forKey: WalletAccount.User.CodingKeys.network
)
}
Expand All @@ -202,7 +202,7 @@ extension WalletAccount {
var emoji: WalletAccount.Emoji
var name: String
var address: String
var network: LocalUserDefaults.FlowNetworkType
var network: FlowNetworkType
}
}

Expand Down
4 changes: 2 additions & 2 deletions FRW/Services/FlowCoin/FlowAddressRegistor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ enum ScriptAddress: String, CaseIterable {
// MARK: Internal

static func addressMap(
on network: LocalUserDefaults.FlowNetworkType = LocalUserDefaults.shared
on network: FlowNetworkType = LocalUserDefaults.shared
.flowNetwork
) -> [String: String] {
let dict = ScriptAddress.allCases
Expand All @@ -45,7 +45,7 @@ enum ScriptAddress: String, CaseIterable {
}

func address(
on network: LocalUserDefaults.FlowNetworkType = LocalUserDefaults.shared
on network: FlowNetworkType = LocalUserDefaults.shared
.flowNetwork
) -> Flow.Address? {
guard let addressMap = RemoteConfigManager.shared.getContarctAddress(network),
Expand Down
2 changes: 1 addition & 1 deletion FRW/Services/Manager/Config/RemoteConfigManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class RemoteConfigManager {
}
}

func getContarctAddress(_ network: LocalUserDefaults.FlowNetworkType) -> [String: String]? {
func getContarctAddress(_ network: FlowNetworkType) -> [String: String]? {
switch network {
case .mainnet:
return contractAddress?.mainnet
Expand Down
Loading

0 comments on commit 6fcf278

Please sign in to comment.