feat: add cropping support for community token assets

This commit extends the `AddCommunityToken` API to also expect an
optional `CroppedImage`, which will be used instead of the `ImageBase64`
path provided by `CommunityToken`, to calculate the actual base64
encoded image.
This commit is contained in:
Pascal Precht 2023-07-03 12:46:09 +02:00 committed by r4bbit
parent 0b9555bf31
commit 4305147f7a
3 changed files with 20 additions and 6 deletions

View File

@ -4003,7 +4003,7 @@ func (m *Manager) ImageToBase64(uri string) string {
return base64img
}
func (m *Manager) AddCommunityToken(token *CommunityToken) (*CommunityToken, error) {
func (m *Manager) AddCommunityToken(token *CommunityToken, croppedImage *images.CroppedImage) (*CommunityToken, error) {
community, err := m.GetByIDString(token.CommunityID)
if err != nil {
@ -4013,7 +4013,20 @@ func (m *Manager) AddCommunityToken(token *CommunityToken) (*CommunityToken, err
return nil, ErrOrgNotFound
}
token.Base64Image = m.ImageToBase64(token.Base64Image)
if croppedImage != nil && croppedImage.ImagePath != "" {
bytes, err := images.OpenAndAdjustImage(*croppedImage, true)
if err != nil {
return nil, err
}
base64img, err := images.GetPayloadDataURI(bytes)
if err != nil {
return nil, err
}
token.Base64Image = base64img
} else {
token.Base64Image = m.ImageToBase64(token.Base64Image)
}
tokenMetadata := &protobuf.CommunityTokenMetadata{
ContractAddresses: map[uint64]string{uint64(token.ChainID): token.Address},

View File

@ -3778,8 +3778,8 @@ func (m *Messenger) GetAllCommunityTokens() ([]*communities.CommunityToken, erro
return m.communitiesManager.GetAllCommunityTokens()
}
func (m *Messenger) AddCommunityToken(token *communities.CommunityToken) (*communities.CommunityToken, error) {
return m.communitiesManager.AddCommunityToken(token)
func (m *Messenger) AddCommunityToken(token *communities.CommunityToken, croppedImage *images.CroppedImage) (*communities.CommunityToken, error) {
return m.communitiesManager.AddCommunityToken(token, croppedImage)
}
func (m *Messenger) UpdateCommunityTokenState(chainID int, contractAddress string, deployState communities.DeployState) error {

View File

@ -18,6 +18,7 @@ import (
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/images"
"github.com/status-im/status-go/mailserver"
"github.com/status-im/status-go/multiaccounts/settings"
"github.com/status-im/status-go/protocol"
@ -1305,8 +1306,8 @@ func (api *PublicAPI) GetAllCommunityTokens() ([]*communities.CommunityToken, er
return api.service.messenger.GetAllCommunityTokens()
}
func (api *PublicAPI) AddCommunityToken(token *communities.CommunityToken) (*communities.CommunityToken, error) {
return api.service.messenger.AddCommunityToken(token)
func (api *PublicAPI) AddCommunityToken(token *communities.CommunityToken, croppedImage *images.CroppedImage) (*communities.CommunityToken, error) {
return api.service.messenger.AddCommunityToken(token, croppedImage)
}
func (api *PublicAPI) UpdateCommunityTokenState(chainID int, contractAddress string, deployState communities.DeployState) error {