Skip to content

Commit

Permalink
simplestore: pass lnpc config and fix small bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
miki authored and miki-totefu committed Aug 16, 2023
1 parent 052baae commit 57c8d48
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 23 deletions.
15 changes: 8 additions & 7 deletions brclient/appstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3589,13 +3589,14 @@ func newAppState(sendMsg func(tea.Msg), lndLogLines *sloglinesbuffer.Buffer,
}

scfg := simplestore.Config{
Root: path,
Log: logBknd.logger("SSTR"),
LiveReload: true, // FIXME: parametrize
Client: c,
PayType: simplestore.PayType(args.SimpleStorePayType),
Account: args.SimpleStoreAccount,
ShipCharge: args.SimpleStoreShipCharge,
Root: path,
Log: logBknd.logger("SSTR"),
LiveReload: true, // FIXME: parametrize
Client: c,
PayType: simplestore.PayType(args.SimpleStorePayType),
Account: args.SimpleStoreAccount,
ShipCharge: args.SimpleStoreShipCharge,
LNPayClient: lnPC,

ExchangeRateProvider: func() float64 {
dcrPrice, _ := as.rates.Get()
Expand Down
5 changes: 1 addition & 4 deletions brclient/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ const (
)

func (sspt simpleStorePayType) isValid() bool {
// NOTE: ssPayTypeLN is disabled here because brclient does not
// wrap long lines that do not contain a wrapping character,
// which make it impossible for users to pay for such payments.
return (sspt == ssPayTypeNone) || /*(sspt == ssPayTypeLN) ||*/
return (sspt == ssPayTypeNone) || (sspt == ssPayTypeLN) ||
(sspt == ssPayTypeOnChain)
}

Expand Down
2 changes: 1 addition & 1 deletion client/resources/simplestore/contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type addToCartContext struct {
}

type orderContext struct {
Order Order
Order
}

type ordersContext struct {
Expand Down
10 changes: 9 additions & 1 deletion client/resources/simplestore/simplestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type PayType string

const (
PayTypeOnChain PayType = "onchain"
PayTypeLN PayType = "LN"
PayTypeLN PayType = "ln"
)

// Config holds the configuration for a simple store.
Expand All @@ -52,6 +52,7 @@ type Config struct {
Account string
ShipCharge float64
Client *client.Client
LNPayClient *client.DcrlnPaymentClient

ExchangeRateProvider func() float64
}
Expand Down Expand Up @@ -84,6 +85,7 @@ func New(cfg Config) (*Store, error) {
root: cfg.Root,
products: make(map[string]*Product),
tmpl: template.New("*root"),
lnpc: cfg.LNPayClient,
}

if err := s.reloadStore(); err != nil {
Expand All @@ -103,6 +105,9 @@ func (s *Store) reloadStore() error {
return err
}
for _, filename := range filenames {
if filepath.Ext(filename) != ".tmpl" {
continue
}
rawBytes, err := os.ReadFile(filename)
if err != nil {
return err
Expand All @@ -127,6 +132,9 @@ func (s *Store) reloadStore() error {
}

for _, prodFile := range prodFiles {
if filepath.Ext(prodFile.Name()) != ".toml" {
continue
}
fname := filepath.Join(prodDir, prodFile.Name())
var prods productsFile
f, err := os.Open(fname)
Expand Down
18 changes: 10 additions & 8 deletions client/resources/simplestore/template/cart.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ Last Updated: {{.Updated.Format "2006-01-02 15:04:05" }}

---
## Place Order
{{$shipping := false}}
{{range .Items}}
{{if .Shipping}}
{{$shipping = true}}
{{break}}
{{end}}
{{- end}}
{{- $shipping := false -}}
{{- range .Items -}}
{{- if .Product.Shipping -}}
{{- $shipping = true -}}
{{- break -}}
{{- end -}}
{{- end -}}

{{if $shipping}}
{{- if $shipping}}
### Shipping Information
--form--
type="action" value="/placeOrder"
type="txtinput" label="Name" name="name"
Expand All @@ -26,6 +27,7 @@ type="txtinput" label="PostalCode" name="postalCode"
type="txtinput" label="Phone" name="phone"
type="submit" label="Place Order"
--/form--

{{else}}
[Place order](/placeOrder)
{{end}}
Expand Down
3 changes: 2 additions & 1 deletion client/resources/simplestore/template/order.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Order Date: {{.PlacedTS}}
Order Status: {{.Status}}
Exchange Rate: {{.ExchangeRate}}

{{if .ShipAddr ne nil}}
{{if .ShipAddr }}
Shipping Address:
{{.ShipAddr.Name}}
{{.ShipAddr.Address}}
Expand Down Expand Up @@ -35,3 +35,4 @@ type="txtinput" label="New comment" name="comment" value=""
type="submit" label="Add Comment"
--/form--

[Back to Orders](/orders)
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ A longish product description. Features:
- Three
"""
tags = ["othertag"]
price = 229.99
price = 0.99


0 comments on commit 57c8d48

Please sign in to comment.