Skip to content

Commit

Permalink
Always use Sepolia for DEBUG, Mainnet for RELEASE, for now
Browse files Browse the repository at this point in the history
  • Loading branch information
livid committed Jul 8, 2024
1 parent e6b27eb commit 2d14cc0
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 25 deletions.
14 changes: 14 additions & 0 deletions Planet/Labs/Wallet/TipSelectView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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(
Expand All @@ -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("")) {
Expand Down
4 changes: 4 additions & 0 deletions Planet/Labs/Wallet/WalletAccountView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion Planet/PlanetUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
61 changes: 38 additions & 23 deletions Planet/Settings/PlanetSettingsGeneralView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@ struct PlanetSettingsGeneralView: View {
PlanetStore.shared.selectedView = nil
PlanetStore.shared.selectedArticleList = nil
PlanetStore.shared.refreshSelectedArticles()
} catch {
}
catch {
debugPrint("failed to reload: \(error)")
}
}
}
}
}

@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)
Expand All @@ -57,7 +60,8 @@ struct PlanetSettingsGeneralView: View {
Button {
do {
try updateLibraryLocation()
} catch {
}
catch {
resetLibraryLocation()
let alert = NSAlert()
alert.messageText = "Failed to Change Library Location"
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Planet/versioning.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CURRENT_PROJECT_VERSION = 2116
CURRENT_PROJECT_VERSION = 2118

0 comments on commit 2d14cc0

Please sign in to comment.