diff --git a/protocol/communities/manager.go b/protocol/communities/manager.go index 11a815c2b..892def486 100644 --- a/protocol/communities/manager.go +++ b/protocol/communities/manager.go @@ -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}, diff --git a/protocol/messenger_communities.go b/protocol/messenger_communities.go index 815b691aa..fb1602648 100644 --- a/protocol/messenger_communities.go +++ b/protocol/messenger_communities.go @@ -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 { diff --git a/services/ext/api.go b/services/ext/api.go index 82d43b8ba..a6cfcbffb 100644 --- a/services/ext/api.go +++ b/services/ext/api.go @@ -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 {