github.com/status-im/status-go@v1.1.0/protocol/identity/profile_showcase.go (about)

     1  package identity
     2  
     3  import "errors"
     4  
     5  var ErrorNoAccountProvidedWithTokenOrCollectible = errors.New("no account provided with tokens or collectible")
     6  
     7  var ErrorExceedMaxProfileShowcaseCommunitiesLimit = errors.New("exeed maximum profile showcase communities limit")
     8  var ErrorExceedMaxProfileShowcaseAccountsLimit = errors.New("exeed maximum profile showcase accounts limit")
     9  var ErrorExceedMaxProfileShowcaseCollectiblesLimit = errors.New("exeed maximum profile showcase collectibles limit")
    10  var ErrorExceedMaxProfileShowcaseVerifiedTokensLimit = errors.New("exeed maximum profile showcase verified tokens limit")
    11  var ErrorExceedMaxProfileShowcaseUnverifiedTokensLimit = errors.New("exeed maximum profile showcase unverified tokens limit")
    12  var ErrorExceedMaxProfileShowcaseSocialLinksLimit = errors.New("exeed maximum profile showcase communities limit")
    13  
    14  const MaxProfileShowcaseSocialLinksLimit = 20
    15  const MaxProfileShowcaseEntriesLimit = 100
    16  
    17  type ProfileShowcaseVisibility int
    18  
    19  const (
    20  	ProfileShowcaseVisibilityNoOne ProfileShowcaseVisibility = iota
    21  	ProfileShowcaseVisibilityIDVerifiedContacts
    22  	ProfileShowcaseVisibilityContacts
    23  	ProfileShowcaseVisibilityEveryone
    24  )
    25  
    26  type ProfileShowcaseMembershipStatus int
    27  
    28  const (
    29  	ProfileShowcaseMembershipStatusUnproven ProfileShowcaseMembershipStatus = iota
    30  	ProfileShowcaseMembershipStatusProvenMember
    31  	ProfileShowcaseMembershipStatusNotAMember
    32  )
    33  
    34  const (
    35  	TwitterID      = "__twitter"
    36  	PersonalSiteID = "__personal_site"
    37  	GithubID       = "__github"
    38  	YoutubeID      = "__youtube"
    39  	DiscordID      = "__discord"
    40  	TelegramID     = "__telegram"
    41  )
    42  
    43  // Profile showcase preferences
    44  
    45  type ProfileShowcaseCommunityPreference struct {
    46  	CommunityID        string                    `json:"communityId"`
    47  	ShowcaseVisibility ProfileShowcaseVisibility `json:"showcaseVisibility"`
    48  	Order              int                       `json:"order"`
    49  }
    50  
    51  type ProfileShowcaseAccountPreference struct {
    52  	Address            string                    `json:"address"`
    53  	ShowcaseVisibility ProfileShowcaseVisibility `json:"showcaseVisibility"`
    54  	Order              int                       `json:"order"`
    55  }
    56  
    57  type ProfileShowcaseCollectiblePreference struct {
    58  	ContractAddress    string                    `json:"contractAddress"`
    59  	ChainID            uint64                    `json:"chainId"`
    60  	TokenID            string                    `json:"tokenId"`
    61  	ShowcaseVisibility ProfileShowcaseVisibility `json:"showcaseVisibility"`
    62  	Order              int                       `json:"order"`
    63  }
    64  
    65  type ProfileShowcaseVerifiedTokenPreference struct {
    66  	Symbol             string                    `json:"symbol"`
    67  	ShowcaseVisibility ProfileShowcaseVisibility `json:"showcaseVisibility"`
    68  	Order              int                       `json:"order"`
    69  }
    70  
    71  type ProfileShowcaseUnverifiedTokenPreference struct {
    72  	ContractAddress    string                    `json:"contractAddress"`
    73  	ChainID            uint64                    `json:"chainId"`
    74  	ShowcaseVisibility ProfileShowcaseVisibility `json:"showcaseVisibility"`
    75  	Order              int                       `json:"order"`
    76  }
    77  
    78  type ProfileShowcaseSocialLinkPreference struct {
    79  	URL                string                    `json:"url"`
    80  	Text               string                    `json:"text"`
    81  	ShowcaseVisibility ProfileShowcaseVisibility `json:"showcaseVisibility"`
    82  	Order              int                       `json:"order"`
    83  }
    84  
    85  type ProfileShowcasePreferences struct {
    86  	Clock            uint64                                      `json:"clock"`
    87  	Communities      []*ProfileShowcaseCommunityPreference       `json:"communities"`
    88  	Accounts         []*ProfileShowcaseAccountPreference         `json:"accounts"`
    89  	Collectibles     []*ProfileShowcaseCollectiblePreference     `json:"collectibles"`
    90  	VerifiedTokens   []*ProfileShowcaseVerifiedTokenPreference   `json:"verifiedTokens"`
    91  	UnverifiedTokens []*ProfileShowcaseUnverifiedTokenPreference `json:"unverifiedTokens"`
    92  	SocialLinks      []*ProfileShowcaseSocialLinkPreference      `json:"socialLinks"`
    93  }
    94  
    95  // Profile showcase for a contact
    96  
    97  type ProfileShowcaseCommunity struct {
    98  	CommunityID      string                          `json:"communityId"`
    99  	Order            int                             `json:"order"`
   100  	MembershipStatus ProfileShowcaseMembershipStatus `json:"membershipStatus"`
   101  	Grant            []byte                          `json:"grant,omitempty"`
   102  }
   103  
   104  type ProfileShowcaseAccount struct {
   105  	ContactID string `json:"contactId"`
   106  	Address   string `json:"address"`
   107  	Name      string `json:"name"`
   108  	ColorID   string `json:"colorId"`
   109  	Emoji     string `json:"emoji"`
   110  	Order     int    `json:"order"`
   111  }
   112  
   113  type ProfileShowcaseCollectible struct {
   114  	ContractAddress string `json:"contractAddress"`
   115  	ChainID         uint64 `json:"chainId"`
   116  	TokenID         string `json:"tokenId"`
   117  	Order           int    `json:"order"`
   118  }
   119  
   120  type ProfileShowcaseVerifiedToken struct {
   121  	Symbol string `json:"symbol"`
   122  	Order  int    `json:"order"`
   123  }
   124  
   125  type ProfileShowcaseUnverifiedToken struct {
   126  	ContractAddress string `json:"contractAddress"`
   127  	ChainID         uint64 `json:"chainId"`
   128  	Order           int    `json:"order"`
   129  }
   130  
   131  type ProfileShowcaseSocialLink struct {
   132  	URL   string `json:"url"`
   133  	Text  string `json:"text"`
   134  	Order int    `json:"order"`
   135  }
   136  
   137  type ProfileShowcase struct {
   138  	ContactID        string                            `json:"contactId"`
   139  	Communities      []*ProfileShowcaseCommunity       `json:"communities"`
   140  	Accounts         []*ProfileShowcaseAccount         `json:"accounts"`
   141  	Collectibles     []*ProfileShowcaseCollectible     `json:"collectibles"`
   142  	VerifiedTokens   []*ProfileShowcaseVerifiedToken   `json:"verifiedTokens"`
   143  	UnverifiedTokens []*ProfileShowcaseUnverifiedToken `json:"unverifiedTokens"`
   144  	SocialLinks      []*ProfileShowcaseSocialLink      `json:"socialLinks"`
   145  }
   146  
   147  func Validate(preferences *ProfileShowcasePreferences) error {
   148  	if len(preferences.Communities) > MaxProfileShowcaseEntriesLimit {
   149  		return ErrorExceedMaxProfileShowcaseCommunitiesLimit
   150  	}
   151  	if len(preferences.Accounts) > MaxProfileShowcaseEntriesLimit {
   152  		return ErrorExceedMaxProfileShowcaseAccountsLimit
   153  	}
   154  	if len(preferences.Collectibles) > MaxProfileShowcaseEntriesLimit {
   155  		return ErrorExceedMaxProfileShowcaseCollectiblesLimit
   156  	}
   157  	if len(preferences.VerifiedTokens) > MaxProfileShowcaseEntriesLimit {
   158  		return ErrorExceedMaxProfileShowcaseVerifiedTokensLimit
   159  	}
   160  	if len(preferences.UnverifiedTokens) > MaxProfileShowcaseEntriesLimit {
   161  		return ErrorExceedMaxProfileShowcaseUnverifiedTokensLimit
   162  	}
   163  	if len(preferences.SocialLinks) > MaxProfileShowcaseSocialLinksLimit {
   164  		return ErrorExceedMaxProfileShowcaseSocialLinksLimit
   165  	}
   166  
   167  	if (len(preferences.VerifiedTokens) > 0 || len(preferences.UnverifiedTokens) > 0 || len(preferences.Collectibles) > 0) &&
   168  		len(preferences.Accounts) == 0 {
   169  		return ErrorNoAccountProvidedWithTokenOrCollectible
   170  	}
   171  
   172  	return nil
   173  }