Skip to content

Commit

Permalink
bump wurbo to v0.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
DougAnderson444 committed Jun 23, 2024
1 parent b452083 commit c84bd93
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 154 deletions.
2 changes: 1 addition & 1 deletion crates/delano-wit-ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
wurbo = { version = "0.1.9" }
wurbo = { version = "0.4.1" }
base64ct = { version = "1.6.0", features = ["alloc"] }
chrono = "0.4.33"
ciborium = "0.2.2"
Expand Down
35 changes: 13 additions & 22 deletions crates/delano-wit-ui/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,12 @@ fn subscribe_to_topic(key: impl ToString) {
wurbo_in::emit(&message);
}

impl StructObject for State {
impl Object for State {
/// Remember to add match arms for any new fields.
fn get_field(&self, name: &str) -> Option<Value> {
fn get_value(self: &Arc<Self>, key: &Value) -> Option<Value> {
// TODO: Show issues/errors as error variant?
// if offer or proof have messages, show them?
match name {
match key.as_str()? {
"id" => Some(Value::from(rand_id())),
"loaded" => Some(Value::from(self.loaded.clone())),
"credential" => Some(Value::from(self.builder.clone())),
Expand All @@ -329,14 +329,10 @@ impl StructObject for State {
},
None => Some(Value::from("Click to generate a proof.")),
},
"history" => Some(Value::from_serializable(&self.history.clone())),
"history" => Some(Value::from_serialize(&self.history.clone())),
_ => None,
}
}
/// So that debug will show the values
fn static_fields(&self) -> Option<&'static [&'static str]> {
Some(&["id", "loaded", "credential", "offer", "proof"])
}
}

impl From<String> for State {
Expand Down Expand Up @@ -442,12 +438,11 @@ impl Loaded {
}
}

impl StructObject for Loaded {
/// Remember to add match arms for any new fields.
fn get_field(&self, name: &str) -> Option<Value> {
match name {
impl Object for Loaded {
fn get_value(self: &Arc<Self>, key: &Value) -> Option<Value> {
match key.as_str()? {
"id" => Some(Value::from(rand_id())),
"context" => match self {
"context" => match **self {
// Offer is the only Loaded context that can be edited
Self::Offer { .. } => {
// We do this so we get the exact name of the context, any changes
Expand All @@ -464,13 +459,13 @@ impl StructObject for Loaded {
}
_ => None,
},
"hints" => match self {
Self::Offer { hints, .. } => Some(Value::from(hints.clone())),
"hints" => match **self {
Self::Offer { ref hints, .. } => Some(Value::from(hints.clone())),
_ => None,
},
"preimages" => match self {
"preimages" => match **self {
Self::Proof(Provables::<AttributeKOV> {
selected_preimages: preimages,
selected_preimages: ref preimages,
..
}) => {
let de_preimages: Vec<Vec<AttributeKOV>> = preimages
Expand All @@ -494,15 +489,11 @@ impl StructObject for Loaded {
_ => None,
}
}
/// So that debug will show the values
fn static_fields(&self) -> Option<&'static [&'static str]> {
Some(&["context", "hints", "preimages", "verified"])
}
}

impl From<Loaded> for wurbo::prelude::Value {
fn from(loaded: Loaded) -> Self {
Value::from_struct_object(loaded)
Value::from_object(loaded)
}
}

Expand Down
38 changes: 13 additions & 25 deletions crates/delano-wit-ui/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,13 @@ impl Operator {
}
}

impl StructObject for Operator {
fn get_field(&self, name: &str) -> Option<Value> {
match name {
impl Object for Operator {
fn get_value(self: &Arc<Self>, key: &Value) -> Option<Value> {
match key.as_str()? {
"value" => Some(Value::from(self.value())),
_ => None,
}
}
/// So that debug will show the values
fn static_fields(&self) -> Option<&'static [&'static str]> {
Some(&["value"])
}
}

impl ToString for Operator {
Expand All @@ -74,7 +70,7 @@ impl TryFrom<String> for Operator {

impl From<Operator> for wurbo::prelude::Value {
fn from(operator: Operator) -> Self {
Self::from_struct_object(operator)
Self::from_object(operator)
}
}

Expand Down Expand Up @@ -152,20 +148,16 @@ impl AttributeKOV {
}
}

impl StructObject for AttributeKOV {
fn get_field(&self, name: &str) -> Option<Value> {
match name {
impl Object for AttributeKOV {
fn get_value(self: &Arc<Self>, key: &Value) -> Option<Value> {
match key.as_str()? {
"key" => Some(Value::from(self.key.deref().clone())),
"op" => Some(Value::from(self.op.get_field("value").unwrap())),
"op" => Some(Value::from(self.op.value())),
"value" => Some(Value::from(self.value.deref().clone())),
"selected" => Some(Value::from(self.selected)),
_ => None,
}
}
/// So that debug will show the values
fn static_fields(&self) -> Option<&'static [&'static str]> {
Some(&["key", "op", "value", "selected"])
}
}

impl ToString for AttributeKOV {
Expand All @@ -189,7 +181,7 @@ impl From<CredentialStruct> for Vec<Vec<AttributeKOV>> {

impl From<AttributeKOV> for wurbo::prelude::Value {
fn from(attribute: AttributeKOV) -> Self {
Self::from_struct_object(attribute)
Self::from_object(attribute)
}
}

Expand Down Expand Up @@ -230,18 +222,14 @@ impl Hint {
}
}

impl StructObject for Hint {
fn get_field(&self, name: &str) -> Option<Value> {
match name {
impl Object for Hint {
fn get_value(self: &Arc<Self>, key: &Value) -> Option<Value> {
match key.as_str()? {
"key" => Some(Value::from(self.key.deref().clone())),
"op" => Some(Value::from(self.op.clone())),
_ => None,
}
}
/// So that debug will show the values
fn static_fields(&self) -> Option<&'static [&'static str]> {
Some(&["key", "op"])
}
}

impl ToString for Hint {
Expand Down Expand Up @@ -281,6 +269,6 @@ impl From<Hint> for AttributeKOV {

impl From<Hint> for wurbo::prelude::Value {
fn from(hint: Hint) -> Self {
Self::from_struct_object(hint)
Self::from_object(hint)
}
}
Loading

0 comments on commit c84bd93

Please sign in to comment.