2024-02-15 19:13:12 +00:00
|
|
|
package identity
|
|
|
|
|
|
|
|
import "errors"
|
|
|
|
|
|
|
|
var ErrorNoAccountProvidedWithTokenOrCollectible = errors.New("no account provided with tokens or collectible")
|
|
|
|
|
2024-02-26 13:53:40 +00:00
|
|
|
var ErrorExceedMaxProfileShowcaseCommunitiesLimit = errors.New("exeed maximum profile showcase communities limit")
|
|
|
|
var ErrorExceedMaxProfileShowcaseAccountsLimit = errors.New("exeed maximum profile showcase accounts limit")
|
|
|
|
var ErrorExceedMaxProfileShowcaseCollectiblesLimit = errors.New("exeed maximum profile showcase collectibles limit")
|
|
|
|
var ErrorExceedMaxProfileShowcaseVerifiedTokensLimit = errors.New("exeed maximum profile showcase verified tokens limit")
|
|
|
|
var ErrorExceedMaxProfileShowcaseUnverifiedTokensLimit = errors.New("exeed maximum profile showcase unverified tokens limit")
|
|
|
|
var ErrorExceedMaxProfileShowcaseSocialLinksLimit = errors.New("exeed maximum profile showcase communities limit")
|
|
|
|
|
2024-03-08 16:20:23 +00:00
|
|
|
const MaxProfileShowcaseSocialLinksLimit = 20
|
|
|
|
const MaxProfileShowcaseEntriesLimit = 100
|
2024-02-26 13:53:40 +00:00
|
|
|
|
2024-02-15 19:13:12 +00:00
|
|
|
type ProfileShowcaseVisibility int
|
|
|
|
|
|
|
|
const (
|
|
|
|
ProfileShowcaseVisibilityNoOne ProfileShowcaseVisibility = iota
|
|
|
|
ProfileShowcaseVisibilityIDVerifiedContacts
|
|
|
|
ProfileShowcaseVisibilityContacts
|
|
|
|
ProfileShowcaseVisibilityEveryone
|
|
|
|
)
|
|
|
|
|
|
|
|
type ProfileShowcaseMembershipStatus int
|
|
|
|
|
|
|
|
const (
|
|
|
|
ProfileShowcaseMembershipStatusUnproven ProfileShowcaseMembershipStatus = iota
|
|
|
|
ProfileShowcaseMembershipStatusProvenMember
|
|
|
|
ProfileShowcaseMembershipStatusNotAMember
|
|
|
|
)
|
|
|
|
|
2024-02-26 13:53:40 +00:00
|
|
|
// Profile showcase preferences
|
|
|
|
|
2024-02-15 19:13:12 +00:00
|
|
|
type ProfileShowcaseCommunityPreference struct {
|
|
|
|
CommunityID string `json:"communityId"`
|
|
|
|
ShowcaseVisibility ProfileShowcaseVisibility `json:"showcaseVisibility"`
|
|
|
|
Order int `json:"order"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ProfileShowcaseAccountPreference struct {
|
|
|
|
Address string `json:"address"`
|
|
|
|
ShowcaseVisibility ProfileShowcaseVisibility `json:"showcaseVisibility"`
|
|
|
|
Order int `json:"order"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ProfileShowcaseCollectiblePreference struct {
|
|
|
|
ContractAddress string `json:"contractAddress"`
|
|
|
|
ChainID uint64 `json:"chainId"`
|
|
|
|
TokenID string `json:"tokenId"`
|
|
|
|
ShowcaseVisibility ProfileShowcaseVisibility `json:"showcaseVisibility"`
|
|
|
|
Order int `json:"order"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ProfileShowcaseVerifiedTokenPreference struct {
|
|
|
|
Symbol string `json:"symbol"`
|
|
|
|
ShowcaseVisibility ProfileShowcaseVisibility `json:"showcaseVisibility"`
|
|
|
|
Order int `json:"order"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ProfileShowcaseUnverifiedTokenPreference struct {
|
|
|
|
ContractAddress string `json:"contractAddress"`
|
|
|
|
ChainID uint64 `json:"chainId"`
|
|
|
|
ShowcaseVisibility ProfileShowcaseVisibility `json:"showcaseVisibility"`
|
|
|
|
Order int `json:"order"`
|
|
|
|
}
|
|
|
|
|
2024-02-26 13:53:40 +00:00
|
|
|
type ProfileShowcaseSocialLinkPreference struct {
|
|
|
|
URL string `json:"url"`
|
|
|
|
Text string `json:"text"`
|
|
|
|
ShowcaseVisibility ProfileShowcaseVisibility `json:"showcaseVisibility"`
|
|
|
|
Order int `json:"order"`
|
|
|
|
}
|
|
|
|
|
2024-02-15 19:13:12 +00:00
|
|
|
type ProfileShowcasePreferences struct {
|
2024-02-17 18:07:20 +00:00
|
|
|
Clock uint64 `json:"clock"`
|
2024-02-15 19:13:12 +00:00
|
|
|
Communities []*ProfileShowcaseCommunityPreference `json:"communities"`
|
|
|
|
Accounts []*ProfileShowcaseAccountPreference `json:"accounts"`
|
|
|
|
Collectibles []*ProfileShowcaseCollectiblePreference `json:"collectibles"`
|
|
|
|
VerifiedTokens []*ProfileShowcaseVerifiedTokenPreference `json:"verifiedTokens"`
|
|
|
|
UnverifiedTokens []*ProfileShowcaseUnverifiedTokenPreference `json:"unverifiedTokens"`
|
2024-02-26 13:53:40 +00:00
|
|
|
SocialLinks []*ProfileShowcaseSocialLinkPreference `json:"socialLinks"`
|
2024-02-15 19:13:12 +00:00
|
|
|
}
|
|
|
|
|
2024-02-26 13:53:40 +00:00
|
|
|
// Profile showcase for a contact
|
|
|
|
|
2024-02-15 19:13:12 +00:00
|
|
|
type ProfileShowcaseCommunity struct {
|
2024-03-29 10:22:44 +00:00
|
|
|
CommunityID string `json:"communityId"`
|
|
|
|
Order int `json:"order"`
|
|
|
|
MembershipStatus ProfileShowcaseMembershipStatus `json:"membershipStatus"`
|
|
|
|
Grant []byte `json:"grant,omitempty"`
|
2024-02-15 19:13:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ProfileShowcaseAccount struct {
|
|
|
|
ContactID string `json:"contactId"`
|
|
|
|
Address string `json:"address"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
ColorID string `json:"colorId"`
|
|
|
|
Emoji string `json:"emoji"`
|
|
|
|
Order int `json:"order"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ProfileShowcaseCollectible struct {
|
|
|
|
ContractAddress string `json:"contractAddress"`
|
|
|
|
ChainID uint64 `json:"chainId"`
|
|
|
|
TokenID string `json:"tokenId"`
|
|
|
|
Order int `json:"order"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ProfileShowcaseVerifiedToken struct {
|
|
|
|
Symbol string `json:"symbol"`
|
|
|
|
Order int `json:"order"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ProfileShowcaseUnverifiedToken struct {
|
|
|
|
ContractAddress string `json:"contractAddress"`
|
|
|
|
ChainID uint64 `json:"chainId"`
|
|
|
|
Order int `json:"order"`
|
|
|
|
}
|
|
|
|
|
2024-02-26 13:53:40 +00:00
|
|
|
type ProfileShowcaseSocialLink struct {
|
|
|
|
URL string `json:"url"`
|
|
|
|
Text string `json:"text"`
|
|
|
|
Order int `json:"order"`
|
|
|
|
}
|
|
|
|
|
2024-02-15 19:13:12 +00:00
|
|
|
type ProfileShowcase struct {
|
|
|
|
ContactID string `json:"contactId"`
|
|
|
|
Communities []*ProfileShowcaseCommunity `json:"communities"`
|
|
|
|
Accounts []*ProfileShowcaseAccount `json:"accounts"`
|
|
|
|
Collectibles []*ProfileShowcaseCollectible `json:"collectibles"`
|
|
|
|
VerifiedTokens []*ProfileShowcaseVerifiedToken `json:"verifiedTokens"`
|
|
|
|
UnverifiedTokens []*ProfileShowcaseUnverifiedToken `json:"unverifiedTokens"`
|
2024-02-26 13:53:40 +00:00
|
|
|
SocialLinks []*ProfileShowcaseSocialLink `json:"socialLinks"`
|
2024-02-15 19:13:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Validate(preferences *ProfileShowcasePreferences) error {
|
2024-03-08 16:20:23 +00:00
|
|
|
if len(preferences.Communities) > MaxProfileShowcaseEntriesLimit {
|
2024-02-26 13:53:40 +00:00
|
|
|
return ErrorExceedMaxProfileShowcaseCommunitiesLimit
|
|
|
|
}
|
2024-03-08 16:20:23 +00:00
|
|
|
if len(preferences.Accounts) > MaxProfileShowcaseEntriesLimit {
|
2024-02-26 13:53:40 +00:00
|
|
|
return ErrorExceedMaxProfileShowcaseAccountsLimit
|
|
|
|
}
|
2024-03-08 16:20:23 +00:00
|
|
|
if len(preferences.Collectibles) > MaxProfileShowcaseEntriesLimit {
|
2024-02-26 13:53:40 +00:00
|
|
|
return ErrorExceedMaxProfileShowcaseCollectiblesLimit
|
|
|
|
}
|
2024-03-08 16:20:23 +00:00
|
|
|
if len(preferences.VerifiedTokens) > MaxProfileShowcaseEntriesLimit {
|
2024-02-26 13:53:40 +00:00
|
|
|
return ErrorExceedMaxProfileShowcaseVerifiedTokensLimit
|
|
|
|
}
|
2024-03-08 16:20:23 +00:00
|
|
|
if len(preferences.UnverifiedTokens) > MaxProfileShowcaseEntriesLimit {
|
2024-02-26 13:53:40 +00:00
|
|
|
return ErrorExceedMaxProfileShowcaseUnverifiedTokensLimit
|
|
|
|
}
|
2024-03-08 16:20:23 +00:00
|
|
|
if len(preferences.SocialLinks) > MaxProfileShowcaseSocialLinksLimit {
|
2024-02-26 13:53:40 +00:00
|
|
|
return ErrorExceedMaxProfileShowcaseSocialLinksLimit
|
|
|
|
}
|
|
|
|
|
2024-02-15 19:13:12 +00:00
|
|
|
if (len(preferences.VerifiedTokens) > 0 || len(preferences.UnverifiedTokens) > 0 || len(preferences.Collectibles) > 0) &&
|
|
|
|
len(preferences.Accounts) == 0 {
|
|
|
|
return ErrorNoAccountProvidedWithTokenOrCollectible
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|