Skip to content

Commit

Permalink
#10: Add POST wallet request
Browse files Browse the repository at this point in the history
  • Loading branch information
VictoriaKostyleva committed Oct 5, 2022
1 parent 9d43e65 commit b8d17e8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -251,6 +252,7 @@
923C373628EC791E003CFC03 /* WalletRouteCollection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletRouteCollection.swift; sourceTree = "<group>"; };
923C373928EC79E8003CFC03 /* Wallet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Wallet.swift; sourceTree = "<group>"; };
923C373B28ED79A2003CFC03 /* Mnemonic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Mnemonic.swift; sourceTree = "<group>"; };
923C373D28EDB109003CFC03 /* PostMnemonicResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostMnemonicResponse.swift; sourceTree = "<group>"; };
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 = "<group>"; };
92D6B3FE28E19E20004CF9DF /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -641,6 +643,7 @@
children = (
923C373B28ED79A2003CFC03 /* Mnemonic.swift */,
923C373928EC79E8003CFC03 /* Wallet.swift */,
923C373D28EDB109003CFC03 /* PostMnemonicResponse.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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<String, Error>) 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
Expand Down

0 comments on commit b8d17e8

Please sign in to comment.