fix: minor issues and adding method to retrieve the stickermarket contract address

This commit is contained in:
Richard Ramos 2022-02-27 20:12:34 -04:00
parent efae55539a
commit c59335aa86
4 changed files with 39 additions and 11 deletions

View File

@ -134,8 +134,6 @@ func (api *API) Market(chainID uint64) ([]StickerPack, error) {
}
case <-doneChan:
// TODO: add an attribute to indicate if the sticker pack
// is bought, but the transaction is still pending confirmation.
var result []StickerPack
for _, pack := range allStickerPacks {
packID := uint(pack.ID.Uint64())
@ -147,6 +145,7 @@ func (api *API) Market(chainID uint64) ([]StickerPack, error) {
}
result = append(result, pack)
}
return result, nil
}
}
@ -327,6 +326,7 @@ func (api *API) fetchStickerPacks(chainID uint64, resultChan chan<- *StickerPack
resultChan <- stickerPack
}(i)
}
c.WaitAllDone()
}

View File

@ -60,6 +60,25 @@ func (api *API) Pending() (map[uint]StickerPack, error) {
for packID, stickerPack := range stickerPacks {
stickerPack.Status = statusPending
stickerPack.Preview, err = decodeStringHash(stickerPack.Preview)
if err != nil {
return nil, err
}
stickerPack.Thumbnail, err = decodeStringHash(stickerPack.Thumbnail)
if err != nil {
return nil, err
}
for i, sticker := range stickerPack.Stickers {
sticker.URL, err = decodeStringHash(sticker.Hash)
if err != nil {
return nil, err
}
stickerPack.Stickers[i] = sticker
}
stickerPacks[packID] = stickerPack
}

View File

@ -7,25 +7,30 @@ import (
const maxNumberRecentStickers = 24
func (api *API) recentStickers() ([]Sticker, error) {
var recentStickersList []Sticker
recentStickersList := make([]Sticker, 0)
recentStickersJSON, err := api.accountsDB.GetRecentStickers()
if err != nil {
return nil, err
return recentStickersList, err
}
if recentStickersJSON == nil {
return nil, nil
return recentStickersList, nil
}
err = json.Unmarshal(*recentStickersJSON, &recentStickersList)
if err != nil {
return nil, err
return recentStickersList, err
}
return recentStickersList, nil
}
func (api *API) ClearRecent() error {
recentStickersList := []Sticker{}
return api.accountsDB.SaveSetting("stickers/recent-stickers", recentStickersList)
}
func (api *API) Recent() ([]Sticker, error) {
recentStickersList, err := api.recentStickers()
if err != nil {

View File

@ -29,11 +29,6 @@ func (api *API) getSigner(chainID uint64, from types.Address, password string) b
}
func (api *API) Buy(ctx context.Context, chainID uint64, txArgs transactions.SendTxArgs, packID *bigint.BigInt, password string) (string, error) {
err := api.AddPending(chainID, packID)
if err != nil {
return "", err
}
snt, err := api.contractMaker.NewSNT(chainID)
if err != nil {
return "", err
@ -78,6 +73,11 @@ func (api *API) Buy(ctx context.Context, chainID uint64, txArgs transactions.Sen
return "", err
}
err = api.AddPending(chainID, packID)
if err != nil {
return "", err
}
// TODO: track pending transaction (do this in ENS service too)
go api.rpcFiltersSrvc.TriggerTransactionSentToUpstreamEvent(types.Hash(tx.Hash()))
@ -140,3 +140,7 @@ func (api *API) BuyEstimate(ctx context.Context, chainID uint64, from types.Addr
})
}
func (api *API) StickerMarketAddress(ctx context.Context, chainID uint64) (common.Address, error) {
return stickers.StickerMarketContractAddress(chainID)
}