Skip to content

Commit

Permalink
fix(collectibles): various ui fixes (#3726)
Browse files Browse the repository at this point in the history
Description
---
Various UI fixes:
* Refresh Accounts list when adding a new asset
* Add metadata to dashboard and account view
* Add Star/Favourite button to account details page
* Automatically create a receive address on asset_wallet_create
* Remove build folder from source control
  • Loading branch information
stringhandler authored Jan 20, 2022
1 parent e5173b7 commit 1cc51a9
Show file tree
Hide file tree
Showing 31 changed files with 216 additions and 254 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
const ASSET_METADATA_TEMPLATE_ID: u32 = 1;
if asset.template_ids_implemented.contains(&ASSET_METADATA_TEMPLATE_ID) {
// TODO: move to a better location, or better yet, have the grpc caller split the metadata
let m = String::from_utf8(output.features.metadata.clone()).unwrap();
let m = String::from_utf8(Vec::from(&output.features.metadata[1..])).unwrap();
let mut m = m
.as_str()
.split('|')
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_collectibles/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ rand = "0.8"
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tonic = "0.6.2"
tauri = { version = "1.0.0-beta.8" }
tauri = { version = "1.0.0-beta.8", features = ["api-all"] }
diesel = { version = "1.4.8", features = ["sqlite"] }
diesel_migrations = "1.4.0"
thiserror = "1.0.30"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ use prost::Message;
use tari_common_types::types::PublicKey;
use tari_dan_common_types::proto::tips::tip002;
use tari_utilities::{hex::Hex, ByteArray};
use tauri::Manager;
use uuid::Uuid;

#[tauri::command]
pub(crate) async fn asset_wallets_create(
asset_public_key: String,
state: tauri::State<'_, ConcurrentAppState>,
app: tauri::AppHandle,
) -> Result<(), Status> {
let wallet_id = state
.current_wallet_id()
Expand Down Expand Up @@ -96,7 +98,21 @@ pub(crate) async fn asset_wallets_create(
wallet_id,
};
db.asset_wallets().insert(&new_asset_wallet, &tx)?;
let (key_manager_path, _, address_public_key) = state
.key_manager()
.await
.generate_asset_address(wallet_id, &asset_public_key, None, &tx)
.map_err(|e| Status::internal(format!("could not generate address key: {}", e)))?;
let address = AddressRow {
id: Uuid::new_v4(),
asset_wallet_id: new_asset_wallet.id,
name: None,
public_key: address_public_key,
key_manager_path,
};
db.addresses().insert(&address, &tx)?;
tx.commit()?;
app.emit_all("asset_wallets::updated", ()).unwrap();
Ok(())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,52 @@ pub(crate) async fn assets_list_owned(
)
}

// TODO: remove and use better serializer
#[derive(Debug)]
struct AssetMetadata {
name: String,
description: String,
image: String,
}

trait AssetMetadataDeserializer {
fn deserialize(&self, metadata: &[u8]) -> AssetMetadata;
}
trait AssetMetadataSerializer {
fn serialize(&self, model: &AssetMetadata) -> Vec<u8>;
}

struct V1AssetMetadataSerializer {}

impl AssetMetadataDeserializer for V1AssetMetadataSerializer {
fn deserialize(&self, metadata: &[u8]) -> AssetMetadata {
let m = String::from_utf8(Vec::from(metadata)).unwrap();
let mut m = m
.as_str()
.split('|')
.map(|s| s.to_string())
.collect::<Vec<String>>()
.into_iter();
let name = m.next();
let description = m.next();
let image = m.next();

AssetMetadata {
name: name.unwrap_or_else(|| "".to_string()),
description: description.unwrap_or_else(|| "".to_string()),
image: image.unwrap_or_else(|| "".to_string()),
}
}
}

impl AssetMetadataSerializer for V1AssetMetadataSerializer {
fn serialize(&self, model: &AssetMetadata) -> Vec<u8> {
let str = format!("{}|{}|{}", model.name, model.description, model.image);

str.into_bytes()
}
}

#[tauri::command]
pub(crate) async fn assets_list_registered_assets(
offset: u64,
Expand All @@ -157,17 +203,28 @@ pub(crate) async fn assets_list_registered_assets(
) -> Result<Vec<RegisteredAssetInfo>, Status> {
let mut client = state.connect_base_node_client().await?;
let assets = client.list_registered_assets(offset, count).await?;
let serializer = V1AssetMetadataSerializer {};
assets
.into_iter()
.map(|asset| {
Ok(RegisteredAssetInfo {
owner_commitment: Commitment::from_bytes(&asset.owner_commitment).ok(),
asset_public_key: RistrettoPublicKey::from_bytes(&asset.asset_public_key).ok(),
unique_id: asset.unique_id,
mined_height: asset.mined_height,
mined_in_block: asset.mined_in_block,
features: asset.features.map(|f| f.into()).unwrap(),
})
.filter_map(|asset| {
if let Some(ref features) = asset.features {
let metadata = serializer.deserialize(&features.metadata[1..]);

// TODO: Find a better way of reading the metadata
Some(Ok(RegisteredAssetInfo {
owner_commitment: Commitment::from_bytes(&asset.owner_commitment).ok(),
asset_public_key: RistrettoPublicKey::from_bytes(&asset.asset_public_key).ok(),
unique_id: asset.unique_id,
mined_height: asset.mined_height,
mined_in_block: asset.mined_in_block,
features: features.clone().into(),
name: metadata.name.clone(),
description: Some(metadata.description.clone()),
image: Some(metadata.image),
}))
} else {
None
}
})
.collect()
}
Expand Down Expand Up @@ -204,6 +261,8 @@ pub(crate) async fn assets_get_registration(

dbg!(&asset);
let features = asset.features.unwrap();
let serializer = V1AssetMetadataSerializer {};
let metadata = serializer.deserialize(&features.metadata[1..]);

Ok(RegisteredAssetInfo {
owner_commitment: Commitment::from_bytes(&asset.owner_commitment).ok(),
Expand All @@ -212,5 +271,8 @@ pub(crate) async fn assets_get_registration(
mined_height: asset.mined_height,
mined_in_block: asset.mined_in_block,
features: features.into(),
name: metadata.name.clone(),
description: Some(metadata.description.clone()),
image: Some(metadata.image),
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ pub struct RegisteredAssetInfo {
pub mined_height: u64,
pub mined_in_block: BlockHash,
pub features: OutputFeatures,
pub name: String,
pub description: Option<String>,
pub image: Option<String>,
}
20 changes: 17 additions & 3 deletions applications/tari_collectibles/src-tauri/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use crate::{error::CollectiblesError, storage::StorageError};
use diesel::result::Error;
use prost::{DecodeError, EncodeError};
use serde::{Deserialize, Serialize};
use tari_utilities::hex::HexError;
Expand Down Expand Up @@ -69,9 +70,22 @@ impl Status {

impl From<StorageError> for Status {
fn from(source: StorageError) -> Self {
Self::Internal {
code: 501,
message: format!("Internal storage error:{}", source),
match source {
StorageError::DieselError { source } => match source {
Error::NotFound => Self::NotFound {
code: 404,
message: format!("Not found:{}", source),
entity: "Unknown".to_string(),
},
_ => Self::Internal {
code: 502,
message: format!("Internal diesel storage error:{}", source),
},
},
_ => Self::Internal {
code: 501,
message: format!("Internal storage error:{}", source),
},
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions applications/tari_collectibles/web-app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

build
Empty file.
22 changes: 0 additions & 22 deletions applications/tari_collectibles/web-app/build/asset-manifest.json

This file was deleted.

Binary file not shown.
1 change: 0 additions & 1 deletion applications/tari_collectibles/web-app/build/index.html

This file was deleted.

Binary file not shown.
Binary file not shown.
25 changes: 0 additions & 25 deletions applications/tari_collectibles/web-app/build/manifest.json

This file was deleted.

50 changes: 0 additions & 50 deletions applications/tari_collectibles/web-app/build/proto/tip002.proto

This file was deleted.

3 changes: 0 additions & 3 deletions applications/tari_collectibles/web-app/build/robots.txt

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 1cc51a9

Please sign in to comment.