Skip to content

Commit

Permalink
Merge commit '0ae014976b92b7cfd622ec6e27e42786d5960afd' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
bigearsenal committed Jan 4, 2024
2 parents 12fe463 + 0ae0149 commit a761fd6
Show file tree
Hide file tree
Showing 110 changed files with 573 additions and 654 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extension SolanaAPIClient {
/// Retrieves associated SPL Token address for ``address``.
///
/// - Returns: The associated address.
internal func getAssociatedSPLTokenAddress(for address: PublicKey, mint: PublicKey) async throws -> PublicKey {
func getAssociatedSPLTokenAddress(for address: PublicKey, mint: PublicKey) async throws -> PublicKey {
let account: BufferInfo<SPLTokenAccountState>? = try? await getAccountInfo(account: address.base58EncodedString)

// The account doesn't exists
Expand All @@ -31,7 +31,7 @@ extension SolanaAPIClient {
return try PublicKey.associatedTokenAddress(walletAddress: address, tokenMintAddress: mint)
}

internal func isAccountExists(_ address: PublicKey) async throws -> Bool {
func isAccountExists(_ address: PublicKey) async throws -> Bool {
let account: BufferInfo<EmptyInfo>? = try await getAccountInfo(account: address.base58EncodedString)
return account != nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public class RelayContextManagerImpl: RelayContextManager {
}
}

internal extension FeeLimitForAuthorityResponse {
extension FeeLimitForAuthorityResponse {
func asUsageStatus() -> UsageStatus {
UsageStatus(
maxUsage: limits.maxFeeCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class KeyAppHistoryProviderImpl: KeyAppHistoryProvider {
}
}

internal struct TransactionsRequestParams: Codable {
struct TransactionsRequestParams: Codable {
var pubKey: String
var limit: UInt64
var offset: UInt64
Expand Down
8 changes: 4 additions & 4 deletions Packages/KeyAppKit/Sources/JSBridge/JSBContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ public class JSBContext: NSObject {
/// An id that indicates current unused local variable.
///
/// The local variable will be used for temporary or permanent js data storage.
internal var variableId: Int = 0
var variableId: Int = 0

/// A dispatch table for callback from async js functions.
internal var promiseDispatchTable: PromiseDispatchTable = .init()
var promiseDispatchTable: PromiseDispatchTable = .init()

internal let wkWebView: WKWebView
let wkWebView: WKWebView

/// A local variable prefix.
private static let kJsbValueName = "__localBridgeVariable"

/// A WKWebview channel for returning values from JS `Promise`.
internal static let kPromiseCallback = "promiseCallback"
static let kPromiseCallback = "promiseCallback"

public init(wkWebView: WKWebView? = nil) {
self.wkWebView = wkWebView ?? WKWebView()
Expand Down
8 changes: 4 additions & 4 deletions Packages/KeyAppKit/Sources/JSBridge/JSBValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class JSBValue: JSBridge, CustomStringConvertible {
currentContext = context
}

internal init(name: String) {
init(name: String) {
// Set variable name
self.name = name
}
Expand Down Expand Up @@ -114,13 +114,13 @@ public class JSBValue: JSBridge, CustomStringConvertible {
}

/// Parse swift args to js args.
internal func parseArgs(_ args: [CustomStringConvertible]) throws -> String {
func parseArgs(_ args: [CustomStringConvertible]) throws -> String {
try args
.map(parse)
.joined(separator: ", ")
}

internal func parse(_ arg: CustomStringConvertible) throws -> String {
func parse(_ arg: CustomStringConvertible) throws -> String {
if let arg = arg as? String {
return "\"\(arg.safe)\""
}
Expand Down Expand Up @@ -187,7 +187,7 @@ public class JSBValue: JSBridge, CustomStringConvertible {
}
}

internal extension String {
extension String {
/// Make string be safed in js
var safe: String {
replacingOccurrences(of: "\"", with: "\\\"")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class JupiterRestClientAPI: JupiterAPI {
}

public func getTokens() async throws -> [TokenMetadata] {
let (data, _) = try await URLSession.shared.data(from: URL(string: "\(tokensHost ?? host)/tokens")!)
let (data, _) = try await URLSession.shared.data(from: URL(string: "\(tokensHost ?? "\(host)/tokens")")!)
return try JSONDecoder().decode([TokenMetadata].self, from: data)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public final class EthereumAccountsService: NSObject, AccountsService {
try await accounts.fetch()?.value
}

internal func fetchPrice(
func fetchPrice(
state: AsyncValueState<[EthereumAccount]>,
fiat: String
) -> Future<AsyncValueState<[Account]>, Never> {
Expand Down Expand Up @@ -153,7 +153,7 @@ public final class EthereumAccountsService: NSObject, AccountsService {
}
}

internal class EthereumAccountAsyncValue: AsyncValue<[EthereumAccount]> {
class EthereumAccountAsyncValue: AsyncValue<[EthereumAccount]> {
enum Error: Swift.Error {
case invalidEthereumAddress
}
Expand Down Expand Up @@ -208,7 +208,7 @@ internal class EthereumAccountAsyncValue: AsyncValue<[EthereumAccount]> {
}

/// Method resolve ethereum erc-20 token accounts.
internal static func resolveTokenAccounts(
static func resolveTokenAccounts(
address: String,
balances: [EthereumTokenBalances.Balance],
repository: EthereumTokensRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public final class EthereumTokensRepository {
try await resolve(addresses: [address]).values.first
}

internal func parseToken(tokenData: KeyAppTokenProviderData.Token) throws -> EthereumToken {
func parseToken(tokenData: KeyAppTokenProviderData.Token) throws -> EthereumToken {
// Logo
let logo: URL?
if let logoUrl = tokenData.logoUrl {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import BigDecimal
import Foundation
import KeyAppKitCore

internal enum PriceRuleHandler {
enum PriceRuleHandler {
case `continue`(TokenPrice?)
case `break`(TokenPrice?)
}

internal protocol PriceRule {
protocol PriceRule {
func adjustValue(token: SomeToken, price: TokenPrice, fiat: String) -> PriceRuleHandler
}

// Make price rate equals 1:1 when `ruleOfProcessingTokenPrice` equals `byCountOfTokensValue`.
internal class OneToOnePriceRule: PriceRule {
class OneToOnePriceRule: PriceRule {
func adjustValue(token: SomeToken, price: TokenPrice, fiat _: String) -> PriceRuleHandler {
if token.keyAppExtension.ruleOfProcessingTokenPriceWS == .byCountOfTokensValue {
return .continue(TokenPrice(currencyCode: price.currencyCode, value: 1.0, token: token))
Expand All @@ -23,7 +23,7 @@ internal class OneToOnePriceRule: PriceRule {
}

// Depegging price by measure percentage difference.
internal class DepeggingPriceRule: PriceRule {
class DepeggingPriceRule: PriceRule {
func adjustValue(token: SomeToken, price: TokenPrice, fiat _: String) -> PriceRuleHandler {
if let allowPercentageDifferenceValue = token.keyAppExtension.percentDifferenceToShowByPriceOnWS {
let percentageDifferenceValue = 100 - (1 / price.value) * 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public class PriceServiceImpl: PriceService {
}

/// Method for fetching price from server
internal func fetchTokenPrice(tokens: [AnyToken], fiat: String) async throws -> [SomeToken: TokenPrice] {
func fetchTokenPrice(tokens: [AnyToken], fiat: String) async throws -> [SomeToken: TokenPrice] {
var result: [SomeToken: TokenPrice] = [:]

// Request token price
Expand Down Expand Up @@ -261,7 +261,7 @@ public class PriceServiceImpl: PriceService {
}
}

internal extension AnyToken {
extension AnyToken {
/// Map token to requested primary key in backend.
var addressPriceMapping: String {
switch network {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public final class SolanaAccountsService: NSObject, AccountsService {
try await fetchedAccountsByRpc.fetch()?.value
}

internal func fetchPrice(
func fetchPrice(
for state: AsyncValueState<[Account]>,
fiat: String
) -> Future<AsyncValueState<[Account]>, Never> {
Expand Down Expand Up @@ -193,7 +193,7 @@ public final class SolanaAccountsService: NSObject, AccountsService {
}

/// Update single accounts.
internal func onUpdateAccount(account: SolanaAccount) {
func onUpdateAccount(account: SolanaAccount) {
var state = accountsStream.value

let matchIdx = state.value
Expand Down Expand Up @@ -238,7 +238,7 @@ public extension SolanaAccountsService {
}
}

internal class SolanaAccountAsyncValue: AsyncValue<[SolanaAccount]> {
class SolanaAccountAsyncValue: AsyncValue<[SolanaAccount]> {
enum Error: Swift.Error {
case authorityError
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ public typealias SolanaTokensService = TokenRepository
public actor KeyAppSolanaTokenRepository: TokenRepository {
static let version: Int = 1

internal struct Database: Codable, Hashable {
struct Database: Codable, Hashable {
var timestamps: Date?
var data: [String: SolanaToken]
var version: Int?
}

internal enum Status: Int {
enum Status: Int {
case initialising = 0
case updating
case ready
Expand Down Expand Up @@ -200,7 +200,7 @@ private extension TokenMetadata {

// fix the mint
return SolanaToken(
_tags: [],
tags: tags.map(\.name),
chainId: chainId,
mintAddress: "So11111111111111111111111111111111111111112",
symbol: symbol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public struct EthereumKeyPair: Equatable, Hashable {
}

/// Protected area data.
internal let privateKey: EthereumPrivateKey
let privateKey: EthereumPrivateKey

/// Ethereum public key
public var publicKey: String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public actor TKeyJSFacade: TKeyFacade {
return RefreshDeviceShareResult(share: deviceShare)
}

internal func parseFacadeJSError(error: Any) -> TKeyFacadeError? {
func parseFacadeJSError(error: Any) -> TKeyFacadeError? {
guard
let errorStr = error as? String,
let error = errorStr.data(using: .utf8)
Expand Down
6 changes: 3 additions & 3 deletions Packages/KeyAppKit/Sources/Onboarding/Common/Crypto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ enum CryptoError: Error {
case invalidMac
}

internal enum Crypto {
internal struct EncryptedMetadata: Codable {
enum Crypto {
struct EncryptedMetadata: Codable {
let nonce: String
let metadataCiphered: String

Expand All @@ -18,7 +18,7 @@ internal enum Crypto {
}
}

internal static func extractSymmetricKey(seedPhrase: String) throws -> Data {
static func extractSymmetricKey(seedPhrase: String) throws -> Data {
try extractOnboardingSeedPhrase(phrase: seedPhrase, path: "m/44'/101'/0'/0'")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import SolanaSwift
import TweetNacl

internal func extractOnboardingSeedPhrase(phrase: String, path: String) throws -> Data {
func extractOnboardingSeedPhrase(phrase: String, path: String) throws -> Data {
let mnemonic = try Mnemonic(phrase: phrase.components(separatedBy: " "))
let secretKey = try Ed25519HDKey.derivePath(path, seed: mnemonic.seed.toHexString()).get().key
let keyPair = try NaclSign.KeyPair.keyPair(fromSeed: secretKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public enum SocialSignInState: Codable, State, Equatable {
}
}

internal func socialSelectionEventHandler(
func socialSelectionEventHandler(
currentState _: Self, event: Event,
provider: Provider
) async throws -> Self {
Expand All @@ -78,7 +78,7 @@ public enum SocialSignInState: Codable, State, Equatable {
}
}

internal func socialSignInProgressEventHandler(event: Event, provider: Provider) async throws -> Self {
func socialSignInProgressEventHandler(event: Event, provider: Provider) async throws -> Self {
switch event {
case let .signInTorus(value, email, socialProvider):
let tokenID = TokenID(value: value, provider: socialProvider.rawValue)
Expand Down Expand Up @@ -118,7 +118,7 @@ public enum SocialSignInState: Codable, State, Equatable {
}
}

internal func socialTryAgainEventHandler(
func socialTryAgainEventHandler(
currentState _: Self, event: Event,
provider: Provider
) async throws -> Self {
Expand Down Expand Up @@ -161,7 +161,7 @@ public enum SocialSignInState: Codable, State, Equatable {
}
}

internal func socialSignInAccountWasUsedHandler(
func socialSignInAccountWasUsedHandler(
currentState: Self, event: Event,
provider: Provider
) async throws -> Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SolanaSwift

public struct ICloudAccount: Codable, Hashable {
public let name: String?
internal let phrase: String
let phrase: String
public let derivablePath: DerivablePath
public let publicKey: String

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import FeeRelayerSwift
import Foundation
import SolanaSwift

struct SendInputBusinessLogic {
enum SendInputBusinessLogic {
static func sendInputBusinessLogic(
state: SendInputState,
action: SendInputAction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ extension RecipientSearchServiceImpl {
// detect token
let token = config
.tokens[accountInfo.mint.base58EncodedString] ??
.unsupported(mint: accountInfo.mint.base58EncodedString, decimals: 1, symbol: "", supply: nil)
.unsupported(
tags: nil,
mint: accountInfo.mint.base58EncodedString,
decimals: 1,
symbol: "",
supply: nil
)

// detect category
let category = try Recipient.Category.solanaTokenAddress(
Expand Down
2 changes: 1 addition & 1 deletion Packages/KeyAppKit/Sources/Send/UsernameUtils.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

struct UsernameUtils {
enum UsernameUtils {
static func splitIntoNameAndDomain(rawName: String) -> (name: String, domain: String) {
var name = ""
var domain = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ extension TokenAmount: CryptoAmountConvertible {

if let mint {
token = SolanaToken(
_tags: nil,
tags: nil,
chainId: 0,
mintAddress: mint,
symbol: symbol,
Expand Down
2 changes: 1 addition & 1 deletion Packages/KeyAppKit/Sources/Wormhole/SupportedToken.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import KeyAppKitCore

public enum SupportedToken {
public static let usdt: SolanaToken = .init(
_tags: nil,
tags: nil,
chainId: 101,
mintAddress: "Dn4noZ5jgGfkntzcQSUZ8czkreiZ1ForXYoV2H8Dm7S1",
symbol: "USDTet",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

struct ClientError {
enum ClientError {
static var insufficientFunds: String {
#"{"code":6,"data":{"ClientError":["RpcError: RpcResponseError {\n code: -32002,\n message: \"Transaction simulation failed: Error processing Instruction 3: custom program error: 0x1\",\n data: SendTransactionPreflightFailure(\n RpcSimulateTransactionResult {\n err: Some(\n InstructionError(\n 3,\n Custom(\n 1,\n ),\n ),\n ),\n logs: Some(\n [\n \"Program 11111111111111111111111111111111 invoke [1]\",\n \"Program 11111111111111111111111111111111 success\",\n \"Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]\",\n \"Program log: Instruction: InitializeAccount\",\n \"Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3392 of 200000 compute units\",\n \"Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success\",\n \"Program 12YKFL4mnZz6CBEGePrf293mEzueQM3h8VLPUJsKpGs9 invoke [1]\",\n \"Program log: Process instruction. Program id: 12YKFL4mnZz6CBEGePrf293mEzueQM3h8VLPUJsKpGs9, 7 accounts, data: [3]\",\n \"Program log: Instruction: CreateTransitTokenAccount\",\n \"Program log: Invoke create transit token account\",\n \"Program 11111111111111111111111111111111 invoke [2]\",\n \"Program 11111111111111111111111111111111 success\",\n \"Program 11111111111111111111111111111111 invoke [2]\",\n \"Program 11111111111111111111111111111111 success\",\n \"Program 11111111111111111111111111111111 invoke [2]\",\n \"Program 11111111111111111111111111111111 success\",\n \"Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]\",\n \"Program log: Instruction: InitializeAccount\",\n \"Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3272 of 171619 compute units\",\n \"Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success\",\n \"Program 12YKFL4mnZz6CBEGePrf293mEzueQM3h8VLPUJsKpGs9 consumed 32387 of 200000 compute units\",\n \"Program 12YKFL4mnZz6CBEGePrf293mEzueQM3h8VLPUJsKpGs9 success\",\n \"Program 12YKFL4mnZz6CBEGePrf293mEzueQM3h8VLPUJsKpGs9 invoke [1]\",\n \"Program log: Process instruction. Program id: 12YKFL4mnZz6CBEGePrf293mEzueQM3h8VLPUJsKpGs9, 20 accounts, data: [4, 160, 134, 1, 0, 0, 0, 0, 0, 83, 148, 12, 0, 0, 0, 0, 0, 70, 86, 10, 0, 0, 0, 0, 0]\",\n \"Program log: Instruction: SplSwapTransitive { amount_in: 100000, transit_minimum_amount: 824403, minimum_amount_out: 677446 }\",\n \"Program log: Invoke SPL swap to transit\",\n \"Program 9W959DqEETiGZocYWCQPaJ6sBmUzgfxXfqGeTEdp3aQP invoke [2]\",\n \"Program log: Instruction: Swap\",\n \"Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [3]\",\n \"Program log: Instruction: Transfer\",\n \"Program log: Error: insufficient funds\",\n \"Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2135 of 150701 compute units\",\n \"Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: custom program error: 0x1\",\n \"Program 9W959DqEETiGZocYWCQPaJ6sBmUzgfxXfqGeTEdp3aQP consumed 20050 of 168616 compute units\",\n \"Program 9W959DqEETiGZocYWCQPaJ6sBmUzgfxXfqGeTEdp3aQP failed: custom program error: 0x1\",\n \"Program 12YKFL4mnZz6CBEGePrf293mEzueQM3h8VLPUJsKpGs9 consumed 51434 of 200000 compute units\",\n \"Program 12YKFL4mnZz6CBEGePrf293mEzueQM3h8VLPUJsKpGs9 failed: custom program error: 0x1\",\n ],\n ),\n accounts: None,\n },\n ),\n}"]},"message":"Solana RPC client error: RPC response error -32002: Transaction simulation failed: Error processing Instruction 3: custom program error: 0x1 [37 log messages]"}"#
}
Expand Down
Loading

0 comments on commit a761fd6

Please sign in to comment.