-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ABW-3712] Allow to hide/unhide resources on Profile (#199)
* Changes to AppPreferences with commented tests * WIP * get all hidden resources * fix tests * WIP * WIP * bump version * add flag to Security * uncomment test * WIP * fixes * fix iOS Tests * Add bool type macro and use it for Security flags * move macro to its own file * missing tests and docs * Hidden resources kt extesions (#200) * Add kt extensions for resource preferences * Remove packaging option * Update asset preferences kt extensions * revert JSON changes --------- Co-authored-by: sergiupuhalschi-rdx <164897324+sergiupuhalschi-rdx@users.noreply.github.com>
- Loading branch information
1 parent
cde0859
commit 5903204
Showing
29 changed files
with
1,003 additions
and
60 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "sargon" | ||
version = "1.1.5" | ||
version = "1.1.6" | ||
edition = "2021" | ||
build = "build.rs" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
apple/Sources/Sargon/Extensions/Methods/Profile/AssetPreference+Wrap+Functions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Matias Bzurovski on 13/8/24. | ||
// | ||
|
||
import Foundation | ||
import SargonUniFFI | ||
|
||
extension [AssetPreference] { | ||
public var hiddenAssets: [AssetAddress] { | ||
assetPreferencesGetHiddenAssets(assetPreferences: self) | ||
} | ||
|
||
public mutating func hideAsset(asset: AssetAddress) { | ||
self = assetPreferencesHideAsset(assetPreferences: self, asset: asset) | ||
} | ||
|
||
public mutating func unhideAsset(asset: AssetAddress) { | ||
self = assetPreferencesUnhideAsset(assetPreferences: self, asset: asset) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
apple/Sources/Sargon/Extensions/SampleValues/Profile/AssetPreferences+SampleValues.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Matias Bzurovski on 13/8/24. | ||
// | ||
|
||
import Foundation | ||
import SargonUniFFI | ||
|
||
#if DEBUG | ||
extension [AssetPreference] { | ||
public static let sample: Self = newAssetPreferencesSample() | ||
public static let sampleOther: Self = newAssetPreferencesSampleOther() | ||
} | ||
#endif // DEBUG |
13 changes: 13 additions & 0 deletions
13
apple/Sources/Sargon/Extensions/Swiftified/Profile/AssetPreference+Swiftified.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Matias Bzurovski on 13/8/24. | ||
// | ||
|
||
import Foundation | ||
import SargonUniFFI | ||
|
||
public typealias AssetPreferences = [AssetPreference] | ||
|
||
//extension AssetPreferences: SargonModel {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Matias Bzurovski on 13/8/24. | ||
// | ||
|
||
import CustomDump | ||
import Foundation | ||
import Sargon | ||
import SargonUniFFI | ||
import XCTest | ||
|
||
final class AssetPreferencesTests: TestCase { | ||
func test_hidden_resources() { | ||
var sut = AssetPreferences() | ||
XCTAssertTrue(sut.hiddenAssets.isEmpty) | ||
|
||
// Hide assets | ||
sut.hideAsset(asset: .fungible(.sample)) | ||
sut.hideAsset(asset: .nonFungible(.sample)) | ||
sut.hideAsset(asset: .fungible(.sampleOther)) | ||
|
||
XCTAssertEqual(sut.hiddenAssets, [.fungible(.sample), .nonFungible(.sample), .fungible(.sampleOther)]) | ||
|
||
// Unhide assets | ||
sut.unhideAsset(asset: .fungible(.sampleOther)) | ||
sut.unhideAsset(asset: .nonFungible(.sample)) | ||
XCTAssertEqual(sut.hiddenAssets, [.fungible(.sample)]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
20 changes: 10 additions & 10 deletions
20
fixtures/vector/profile_encrypted_by_password_of_babylon.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
jvm/sargon-android/src/main/java/com/radixdlt/sargon/extensions/AssetPreferences.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.radixdlt.sargon.extensions | ||
|
||
import com.radixdlt.sargon.AssetAddress | ||
import com.radixdlt.sargon.AssetPreference | ||
import com.radixdlt.sargon.annotation.KoverIgnore | ||
import com.radixdlt.sargon.assetPreferencesGetHiddenAssets | ||
import com.radixdlt.sargon.assetPreferencesHideAsset | ||
import com.radixdlt.sargon.assetPreferencesUnhideAsset | ||
|
||
class AssetPreferences private constructor( | ||
private val array: IdentifiedArray<AssetAddress, AssetPreference> | ||
) : IdentifiedArray<AssetAddress, AssetPreference> by array { | ||
|
||
constructor(assetPreferences: List<AssetPreference>) : this( | ||
IdentifiedArrayImpl( | ||
elements = assetPreferences, | ||
identifier = { it.assetAddress } | ||
) | ||
) | ||
|
||
constructor(vararg assetPreference: AssetPreference) : this(assetPreferences = assetPreference.asList()) | ||
|
||
@KoverIgnore // False positive in javaClass check | ||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (javaClass != other?.javaClass) return false | ||
|
||
other as AssetPreferences | ||
|
||
return array == other.array | ||
} | ||
|
||
override fun hashCode(): Int { | ||
return array.hashCode() | ||
} | ||
|
||
@KoverIgnore | ||
override fun toString(): String { | ||
return "AssetPreferences(array=$array)" | ||
} | ||
|
||
companion object | ||
|
||
} | ||
|
||
fun List<AssetPreference>.asIdentifiable() = AssetPreferences(assetPreferences = this) | ||
|
||
val AssetPreferences.hiddenAssets | ||
get() = assetPreferencesGetHiddenAssets(asList()) | ||
|
||
fun AssetPreferences.hideAsset(assetAddress: AssetAddress) = assetPreferencesHideAsset(asList(), assetAddress).asIdentifiable() | ||
|
||
fun AssetPreferences.unhideAsset(assetAddress: AssetAddress) = assetPreferencesUnhideAsset(asList(), assetAddress).asIdentifiable() |
16 changes: 16 additions & 0 deletions
16
jvm/sargon-android/src/main/java/com/radixdlt/sargon/samples/AssetPreferencesSample.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.radixdlt.sargon.samples | ||
|
||
import com.radixdlt.sargon.annotation.UsesSampleValues | ||
import com.radixdlt.sargon.extensions.AssetPreferences | ||
import com.radixdlt.sargon.extensions.asIdentifiable | ||
import com.radixdlt.sargon.newAssetPreferencesSample | ||
import com.radixdlt.sargon.newAssetPreferencesSampleOther | ||
|
||
@UsesSampleValues | ||
val AssetPreferences.Companion.sample: Sample<AssetPreferences> | ||
get() = object : Sample<AssetPreferences> { | ||
|
||
override fun invoke(): AssetPreferences = newAssetPreferencesSample().asIdentifiable() | ||
|
||
override fun other(): AssetPreferences = newAssetPreferencesSampleOther().asIdentifiable() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
jvm/sargon-android/src/test/java/com/radixdlt/sargon/AssetPreferencesTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.radixdlt.sargon | ||
|
||
import com.radixdlt.sargon.extensions.AssetPreferences | ||
import com.radixdlt.sargon.extensions.hiddenAssets | ||
import com.radixdlt.sargon.extensions.hideAsset | ||
import com.radixdlt.sargon.extensions.unhideAsset | ||
import com.radixdlt.sargon.samples.Sample | ||
import com.radixdlt.sargon.samples.sample | ||
import com.radixdlt.sargon.samples.sampleMainnet | ||
import com.radixdlt.sargon.samples.sampleStokenet | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Assertions.assertTrue | ||
import org.junit.jupiter.api.Test | ||
|
||
class AssetPreferencesTest : SampleTestable<AssetPreferences> { | ||
|
||
override val samples: List<Sample<AssetPreferences>> | ||
get() = listOf(AssetPreferences.sample) | ||
|
||
@Test | ||
fun testHiddenAssets() { | ||
var sut = AssetPreferences() | ||
|
||
assertTrue(sut.hiddenAssets.isEmpty()) | ||
|
||
// Hide assets | ||
sut = sut.hideAsset(AssetAddress.Fungible(ResourceAddress.sampleMainnet())) | ||
.hideAsset(AssetAddress.Fungible(ResourceAddress.sampleStokenet())) | ||
.hideAsset(AssetAddress.NonFungible(NonFungibleGlobalId.sample())) | ||
.hideAsset(AssetAddress.PoolUnit(PoolAddress.sampleMainnet())) | ||
|
||
assertEquals( | ||
listOf( | ||
AssetAddress.Fungible(ResourceAddress.sampleMainnet()), | ||
AssetAddress.Fungible(ResourceAddress.sampleStokenet()), | ||
AssetAddress.NonFungible(NonFungibleGlobalId.sample()), | ||
AssetAddress.PoolUnit(PoolAddress.sampleMainnet()) | ||
), | ||
sut.hiddenAssets | ||
) | ||
|
||
// Unhide assets | ||
sut = sut.unhideAsset(AssetAddress.Fungible(ResourceAddress.sampleStokenet())) | ||
.unhideAsset(AssetAddress.NonFungible(NonFungibleGlobalId.sample())) | ||
|
||
assertEquals( | ||
listOf( | ||
AssetAddress.Fungible(ResourceAddress.sampleMainnet()), | ||
AssetAddress.PoolUnit(PoolAddress.sampleMainnet()) | ||
), | ||
sut.hiddenAssets | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
use crate::prelude::*; | ||
|
||
macro_rules! decl_bool_type { | ||
($name:ident, $default_value:expr) => { | ||
#[derive( | ||
Serialize, | ||
Deserialize, | ||
Debug, | ||
PartialEq, | ||
Eq, | ||
Clone, | ||
Hash, | ||
derive_more::Display, | ||
)] | ||
#[serde(transparent)] | ||
pub struct $name(pub bool); | ||
|
||
impl Default for $name { | ||
fn default() -> Self { | ||
$name($default_value) | ||
} | ||
} | ||
|
||
impl HasSampleValues for $name { | ||
fn sample() -> Self { | ||
$name($default_value) | ||
} | ||
|
||
fn sample_other() -> Self { | ||
$name(!$default_value) | ||
} | ||
} | ||
|
||
impl Deref for $name { | ||
type Target = bool; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
uniffi::custom_newtype!($name, bool); | ||
}; | ||
} | ||
|
||
pub(crate) use decl_bool_type; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
decl_bool_type!(ExampleTrue, true); | ||
decl_bool_type!(ExampleFalse, false); | ||
|
||
use crate::prelude::*; | ||
|
||
#[test] | ||
fn equality() { | ||
assert_eq!(ExampleTrue::sample(), ExampleTrue::sample()); | ||
assert_eq!(ExampleTrue::sample_other(), ExampleTrue::sample_other()); | ||
|
||
assert_eq!(ExampleFalse::sample(), ExampleFalse::sample()); | ||
assert_eq!(ExampleFalse::sample_other(), ExampleFalse::sample_other()); | ||
} | ||
|
||
#[test] | ||
fn inequality() { | ||
assert_ne!(ExampleTrue::sample(), ExampleTrue::sample_other()); | ||
|
||
assert_ne!(ExampleFalse::sample(), ExampleFalse::sample_other()); | ||
} | ||
|
||
#[test] | ||
fn default() { | ||
assert!(*ExampleTrue::default()); | ||
|
||
assert!(!*ExampleFalse::default()); | ||
} | ||
|
||
#[test] | ||
fn debug() { | ||
let str = "ExampleTrue(true)"; | ||
let sut = ExampleTrue::sample(); | ||
assert_eq!(format!("{:?}", sut), str); | ||
} | ||
|
||
#[test] | ||
fn modification() { | ||
let mut example_true = ExampleTrue::default(); | ||
assert!(*example_true); | ||
example_true.0 = false; | ||
assert!(!*example_true); | ||
|
||
let mut example_false = ExampleFalse::default(); | ||
assert!(!*example_false); | ||
example_false.0 = true; | ||
assert!(*example_false); | ||
} | ||
} |
Oops, something went wrong.