From e6d5aca0eb4fbb9de5cbea88722d81bab6ff6c05 Mon Sep 17 00:00:00 2001 From: Raphael Osaze Eyerin Date: Wed, 24 May 2023 23:29:18 +0100 Subject: [PATCH] [FIX] Assign Bounty and Null error caused by StringArray (#553) * fixed null error and assign tickets * changed to extractedPubKey * changed Property map function --- db/db.go | 5 +- db/structs.go | 145 +++++++++--------- .../app/src/people/utils/assignBounty.tsx | 4 +- .../summaries/wantedSummaries/invoice.tsx | 2 +- handlers/invoiceCron.go | 6 +- 5 files changed, 84 insertions(+), 78 deletions(-) diff --git a/db/db.go b/db/db.go index 065df3d2e..70b384bcf 100644 --- a/db/db.go +++ b/db/db.go @@ -11,6 +11,7 @@ import ( "time" "github.com/go-chi/chi" + "github.com/lib/pq" _ "github.com/lib/pq" "github.com/rs/xid" @@ -829,8 +830,10 @@ func (db database) CreateLnUser(lnKey string) (Person, error) { p.OwnerAlias = lnKey p.UniqueName, _ = PersonUniqueNameFromName(p.OwnerAlias) p.Created = &now - p.Tags = StringArray{} + p.Tags = pq.StringArray{} p.Uuid = xid.New().String() + p.Extras = make(map[string]interface{}) + p.GithubIssues = make(map[string]interface{}) db.db.Create(&p) } diff --git a/db/structs.go b/db/structs.go index c04a1f664..988bb4c08 100644 --- a/db/structs.go +++ b/db/structs.go @@ -14,66 +14,66 @@ import ( // Tribe struct type Tribe struct { - UUID string `json:"uuid"` - OwnerPubKey string `json:"owner_pubkey"` - OwnerAlias string `json:"owner_alias"` - GroupKey string `json:"group_key"` - Name string `json:"name"` - UniqueName string `json:"unique_name"` - Description string `json:"description"` - Tags StringArray `gorm:"type:text[]" json:"tags"` - Img string `json:"img"` - PriceToJoin int64 `json:"price_to_join"` - PricePerMessage int64 `json:"price_per_message"` - EscrowAmount int64 `json:"escrow_amount"` - EscrowMillis int64 `json:"escrow_millis"` - Created *time.Time `json:"created"` - Updated *time.Time `json:"updated"` - MemberCount uint64 `json:"member_count"` - Unlisted bool `json:"unlisted"` - Private bool `json:"private"` - Deleted bool `json:"deleted"` - AppURL string `json:"app_url"` - FeedURL string `json:"feed_url"` - FeedType uint64 `json:"feed_type"` - LastActive int64 `json:"last_active"` - Bots string `json:"bots"` - OwnerRouteHint string `json:"owner_route_hint"` - Pin string `json:"pin"` - Preview string `json:"preview"` - ProfileFilters string `json:"profile_filters"` // "twitter,github" - Badges StringArray `gorm:"type:text[]" json:"badges"` + UUID string `json:"uuid"` + OwnerPubKey string `json:"owner_pubkey"` + OwnerAlias string `json:"owner_alias"` + GroupKey string `json:"group_key"` + Name string `json:"name"` + UniqueName string `json:"unique_name"` + Description string `json:"description"` + Tags pq.StringArray `gorm:"type:text[]" json:"tags"` + Img string `json:"img"` + PriceToJoin int64 `json:"price_to_join"` + PricePerMessage int64 `json:"price_per_message"` + EscrowAmount int64 `json:"escrow_amount"` + EscrowMillis int64 `json:"escrow_millis"` + Created *time.Time `json:"created"` + Updated *time.Time `json:"updated"` + MemberCount uint64 `json:"member_count"` + Unlisted bool `json:"unlisted"` + Private bool `json:"private"` + Deleted bool `json:"deleted"` + AppURL string `json:"app_url"` + FeedURL string `json:"feed_url"` + FeedType uint64 `json:"feed_type"` + LastActive int64 `json:"last_active"` + Bots string `json:"bots"` + OwnerRouteHint string `json:"owner_route_hint"` + Pin string `json:"pin"` + Preview string `json:"preview"` + ProfileFilters string `json:"profile_filters"` // "twitter,github" + Badges pq.StringArray `gorm:"type:text[]" json:"badges"` } // Bot struct type Bot struct { - UUID string `json:"uuid"` - OwnerPubKey string `json:"owner_pubkey"` - OwnerAlias string `json:"owner_alias"` - Name string `json:"name"` - UniqueName string `json:"unique_name"` - Description string `json:"description"` - Tags StringArray `json:"tags"` - Img string `json:"img"` - PricePerUse int64 `json:"price_per_use"` - Created *time.Time `json:"created"` - Updated *time.Time `json:"updated"` - Unlisted bool `json:"unlisted"` - Deleted bool `json:"deleted"` - MemberCount uint64 `json:"member_count"` - OwnerRouteHint string `json:"owner_route_hint"` + UUID string `json:"uuid"` + OwnerPubKey string `json:"owner_pubkey"` + OwnerAlias string `json:"owner_alias"` + Name string `json:"name"` + UniqueName string `json:"unique_name"` + Description string `json:"description"` + Tags pq.StringArray `json:"tags"` + Img string `json:"img"` + PricePerUse int64 `json:"price_per_use"` + Created *time.Time `json:"created"` + Updated *time.Time `json:"updated"` + Unlisted bool `json:"unlisted"` + Deleted bool `json:"deleted"` + MemberCount uint64 `json:"member_count"` + OwnerRouteHint string `json:"owner_route_hint"` } // Bot struct type BotRes struct { - UUID string `json:"uuid"` - OwnerPubKey string `json:"owner_pubkey"` - Name string `json:"name"` - UniqueName string `json:"unique_name"` - Description string `json:"description"` - Tags StringArray `json:"tags"` - Img string `json:"img"` - PricePerUse int64 `json:"price_per_use"` + UUID string `json:"uuid"` + OwnerPubKey string `json:"owner_pubkey"` + Name string `json:"name"` + UniqueName string `json:"unique_name"` + Description string `json:"description"` + Tags pq.StringArray `json:"tags"` + Img string `json:"img"` + PricePerUse int64 `json:"price_per_use"` } // for bot pricing info @@ -105,26 +105,26 @@ func (PersonInShort) TableName() string { // Person struct type Person struct { - ID uint `json:"id"` - Uuid string `json:"uuid"` - OwnerPubKey string `json:"owner_pubkey"` - OwnerAlias string `json:"owner_alias"` - UniqueName string `json:"unique_name"` - Description string `json:"description"` - Tags StringArray `gorm:"type:text[]" json:"tags" null` - Img string `json:"img"` - Created *time.Time `json:"created"` - Updated *time.Time `json:"updated"` - Unlisted bool `json:"unlisted"` - Deleted bool `json:"deleted"` - LastLogin int64 `json:"last_login"` - OwnerRouteHint string `json:"owner_route_hint"` - OwnerContactKey string `json:"owner_contact_key"` - PriceToMeet int64 `json:"price_to_meet"` - Extras PropertyMap `json:"extras", type: jsonb not null default '{}'::jsonb` - TwitterConfirmed bool `json:"twitter_confirmed"` - GithubIssues PropertyMap `json:"github_issues", type: jsonb not null default '{}'::jsonb` - NewTicketTime int64 `json:"new_ticket_time", gorm: "-:all"` + ID uint `json:"id"` + Uuid string `json:"uuid"` + OwnerPubKey string `json:"owner_pubkey"` + OwnerAlias string `json:"owner_alias"` + UniqueName string `json:"unique_name"` + Description string `json:"description"` + Tags pq.StringArray `gorm:"type:text[]" json:"tags" null` + Img string `json:"img"` + Created *time.Time `json:"created"` + Updated *time.Time `json:"updated"` + Unlisted bool `json:"unlisted"` + Deleted bool `json:"deleted"` + LastLogin int64 `json:"last_login"` + OwnerRouteHint string `json:"owner_route_hint"` + OwnerContactKey string `json:"owner_contact_key"` + PriceToMeet int64 `json:"price_to_meet"` + Extras PropertyMap `json:"extras", type: jsonb not null default '{}'::jsonb` + TwitterConfirmed bool `json:"twitter_confirmed"` + GithubIssues PropertyMap `json:"github_issues", type: jsonb not null default '{}'::jsonb` + NewTicketTime int64 `json:"new_ticket_time", gorm: "-:all"` } type GormDataTypeInterface interface { @@ -322,7 +322,6 @@ type PropertyMap map[string]interface{} func (p PropertyMap) Value() (driver.Value, error) { b := new(bytes.Buffer) err := json.NewEncoder(b).Encode(p) - return b, err } diff --git a/frontend/app/src/people/utils/assignBounty.tsx b/frontend/app/src/people/utils/assignBounty.tsx index 29f1ab770..c7b5baaa7 100644 --- a/frontend/app/src/people/utils/assignBounty.tsx +++ b/frontend/app/src/people/utils/assignBounty.tsx @@ -39,7 +39,7 @@ export default function AssignBounty(props: ConnectCardProps) { } const generateInvoice = async () => { - const data = await main.getLnInvoice({ + await main.getLnInvoice({ amount: 200 * bountyHours, memo: '', owner_pubkey: person?.owner_pubkey ?? '', @@ -81,7 +81,7 @@ export default function AssignBounty(props: ConnectCardProps) { main.getPeopleWanteds({ page: 1, resetPage: true }); } - if (count >= invoicePollTarget * pollMinutes) { + if (count >= invoicePollTarget) { // close modal props.dismiss(); main.setLnInvoice(''); diff --git a/frontend/app/src/people/widgetViews/summaries/wantedSummaries/invoice.tsx b/frontend/app/src/people/widgetViews/summaries/wantedSummaries/invoice.tsx index 41b3c18e5..1bc5722b1 100644 --- a/frontend/app/src/people/widgetViews/summaries/wantedSummaries/invoice.tsx +++ b/frontend/app/src/people/widgetViews/summaries/wantedSummaries/invoice.tsx @@ -29,7 +29,7 @@ export default function Invoice(props: { return (
- {timeLeft.seconds || (timeLeft.minutes && !props.dataStatus) ? ( + {timeLeft.seconds >= 0 || (timeLeft.minutes >= 0 && !props.dataStatus) ? ( Invoice expires in a minute diff --git a/handlers/invoiceCron.go b/handlers/invoiceCron.go index 7008111e5..d31e75411 100644 --- a/handlers/invoiceCron.go +++ b/handlers/invoiceCron.go @@ -126,7 +126,7 @@ func InitInvoiceCron() { "extras": b, }) - // Delete the index from tje store array list and reset the store + // Delete the index from the store array list and reset the store newInvoiceList := append(invoiceList[:index], invoiceList[index+1:]...) db.Store.SetInvoiceCache(newInvoiceList) } @@ -191,6 +191,10 @@ func InitInvoiceCron() { db.DB.UpdatePerson(p.ID, map[string]interface{}{ "extras": b, }) + + // Delete the index from the store array list and reset the store + newInvoiceList := append(invoiceList[:index], invoiceList[index+1:]...) + db.Store.SetInvoiceCache(newInvoiceList) } } }