@@ -213,6 +213,13 @@ type Premium struct {
213213 PremiumRatePpm int64
214214}
215215
216+ type PremiumCard struct {
217+ Premium
218+ Title string
219+ Description string
220+ FormID string
221+ }
222+
216223func peerHandler (w http.ResponseWriter , r * http.Request ) {
217224 keys , ok := r .URL .Query ()["id" ]
218225 if ! ok || len (keys [0 ]) < 1 {
@@ -325,7 +332,7 @@ func peerHandler(w http.ResponseWriter, r *http.Request) {
325332
326333 btcBalance := ln .ConfirmedWalletBalance (cl )
327334
328- var globalPremium , peerPremium []Premium
335+ var peerPremium []Premium
329336
330337 psPeer := true
331338 if peer == nil {
@@ -353,13 +360,6 @@ func peerHandler(w http.ResponseWriter, r *http.Request) {
353360
354361 for _ , asset := range []peerswaprpc.AssetType {peerswaprpc .AssetType_BTC , peerswaprpc .AssetType_LBTC } {
355362 for _ , operation := range []peerswaprpc.OperationType {peerswaprpc .OperationType_SWAP_IN , peerswaprpc .OperationType_SWAP_OUT } {
356- globalRate , _ := ps .GetGlobalPremiumRate (client , asset , operation )
357- globalPremium = append (globalPremium , Premium {
358- Asset : int32 (asset .Number ()),
359- Operation : int32 (operation .Number ()),
360- PremiumRatePpm : globalRate .PremiumRatePpm ,
361- })
362-
363363 peerRate , _ := ps .GetPremiumRate (client , peer .NodeId , asset , operation )
364364 peerPremium = append (peerPremium , Premium {
365365 Asset : int32 (asset .Number ()),
@@ -640,7 +640,6 @@ func peerHandler(w http.ResponseWriter, r *http.Request) {
640640 OPENING_TX_SIZE_BTC int64
641641 OPENING_TX_SIZE_LBTC int64
642642 OPENING_TX_SIZE_LBTC_DISCOUNTED int64
643- GlobalPremium []Premium
644643 PeerPremium []Premium
645644 }
646645
@@ -702,14 +701,108 @@ func peerHandler(w http.ResponseWriter, r *http.Request) {
702701 OPENING_TX_SIZE_BTC : OPENING_TX_SIZE_BTC ,
703702 OPENING_TX_SIZE_LBTC : OPENING_TX_SIZE_LBTC ,
704703 OPENING_TX_SIZE_LBTC_DISCOUNTED : OPENING_TX_SIZE_LBTC_DISCOUNTED ,
705- GlobalPremium : globalPremium ,
706704 PeerPremium : peerPremium ,
707705 }
708706
709707 // executing template named "peer"
710708 executeTemplate (w , "peer" , data )
711709}
712710
711+ func globalPremiumsHandler (w http.ResponseWriter , r * http.Request ) {
712+ errorMessage := ""
713+ keys , ok := r .URL .Query ()["err" ]
714+ if ok && len (keys [0 ]) > 0 {
715+ errorMessage = keys [0 ]
716+ }
717+
718+ popupMessage := ""
719+ keys , ok = r .URL .Query ()["msg" ]
720+ if ok && len (keys [0 ]) > 0 {
721+ popupMessage = keys [0 ]
722+ }
723+
724+ client , cleanup , err := ps .GetClient (config .Config .RpcHost )
725+ if err != nil {
726+ redirectWithError (w , r , "/config?" , err )
727+ return
728+ }
729+ defer cleanup ()
730+
731+ combos := []struct {
732+ asset peerswaprpc.AssetType
733+ operation peerswaprpc.OperationType
734+ title string
735+ description string
736+ }{
737+ {
738+ asset : peerswaprpc .AssetType_BTC ,
739+ operation : peerswaprpc .OperationType_SWAP_IN ,
740+ title : "Bitcoin → Lightning" ,
741+ description : "Premium applied when swapping on-chain bitcoin into Lightning." ,
742+ },
743+ {
744+ asset : peerswaprpc .AssetType_BTC ,
745+ operation : peerswaprpc .OperationType_SWAP_OUT ,
746+ title : "Lightning → Bitcoin" ,
747+ description : "Premium applied when sending bitcoin on-chain using Lightning liquidity." ,
748+ },
749+ {
750+ asset : peerswaprpc .AssetType_LBTC ,
751+ operation : peerswaprpc .OperationType_SWAP_IN ,
752+ title : "Liquid → Lightning" ,
753+ description : "Premium applied when converting Liquid bitcoin into Lightning." ,
754+ },
755+ {
756+ asset : peerswaprpc .AssetType_LBTC ,
757+ operation : peerswaprpc .OperationType_SWAP_OUT ,
758+ title : "Lightning → Liquid" ,
759+ description : "Premium applied when sending swaps out to Liquid bitcoin." ,
760+ },
761+ }
762+
763+ premiums := make ([]PremiumCard , 0 , len (combos ))
764+ for i , combo := range combos {
765+ rate , err := ps .GetGlobalPremiumRate (client , combo .asset , combo .operation )
766+ ppm := int64 (0 )
767+ if err != nil {
768+ log .Printf ("GetGlobalPremiumRate(%s,%s): %v" , combo .asset .String (), combo .operation .String (), err )
769+ } else if rate != nil {
770+ ppm = rate .PremiumRatePpm
771+ }
772+
773+ premiums = append (premiums , PremiumCard {
774+ Premium : Premium {
775+ Asset : int32 (combo .asset .Number ()),
776+ Operation : int32 (combo .operation .Number ()),
777+ PremiumRatePpm : ppm ,
778+ },
779+ Title : combo .title ,
780+ Description : combo .description ,
781+ FormID : fmt .Sprintf ("premium_%d" , i ),
782+ })
783+ }
784+
785+ type Page struct {
786+ Authenticated bool
787+ ErrorMessage string
788+ PopUpMessage string
789+ ColorScheme string
790+ MempoolFeeRate float64
791+ Premiums []PremiumCard
792+ }
793+
794+ data := Page {
795+ Authenticated : config .Config .SecureConnection && config .Config .Password != "" ,
796+ ErrorMessage : errorMessage ,
797+ PopUpMessage : popupMessage ,
798+ ColorScheme : config .Config .ColorScheme ,
799+ MempoolFeeRate : mempoolFeeRate ,
800+ Premiums : premiums ,
801+ }
802+
803+ executeTemplate (w , "premiums" , data )
804+ }
805+
713806func bitcoinHandler (w http.ResponseWriter , r * http.Request ) {
714807 //check for error message to display
715808 errorMessage := ""
0 commit comments