diff --git a/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS.xcodeproj/project.pbxproj b/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS.xcodeproj/project.pbxproj index 3d89130..6743425 100644 --- a/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS.xcodeproj/project.pbxproj +++ b/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS.xcodeproj/project.pbxproj @@ -93,6 +93,7 @@ 923C373728EC791E003CFC03 /* WalletRouteCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 923C373628EC791E003CFC03 /* WalletRouteCollection.swift */; }; 923C373A28EC79E8003CFC03 /* Wallet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 923C373928EC79E8003CFC03 /* Wallet.swift */; }; 923C373C28ED79A2003CFC03 /* Mnemonic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 923C373B28ED79A2003CFC03 /* Mnemonic.swift */; }; + 923C373E28EDB109003CFC03 /* PostMnemonicResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 923C373D28EDB109003CFC03 /* PostMnemonicResponse.swift */; }; 92D6B3FD28E19E20004CF9DF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92D6B3FC28E19E20004CF9DF /* AppDelegate.swift */; }; 92D6B3FF28E19E20004CF9DF /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92D6B3FE28E19E20004CF9DF /* SceneDelegate.swift */; }; 92D6B40128E19E20004CF9DF /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92D6B40028E19E20004CF9DF /* ViewController.swift */; }; @@ -251,6 +252,7 @@ 923C373628EC791E003CFC03 /* WalletRouteCollection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletRouteCollection.swift; sourceTree = ""; }; 923C373928EC79E8003CFC03 /* Wallet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Wallet.swift; sourceTree = ""; }; 923C373B28ED79A2003CFC03 /* Mnemonic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Mnemonic.swift; sourceTree = ""; }; + 923C373D28EDB109003CFC03 /* PostMnemonicResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostMnemonicResponse.swift; sourceTree = ""; }; 92D6B3F928E19E20004CF9DF /* SOLARdVPNCommunityCoreiOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SOLARdVPNCommunityCoreiOS.app; sourceTree = BUILT_PRODUCTS_DIR; }; 92D6B3FC28E19E20004CF9DF /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 92D6B3FE28E19E20004CF9DF /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; @@ -641,6 +643,7 @@ children = ( 923C373B28ED79A2003CFC03 /* Mnemonic.swift */, 923C373928EC79E8003CFC03 /* Wallet.swift */, + 923C373D28EDB109003CFC03 /* PostMnemonicResponse.swift */, ); path = Models; sourceTree = ""; @@ -1080,6 +1083,7 @@ 22C3EEAA28E4733C007DB01B /* NETunnelProviderProtocol+Extension.swift in Sources */, 22488AA328E72C4E00FE29C3 /* StoresWallet.swift in Sources */, 22C3EED128E48B52007DB01B /* TunnelStatus.swift in Sources */, + 923C373E28EDB109003CFC03 /* PostMnemonicResponse.swift in Sources */, 923C373328EB150A003CFC03 /* GetContinentResponse.swift in Sources */, 923C372A28EAFAA5003CFC03 /* NodesServiceError.swift in Sources */, 225A836C28EACE6C00F66619 /* ConnectionNodeModel.swift in Sources */, diff --git a/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/Root/RouteCollections/Wallet/Models/PostMnemonicResponse.swift b/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/Root/RouteCollections/Wallet/Models/PostMnemonicResponse.swift new file mode 100644 index 0000000..3d822c4 --- /dev/null +++ b/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/Root/RouteCollections/Wallet/Models/PostMnemonicResponse.swift @@ -0,0 +1,13 @@ +// +// PostMnemonicResponse.swift +// SOLARdVPNCommunityCoreiOS +// +// Created by Viktoriia Kostyleva on 05.10.2022. +// + +import Foundation + +struct PostMnemonicResponse: Codable { + let wallet: Wallet + let mnemonic: String +} diff --git a/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/Root/RouteCollections/Wallet/WalletRouteCollection.swift b/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/Root/RouteCollections/Wallet/WalletRouteCollection.swift index 7311a8e..7d7173d 100644 --- a/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/Root/RouteCollections/Wallet/WalletRouteCollection.swift +++ b/SolardVPNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/Root/RouteCollections/Wallet/WalletRouteCollection.swift @@ -14,6 +14,7 @@ struct WalletRouteCollection: RouteCollection { func boot(routes: RoutesBuilder) throws { routes.get("wallet", use: getWallet) routes.put("wallet", use: putWallet) + routes.post("wallet", use: postWallet) } } @@ -62,6 +63,28 @@ extension WalletRouteCollection { } }) } + + func postWallet(_ req: Request) async throws -> String { + context.resetWalletContext() + + let address = context.walletStorage.walletAddress + + guard let mnemonic = context.securityService.loadMnemonics(for: address) else { + throw Abort(.init(statusCode: 500), reason: "Failed to liad mnemonic") + } + + return try await withCheckedThrowingContinuation({ (continuation: CheckedContinuation) in + getWallet() { result in + switch result { + case let .failure(error): + continuation.resume(throwing: Abort(.init(statusCode: 500), reason: error.localizedDescription)) + case let .success(wallet): + let response = PostMnemonicResponse(wallet: wallet, mnemonic: mnemonic.joined(separator: " ")) + Encoder.encode(model: response, continuation: continuation) + } + } + }) + } } // MARK: - Private