From 2554268a98d0779fe654cb184c06b457dc2b9721 Mon Sep 17 00:00:00 2001 From: Chung Tran Date: Tue, 2 Jan 2024 16:41:03 +0700 Subject: [PATCH 1/2] fix: KEYAPP_ORG_API_KEY --- .../Extensions/SolanaSDK+Extensions.swift | 7 +++-- p2p_wallet/Info.plist | 2 ++ .../ViewModel/DebugMenuViewModel.swift | 26 ++++++++++++++++--- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/p2p_wallet/Common/Extensions/SolanaSDK+Extensions.swift b/p2p_wallet/Common/Extensions/SolanaSDK+Extensions.swift index d92c09fea7..a9e72ff464 100644 --- a/p2p_wallet/Common/Extensions/SolanaSDK+Extensions.swift +++ b/p2p_wallet/Common/Extensions/SolanaSDK+Extensions.swift @@ -15,8 +15,11 @@ extension APIEndPoint { var endpoints = remoteEndpoints.isEmpty ? defaultEndpoints : remoteEndpoints if remoteEndpoints.isEmpty { endpoints.insert( - .init(address: "https://p2p.rpcpool.com", network: .mainnetBeta, - additionalQuery: .secretConfig("RPCPOOL_API_KEY")), + .init( + address: "https://solana.keyapp.org", + network: .mainnetBeta, + additionalQuery: .secretConfig("KEYAPP_ORG_API_KEY") + ), at: 0 ) #if !DEBUG diff --git a/p2p_wallet/Info.plist b/p2p_wallet/Info.plist index 322de822a5..17d104cedb 100644 --- a/p2p_wallet/Info.plist +++ b/p2p_wallet/Info.plist @@ -177,6 +177,8 @@ $(TRANSAK_PRODUCTION_API_KEY) TRANSAK_STAGING_API_KEY $(TRANSAK_STAGING_API_KEY) + KEYAPP_ORG_API_KEY + $(KEYAPP_ORG_API_KEY) UIApplicationSupportsIndirectInputEvents UIBackgroundModes diff --git a/p2p_wallet/Scenes/DebugMenu/ViewModel/DebugMenuViewModel.swift b/p2p_wallet/Scenes/DebugMenu/ViewModel/DebugMenuViewModel.swift index 396524ac32..e7916acdf7 100644 --- a/p2p_wallet/Scenes/DebugMenu/ViewModel/DebugMenuViewModel.swift +++ b/p2p_wallet/Scenes/DebugMenu/ViewModel/DebugMenuViewModel.swift @@ -25,10 +25,28 @@ final class DebugMenuViewModel: BaseViewModel, ObservableObject { } let solanaEndpoints: [APIEndPoint] = [ - .init(address: "https://api.mainnet-beta.solana.com", network: .mainnetBeta), - .init(address: "https://solana-api.projectserum.com", network: .mainnetBeta), - .init(address: "https://p2p.rpcpool.com", network: .mainnetBeta), - .init(address: "https://api.devnet.solana.com", network: .devnet), + .init( + address: "https://api.mainnet-beta.solana.com", + network: .mainnetBeta + ), + .init( + address: "https://solana-api.projectserum.com", + network: .mainnetBeta + ), + .init( + address: "https://p2p.rpcpool.com", + network: .mainnetBeta, + additionalQuery: .secretConfig("RPCPOOL_API_KEY") + ), + .init( + address: "https://solana.keyapp.org", + network: .mainnetBeta, + additionalQuery: .secretConfig("KEYAPP_ORG_API_KEY") + ), + .init( + address: "https://api.devnet.solana.com", + network: .devnet + ), ] self.solanaEndpoints = solanaEndpoints selectedEndpoint = solanaEndpoints.first(where: { $0 == Defaults.apiEndPoint }) From a34a0c6ce63710209c6e628eaa28107ea275fba6 Mon Sep 17 00:00:00 2001 From: Chung Tran Date: Tue, 2 Jan 2024 17:33:46 +0700 Subject: [PATCH 2/2] feat: migrate to new endpoint --- .../Extensions/SolanaSDK+Extensions.swift | 26 +++++++++---------- .../MigrationWarmupProcess.swift | 20 ++++++++++++++ .../Resolver+registerAllServices.swift | 1 + 3 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 p2p_wallet/Common/Services/WarmupService/MigrationWarmupProcess.swift diff --git a/p2p_wallet/Common/Extensions/SolanaSDK+Extensions.swift b/p2p_wallet/Common/Extensions/SolanaSDK+Extensions.swift index a9e72ff464..1a2481dc1d 100644 --- a/p2p_wallet/Common/Extensions/SolanaSDK+Extensions.swift +++ b/p2p_wallet/Common/Extensions/SolanaSDK+Extensions.swift @@ -13,19 +13,19 @@ extension APIEndPoint { ) } var endpoints = remoteEndpoints.isEmpty ? defaultEndpoints : remoteEndpoints - if remoteEndpoints.isEmpty { - endpoints.insert( - .init( - address: "https://solana.keyapp.org", - network: .mainnetBeta, - additionalQuery: .secretConfig("KEYAPP_ORG_API_KEY") - ), - at: 0 - ) - #if !DEBUG - endpoints.removeAll { $0.network == .testnet || $0.network == .devnet } - #endif - } +// if remoteEndpoints.isEmpty { + endpoints.insert( + .init( + address: "https://solana.keyapp.org", + network: .mainnetBeta, + additionalQuery: .secretConfig("KEYAPP_ORG_API_KEY") + ), + at: 0 + ) + #if !DEBUG + endpoints.removeAll { $0.network == .testnet || $0.network == .devnet } + #endif +// } return endpoints } } diff --git a/p2p_wallet/Common/Services/WarmupService/MigrationWarmupProcess.swift b/p2p_wallet/Common/Services/WarmupService/MigrationWarmupProcess.swift new file mode 100644 index 0000000000..fb8946a2ea --- /dev/null +++ b/p2p_wallet/Common/Services/WarmupService/MigrationWarmupProcess.swift @@ -0,0 +1,20 @@ +import Foundation +import Resolver + +class MigrationWarmupProcess: WarmupProcess { + func start() async { + // Migrate to endpoint solana.keyapp.org + let migration1Key = "APIEndpoint.migrationKey1" + if !UserDefaults.standard.bool(forKey: migration1Key) { + Resolver.resolve(ChangeNetworkResponder.self) + .changeAPIEndpoint( + to: .init( + address: "https://solana.keyapp.org", + network: .mainnetBeta, + additionalQuery: .secretConfig("KEYAPP_ORG_API_KEY") + ) + ) + UserDefaults.standard.set(true, forKey: migration1Key) + } + } +} diff --git a/p2p_wallet/Injection/Resolver+registerAllServices.swift b/p2p_wallet/Injection/Resolver+registerAllServices.swift index 1e9db0f145..49b0ee5941 100644 --- a/p2p_wallet/Injection/Resolver+registerAllServices.swift +++ b/p2p_wallet/Injection/Resolver+registerAllServices.swift @@ -42,6 +42,7 @@ extension Resolver: ResolverRegistering { WarmupManager(processes: [ RemoteConfigWarmupProcess(), TokenServiceWarmupProcess(), + MigrationWarmupProcess(), ]) }.scope(.application)