fix: use same datatype for packID

This commit is contained in:
Richard Ramos 2022-02-13 19:43:08 -04:00
parent e89f8bbc50
commit 8c7549bf5e
3 changed files with 21 additions and 21 deletions

View File

@ -3,18 +3,17 @@ package stickers
import (
"encoding/json"
"errors"
"math/big"
"github.com/status-im/status-go/services/wallet/bigint"
)
func (api *API) Install(chainID uint64, packID uint64) error {
func (api *API) Install(chainID uint64, packID *bigint.BigInt) error {
installedPacks, err := api.installedStickerPacks()
if err != nil {
return err
}
if _, exists := installedPacks[uint(packID)]; exists {
if _, exists := installedPacks[uint(packID.Uint64())]; exists {
return errors.New("sticker pack is already installed")
}
@ -25,12 +24,12 @@ func (api *API) Install(chainID uint64, packID uint64) error {
return err
}
stickerPack, err := api.fetchPackData(stickerType, new(big.Int).SetUint64(packID), false)
stickerPack, err := api.fetchPackData(stickerType, packID.Int, false)
if err != nil {
return err
}
installedPacks[uint(packID)] = *stickerPack
installedPacks[uint(packID.Uint64())] = *stickerPack
err = api.accountsDB.SaveSetting("stickers/packs-installed", installedPacks)
if err != nil {
@ -93,17 +92,17 @@ func (api *API) Installed() (map[uint]StickerPack, error) {
return stickerPacks, nil
}
func (api *API) Uninstall(packID uint64) error {
func (api *API) Uninstall(packID *bigint.BigInt) error {
installedPacks, err := api.installedStickerPacks()
if err != nil {
return err
}
if _, exists := installedPacks[uint(packID)]; !exists {
if _, exists := installedPacks[uint(packID.Uint64())]; !exists {
return errors.New("sticker pack is not installed")
}
delete(installedPacks, uint(packID))
delete(installedPacks, uint(packID.Uint64()))
err = api.accountsDB.SaveSetting("stickers/packs-installed", installedPacks)
if err != nil {
@ -117,10 +116,9 @@ func (api *API) Uninstall(packID uint64) error {
return err
}
pID := &bigint.BigInt{Int: new(big.Int).SetUint64(packID)}
idx := -1
for i, r := range recentStickers {
if r.PackID.Cmp(pID.Int) == 0 {
if r.PackID.Cmp(packID.Int) == 0 {
idx = i
break
}

View File

@ -3,16 +3,17 @@ package stickers
import (
"encoding/json"
"errors"
"math/big"
"github.com/status-im/status-go/services/wallet/bigint"
)
func (api *API) AddPending(chainID uint64, packID uint64) error {
func (api *API) AddPending(chainID uint64, packID *bigint.BigInt) error {
pendingPacks, err := api.pendingStickerPacks()
if err != nil {
return err
}
if _, exists := pendingPacks[uint(packID)]; exists {
if _, exists := pendingPacks[uint(packID.Uint64())]; exists {
return errors.New("sticker pack is already pending")
}
@ -21,12 +22,12 @@ func (api *API) AddPending(chainID uint64, packID uint64) error {
return err
}
stickerPack, err := api.fetchPackData(stickerType, new(big.Int).SetUint64(packID), false)
stickerPack, err := api.fetchPackData(stickerType, packID.Int, false)
if err != nil {
return err
}
pendingPacks[uint(packID)] = *stickerPack
pendingPacks[uint(packID.Uint64())] = *stickerPack
return api.accountsDB.SaveSetting("stickers/packs-pending", pendingPacks)
}
@ -65,17 +66,17 @@ func (api *API) Pending() (map[uint]StickerPack, error) {
return stickerPacks, nil
}
func (api *API) RemovePending(packID uint64) error {
func (api *API) RemovePending(packID *bigint.BigInt) error {
pendingPacks, err := api.pendingStickerPacks()
if err != nil {
return err
}
if _, exists := pendingPacks[uint(packID)]; !exists {
if _, exists := pendingPacks[uint(packID.Uint64())]; !exists {
return errors.New("sticker pack is not pending")
}
delete(pendingPacks, uint(packID))
delete(pendingPacks, uint(packID.Uint64()))
return api.accountsDB.SaveSetting("stickers/packs-pending", pendingPacks)
}

View File

@ -13,6 +13,7 @@ import (
"github.com/status-im/status-go/contracts/snt"
"github.com/status-im/status-go/contracts/stickers"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/services/wallet/bigint"
"github.com/status-im/status-go/transactions"
)
@ -27,8 +28,8 @@ 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 *big.Int, password string) (string, error) {
err := api.AddPending(chainID, packID.Uint64())
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
}
@ -45,7 +46,7 @@ func (api *API) Buy(ctx context.Context, chainID uint64, txArgs transactions.Sen
callOpts := &bind.CallOpts{Context: api.ctx, Pending: false}
packInfo, err := stickerType.GetPackData(callOpts, packID)
packInfo, err := stickerType.GetPackData(callOpts, packID.Int)
if err != nil {
return "", err
}