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:
parent
0b9555bf31
commit
4305147f7a
|
@ -4003,7 +4003,7 @@ func (m *Manager) ImageToBase64(uri string) string {
|
||||||
return base64img
|
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)
|
community, err := m.GetByIDString(token.CommunityID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -4013,7 +4013,20 @@ func (m *Manager) AddCommunityToken(token *CommunityToken) (*CommunityToken, err
|
||||||
return nil, ErrOrgNotFound
|
return nil, ErrOrgNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
token.Base64Image = m.ImageToBase64(token.Base64Image)
|
||||||
|
}
|
||||||
|
|
||||||
tokenMetadata := &protobuf.CommunityTokenMetadata{
|
tokenMetadata := &protobuf.CommunityTokenMetadata{
|
||||||
ContractAddresses: map[uint64]string{uint64(token.ChainID): token.Address},
|
ContractAddresses: map[uint64]string{uint64(token.ChainID): token.Address},
|
||||||
|
|
|
@ -3778,8 +3778,8 @@ func (m *Messenger) GetAllCommunityTokens() ([]*communities.CommunityToken, erro
|
||||||
return m.communitiesManager.GetAllCommunityTokens()
|
return m.communitiesManager.GetAllCommunityTokens()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) AddCommunityToken(token *communities.CommunityToken) (*communities.CommunityToken, error) {
|
func (m *Messenger) AddCommunityToken(token *communities.CommunityToken, croppedImage *images.CroppedImage) (*communities.CommunityToken, error) {
|
||||||
return m.communitiesManager.AddCommunityToken(token)
|
return m.communitiesManager.AddCommunityToken(token, croppedImage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) UpdateCommunityTokenState(chainID int, contractAddress string, deployState communities.DeployState) error {
|
func (m *Messenger) UpdateCommunityTokenState(chainID int, contractAddress string, deployState communities.DeployState) error {
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
ethcommon "github.com/ethereum/go-ethereum/common"
|
ethcommon "github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/status-im/status-go/eth-node/crypto"
|
"github.com/status-im/status-go/eth-node/crypto"
|
||||||
"github.com/status-im/status-go/eth-node/types"
|
"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/mailserver"
|
||||||
"github.com/status-im/status-go/multiaccounts/settings"
|
"github.com/status-im/status-go/multiaccounts/settings"
|
||||||
"github.com/status-im/status-go/protocol"
|
"github.com/status-im/status-go/protocol"
|
||||||
|
@ -1305,8 +1306,8 @@ func (api *PublicAPI) GetAllCommunityTokens() ([]*communities.CommunityToken, er
|
||||||
return api.service.messenger.GetAllCommunityTokens()
|
return api.service.messenger.GetAllCommunityTokens()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PublicAPI) AddCommunityToken(token *communities.CommunityToken) (*communities.CommunityToken, error) {
|
func (api *PublicAPI) AddCommunityToken(token *communities.CommunityToken, croppedImage *images.CroppedImage) (*communities.CommunityToken, error) {
|
||||||
return api.service.messenger.AddCommunityToken(token)
|
return api.service.messenger.AddCommunityToken(token, croppedImage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PublicAPI) UpdateCommunityTokenState(chainID int, contractAddress string, deployState communities.DeployState) error {
|
func (api *PublicAPI) UpdateCommunityTokenState(chainID int, contractAddress string, deployState communities.DeployState) error {
|
||||||
|
|
Loading…
Reference in New Issue