From 2d14cc00d45d12b0cbfb76ac0b838f8bc425a721 Mon Sep 17 00:00:00 2001 From: Xin Liu Date: Mon, 8 Jul 2024 02:22:26 -0700 Subject: [PATCH] Always use Sepolia for DEBUG, Mainnet for RELEASE, for now --- Planet/Labs/Wallet/TipSelectView.swift | 14 +++++ Planet/Labs/Wallet/WalletAccountView.swift | 4 ++ Planet/PlanetUI.swift | 2 +- .../Settings/PlanetSettingsGeneralView.swift | 61 ++++++++++++------- Planet/versioning.xcconfig | 2 +- 5 files changed, 58 insertions(+), 25 deletions(-) diff --git a/Planet/Labs/Wallet/TipSelectView.swift b/Planet/Labs/Wallet/TipSelectView.swift index 34fe4611..f923da35 100644 --- a/Planet/Labs/Wallet/TipSelectView.swift +++ b/Planet/Labs/Wallet/TipSelectView.swift @@ -11,8 +11,15 @@ import Web3 struct TipSelectView: View { @Environment(\.dismiss) var dismiss + /* @AppStorage(String.settingsEthereumChainId) private var ethereumChainId: Int = UserDefaults .standard.integer(forKey: String.settingsEthereumChainId) + */ + #if DEBUG + @State private var ethereumChainId: Int = EthereumChainID.sepolia.rawValue + #else + @State private var ethereumChainId: Int = EthereumChainID.mainnet.rawValue + #endif @AppStorage(String.settingsEthereumTipAmount) private var tipAmount: Int = UserDefaults .standard.integer(forKey: String.settingsEthereumTipAmount) @@ -46,7 +53,12 @@ struct TipSelectView: View { Divider() HStack { Text("Please select the amount") + Spacer() + + Text("\(EthereumChainID.names[ethereumChainId] ?? "Unknown Chain ID \(ethereumChainId)")") + + /* Picker(selection: $ethereumChainId, label: Text("")) { ForEach(EthereumChainID.allCases, id: \.id) { value in Text( @@ -58,6 +70,8 @@ struct TipSelectView: View { } .pickerStyle(.menu) .frame(width: 120) + */ + /* TODO: Remove this V1 logic if WalletManager.shared.canSwitchNetwork() { Picker(selection: $ethereumChainId, label: Text("")) { diff --git a/Planet/Labs/Wallet/WalletAccountView.swift b/Planet/Labs/Wallet/WalletAccountView.swift index 9899dc2a..3e895eb6 100644 --- a/Planet/Labs/Wallet/WalletAccountView.swift +++ b/Planet/Labs/Wallet/WalletAccountView.swift @@ -153,7 +153,11 @@ struct WalletAccountView: View { Spacer() Button { + #if DEBUG + let etherscanURL = URL(string: "https://sepolia.etherscan.io/address/\(walletAddress)")! + #else let etherscanURL = URL(string: "https://etherscan.io/address/\(walletAddress)")! + #endif NSWorkspace.shared.open(etherscanURL) } label: { Text("Etherscan") diff --git a/Planet/PlanetUI.swift b/Planet/PlanetUI.swift index 13b36985..b64a07ba 100644 --- a/Planet/PlanetUI.swift +++ b/Planet/PlanetUI.swift @@ -32,5 +32,5 @@ struct PlanetUI { // Button min width for buttons with short labels like "OK" static let BUTTON_MIN_WIDTH_SHORT: CGFloat = 50 - static let SETTINGS_CAPTION_WIDTH: CGFloat = 120 + static let SETTINGS_CAPTION_WIDTH: CGFloat = 140 } diff --git a/Planet/Settings/PlanetSettingsGeneralView.swift b/Planet/Settings/PlanetSettingsGeneralView.swift index 5a411523..f75e688a 100644 --- a/Planet/Settings/PlanetSettingsGeneralView.swift +++ b/Planet/Settings/PlanetSettingsGeneralView.swift @@ -21,7 +21,8 @@ struct PlanetSettingsGeneralView: View { PlanetStore.shared.selectedView = nil PlanetStore.shared.selectedArticleList = nil PlanetStore.shared.refreshSelectedArticles() - } catch { + } + catch { debugPrint("failed to reload: \(error)") } } @@ -29,8 +30,10 @@ struct PlanetSettingsGeneralView: View { } } - @AppStorage(String.settingsPreferredIPFSPublicGateway) private var preferredIPFSPublicGateway: String = - UserDefaults.standard.string(forKey: String.settingsPreferredIPFSPublicGateway) ?? IPFSGateway.defaultGateway.rawValue + @AppStorage(String.settingsPreferredIPFSPublicGateway) private var preferredIPFSPublicGateway: + String = + UserDefaults.standard.string(forKey: String.settingsPreferredIPFSPublicGateway) + ?? IPFSGateway.defaultGateway.rawValue @AppStorage(String.settingsEthereumChainId) private var ethereumChainId: Int = UserDefaults .standard.integer(forKey: String.settingsEthereumChainId) @@ -57,7 +60,8 @@ struct PlanetSettingsGeneralView: View { Button { do { try updateLibraryLocation() - } catch { + } + catch { resetLibraryLocation() let alert = NSAlert() alert.messageText = "Failed to Change Library Location" @@ -111,36 +115,42 @@ struct PlanetSettingsGeneralView: View { .pickerStyle(.menu) .onChange(of: preferredIPFSPublicGateway) { newValue in // Refresh Published Folders Dashboard Toolbar - NotificationCenter.default.post(name: .dashboardRefreshToolbar, object: nil) + NotificationCenter.default.post( + name: .dashboardRefreshToolbar, + object: nil + ) } } - if PlanetStore.app == .planet { - VStack { - HStack(spacing: 4) { - Text("Ethereum Network") - .frame(width: PlanetUI.SETTINGS_CAPTION_WIDTH, alignment: .trailing) - Picker(selection: $ethereumChainId, label: Text("")) { - ForEach(EthereumChainID.allCases, id: \.id) { value in - Text( - "\(EthereumChainID.names[value.rawValue] ?? "Unknown Chain ID \(value.rawValue)")" + #if DEBUG + if PlanetStore.app == .planet { + VStack(spacing: 4) { + HStack(spacing: 4) { + Text("Ethereum Network") + .frame( + width: PlanetUI.SETTINGS_CAPTION_WIDTH, + alignment: .trailing ) - .tag(value) + Picker(selection: $ethereumChainId, label: Text("")) { + ForEach(EthereumChainID.allCases, id: \.id) { value in + Text( + "\(EthereumChainID.names[value.rawValue] ?? "Unknown Chain ID \(value.rawValue)")" + ) + .tag(value) + } } + .pickerStyle(.segmented) } - .pickerStyle(.segmented) - } - HStack { - Text("") - .frame(width: PlanetUI.SETTINGS_CAPTION_WIDTH) Text( "When you tip a creator, transactions will be sent to the selected Ethereum network." ) + .frame(minHeight: 40) .font(.footnote) .foregroundColor(.secondary) + .padding(.leading, PlanetUI.SETTINGS_CAPTION_WIDTH + 10) } } - } + #endif } } @@ -180,7 +190,8 @@ struct PlanetSettingsGeneralView: View { let alert = NSAlert() alert.messageText = "Existing Planet Library Found" alert.alertStyle = .warning - alert.informativeText = "Would you like to use new library location at: \(url.path), current database including following planets will be replaced with contents at this location." + alert.informativeText = + "Would you like to use new library location at: \(url.path), current database including following planets will be replaced with contents at this location." alert.addButton(withTitle: "Cancel") alert.addButton(withTitle: "Continue & Update") let result = alert.runModal() @@ -189,7 +200,11 @@ struct PlanetSettingsGeneralView: View { } } let bookmarkKey = url.path.md5() - let bookmarkData = try url.bookmarkData(options: .withSecurityScope, includingResourceValuesForKeys: nil, relativeTo: nil) + let bookmarkData = try url.bookmarkData( + options: .withSecurityScope, + includingResourceValuesForKeys: nil, + relativeTo: nil + ) UserDefaults.standard.set(bookmarkData, forKey: bookmarkKey) if !useAsExistingLibraryLocation { try FileManager.default.copyItem(at: URLUtils.repoPath(), to: planetURL) diff --git a/Planet/versioning.xcconfig b/Planet/versioning.xcconfig index 96da3f60..f19beee8 100644 --- a/Planet/versioning.xcconfig +++ b/Planet/versioning.xcconfig @@ -1 +1 @@ -CURRENT_PROJECT_VERSION = 2116 +CURRENT_PROJECT_VERSION = 2118