Skip to content

Commit

Permalink
Completing getting and address from a file
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenperera committed Oct 27, 2024
1 parent ae7e095 commit 19892ae
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
19 changes: 14 additions & 5 deletions ios/Cove/CoveApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,20 @@ struct CoveApp: App {
}

func handleAddress(_ addressWithNetwork: AddressWithNetwork) {
// TODO:
// check if network is current network, if not display error
// if current route is a wallet, pop up a sheet that shows the address, shows mine or external and has link to "Send"
let _ = addressWithNetwork
()
let currentNetwork = Database().globalConfig().selectedNetwork()
let address = addressWithNetwork.address()
let network = addressWithNetwork.network()
let selectedWallet = Database().globalConfig().selectedWallet()

if selectedWallet == nil {
return alert = PresentableItem(AlertState.noWalletSelected(address))
}

if network != currentNetwork {
return alert = PresentableItem(AlertState.addressWrongNetwork(address: address, network: network, currentNetwork: currentNetwork))
}

return alert = PresentableItem(.foundAddress(address))
}

func handleFileOpen(_ url: URL) {
Expand Down
24 changes: 23 additions & 1 deletion rust/ios/Cove/Cove.swift
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,11 @@ public func FfiConverterTypeAddressInfo_lower(_ value: AddressInfo) -> UnsafeMut
return FfiConverterTypeAddressInfo.lower(value)
}

public protocol AddressWithNetworkProtocol: AnyObject {}
public protocol AddressWithNetworkProtocol: AnyObject {
func address() -> Address

func network() -> Network
}

open class AddressWithNetwork:
AddressWithNetworkProtocol
Expand Down Expand Up @@ -802,6 +806,18 @@ open class AddressWithNetwork:

try! rustCall { uniffi_cove_fn_free_addresswithnetwork(pointer, $0) }
}

open func address() -> Address {
return try! FfiConverterTypeAddress.lift(try! rustCall {
uniffi_cove_fn_method_addresswithnetwork_address(self.uniffiClonePointer(), $0)
})
}

open func network() -> Network {
return try! FfiConverterTypeNetwork.lift(try! rustCall {
uniffi_cove_fn_method_addresswithnetwork_network(self.uniffiClonePointer(), $0)
})
}
}

public struct FfiConverterTypeAddressWithNetwork: FfiConverter {
Expand Down Expand Up @@ -13701,6 +13717,12 @@ private var initializationResult: InitializationResult = {
if uniffi_cove_checksum_method_addressinfo_index() != 45529 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_cove_checksum_method_addresswithnetwork_address() != 33477 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_cove_checksum_method_addresswithnetwork_network() != 64145 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_cove_checksum_method_amount_as_btc() != 7531 {
return InitializationResult.apiChecksumMismatch
}
Expand Down
11 changes: 11 additions & 0 deletions rust/src/wallet/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ mod ffi {

use super::*;

#[uniffi::export]
impl AddressWithNetwork {
fn address(&self) -> Address {
self.address.clone().into()
}

fn network(&self) -> Network {
self.network
}
}

#[uniffi::export]
impl Address {
#[uniffi::constructor(name = "preview_new")]
Expand Down

0 comments on commit 19892ae

Please sign in to comment.