github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/chat/wallet/decorate.go (about) 1 package wallet 2 3 import ( 4 "context" 5 6 "github.com/keybase/client/go/chat/utils" 7 "github.com/keybase/client/go/protocol/chat1" 8 ) 9 10 func DecorateWithPayments(ctx context.Context, body string, payments []chat1.TextPayment) string { 11 var added int 12 seen := make(map[string]struct{}) 13 paymentMap := make(map[string]chat1.TextPayment) 14 for _, p := range payments { 15 paymentMap[p.PaymentText] = p 16 } 17 offset := 0 18 parsed := FindChatTxCandidates(body) 19 for _, p := range parsed { 20 payment, ok := paymentMap[p.Full] 21 if !ok { 22 continue 23 } 24 if _, ok := seen[p.Full]; ok { 25 continue 26 } 27 seen[p.Full] = struct{}{} 28 body, added = utils.DecorateBody(ctx, body, p.Position[0]+offset, p.Position[1]-p.Position[0], 29 chat1.NewUITextDecorationWithPayment(payment)) 30 offset += added 31 } 32 return body 33 }