This repository was archived by the owner on Feb 3, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1263,6 +1263,46 @@ impl<S: MutinyStorage> NodeManager<S> {
12631263 Ok ( activity)
12641264 }
12651265
1266+ /// Returns all the on-chain and lightning activity for a given label
1267+ pub async fn get_label_activity (
1268+ & self ,
1269+ label : & String ,
1270+ ) -> Result < Vec < ActivityItem > , MutinyError > {
1271+ let Some ( label_item) = self . get_label ( label) ? else {
1272+ return Ok ( Vec :: new ( ) ) ;
1273+ } ;
1274+
1275+ let mut activity = vec ! [ ] ;
1276+ for inv in label_item. invoices . iter ( ) {
1277+ let ln = self . get_invoice ( inv) . await ?;
1278+ // Only show paid and in-flight invoices
1279+ match ln. status {
1280+ HTLCStatus :: Succeeded | HTLCStatus :: InFlight => {
1281+ activity. push ( ActivityItem :: Lightning ( Box :: new ( ln) ) ) ;
1282+ }
1283+ HTLCStatus :: Pending | HTLCStatus :: Failed => { }
1284+ }
1285+ }
1286+ let onchain = self
1287+ . list_onchain ( )
1288+ . map_err ( |e| {
1289+ log_warn ! ( self . logger, "Failed to get bdk history: {e}" ) ;
1290+ e
1291+ } )
1292+ . unwrap_or_default ( ) ;
1293+
1294+ for on in onchain {
1295+ if on. labels . contains ( label) {
1296+ activity. push ( ActivityItem :: OnChain ( on) ) ;
1297+ }
1298+ }
1299+
1300+ // Newest first
1301+ activity. sort_by ( |a, b| b. cmp ( a) ) ;
1302+
1303+ Ok ( activity)
1304+ }
1305+
12661306 /// Adds labels to the TransactionDetails based on the address labels.
12671307 /// This will panic if the TransactionDetails does not have a transaction.
12681308 /// Make sure you flag `include_raw` when calling `list_transactions` to
Original file line number Diff line number Diff line change @@ -920,6 +920,35 @@ impl MutinyWallet {
920920 Ok ( JsValue :: from_serde ( & activity) ?)
921921 }
922922
923+ /// Returns all the on-chain and lightning activity for a given label
924+ #[ wasm_bindgen]
925+ pub async fn get_label_activity (
926+ & self ,
927+ label : String ,
928+ ) -> Result < JsValue /* Vec<ActivityItem> */ , MutinyJsError > {
929+ // get activity from the node manager
930+ let activity = self . inner . node_manager . get_label_activity ( & label) . await ?;
931+ let mut activity: Vec < ActivityItem > = activity. into_iter ( ) . map ( |a| a. into ( ) ) . collect ( ) ;
932+
933+ // add contact to the activity item if it is one
934+ let Some ( contact) = self . inner . node_manager . get_contact ( & label) ? else {
935+ return Ok ( JsValue :: from_serde ( & activity) ?) ;
936+ } ;
937+
938+ for a in activity. iter_mut ( ) {
939+ // find labels that have a contact and add them to the item
940+ for a_label in a. labels . iter ( ) {
941+ if label == * a_label {
942+ a. contacts . push ( Contact :: from ( contact. clone ( ) ) ) ;
943+ }
944+ }
945+ // remove labels that have the contact to prevent duplicates
946+ a. labels . retain ( |l| l != & label) ;
947+ }
948+
949+ Ok ( JsValue :: from_serde ( & activity) ?)
950+ }
951+
923952 /// Initiates a redshift
924953 #[ wasm_bindgen]
925954 pub async fn init_redshift (
You can’t perform that action at this time.
0 commit comments