Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 1 addition & 37 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/attaswift/BigInt.git", .upToNextMinor(from: "5.4.0")),
.package(url: "https://github.com/marmelroy/PhoneNumberKit", from: "4.0.0"),
.package(url: "https://github.com/p2p-org/solana-swift", from: "5.0.0"),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
Expand All @@ -26,7 +25,6 @@ let package = Package(
dependencies: [
"BigInt",
"PhoneNumberKit",
.product(name: "SolanaSwift", package: "solana-swift"),
],
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ extension EVMTransaction {
if let gasPrice = toHexString(gasPrice) { tx["gasPrice"] = gasPrice }
if let maxPriorityFeePerGas = toHexString(maxPriorityFeePerGas) { tx["maxPriorityFeePerGas"] = maxPriorityFeePerGas }
if let maxFeePerGas = toHexString(maxFeePerGas) { tx["maxFeePerGas"] = maxFeePerGas }
if let nonce = toHexString(nonce) { tx["nonce"] = nonce }
// Note: Nonce is intentionally excluded to let MetaMask handle it automatically
// This prevents "nonce too low" errors when the external wallet has transaction history
if let type { tx["type"] = "0x" + String(type, radix: 16) }
if let chainId = toHexString(chainId) { tx["chainId"] = chainId }

Expand Down
67 changes: 67 additions & 0 deletions Sources/ParaSwift/Core/JSONValue.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import Foundation

/// Helper type to encode arbitrary JSON values
struct JSONValue: Encodable {
let value: Any

init(_ value: Any) {
self.value = value
}

func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()

if let dict = value as? [String: Any] {
try container.encode(JSONDictionary(dict))
} else if let array = value as? [Any] {
try container.encode(array.map { JSONValue($0) })
} else if let string = value as? String {
try container.encode(string)
} else if let bool = value as? Bool {
try container.encode(bool)
} else if let int = value as? Int {
try container.encode(int)
} else if let double = value as? Double {
try container.encode(double)
} else if value is NSNull {
try container.encodeNil()
} else {
throw EncodingError.invalidValue(value, EncodingError.Context(
codingPath: container.codingPath,
debugDescription: "Cannot encode value of type \(type(of: value))"
))
}
}
}

struct JSONDictionary: Encodable {
let dictionary: [String: Any]

init(_ dictionary: [String: Any]) {
self.dictionary = dictionary
}

func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: DynamicCodingKey.self)

for (key, value) in dictionary {
let codingKey = DynamicCodingKey(stringValue: key)!
try container.encode(JSONValue(value), forKey: codingKey)
}
}
}

struct DynamicCodingKey: CodingKey {
var stringValue: String
var intValue: Int?

init?(stringValue: String) {
self.stringValue = stringValue
self.intValue = nil
}

init?(intValue: Int) {
self.stringValue = String(intValue)
self.intValue = intValue
}
}
Loading
Loading