-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add asset pkg with logo and info functions (#19)
- Loading branch information
Showing
6 changed files
with
88 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package asset | ||
|
||
import "fmt" | ||
|
||
func GetAssetInfoPath(chain, tokenID string) string { | ||
return fmt.Sprintf("blockchains/%s/assets/%s/info.json", chain, tokenID) | ||
} | ||
|
||
func GetAssetInfoURL(repoOwner, repoName, branch, chain, tokenID string) string { | ||
return fmt.Sprintf("https://raw.githubusercontent.com/%s/%s/%s/blockchains/%s/assets/%s/info.json", | ||
repoOwner, repoName, branch, chain, tokenID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package asset | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/trustwallet/go-primitives/types" | ||
) | ||
|
||
func GetAssetLogoPath(chain, tokenID string) string { | ||
return fmt.Sprintf("blockchains/%s/assets/%s/logo.png", chain, tokenID) | ||
} | ||
|
||
func GetAssetLogoURL(repoOwner, repoName, branch, chain, tokenID string) string { | ||
return fmt.Sprintf("https://raw.githubusercontent.com/%s/%s/%s/blockchains/%s/assets/%s/logo.png", | ||
repoOwner, repoName, branch, chain, tokenID) | ||
} | ||
|
||
func GetTokenFromAssetLogoPath(path string) (tokenID, tokenType string, err error) { | ||
for _, t := range types.GetTokenTypes() { | ||
chain, err := types.GetChainFromAssetType(string(t)) | ||
if err != nil { | ||
continue | ||
} | ||
|
||
prefix := fmt.Sprintf("blockchains/%s/assets/", chain.Handle) | ||
suffix := "/logo.png" | ||
|
||
if strings.HasPrefix(path, prefix) && strings.HasSuffix(path, suffix) { | ||
tokenType = string(t) | ||
tokenID = path[len(prefix):(len(path) - len(suffix))] | ||
|
||
break | ||
} | ||
} | ||
|
||
if tokenType == "TRC20" && strings.HasPrefix(tokenID, "10") { | ||
tokenType = "TRC10" | ||
} | ||
|
||
if tokenID == "" && tokenType == "" { | ||
return tokenID, tokenType, fmt.Errorf("couldn't get token id and token type") | ||
} | ||
|
||
return tokenID, tokenType, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package pkg | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
func IsFileAllowedInPR(path string) bool { | ||
if strings.HasSuffix(path, "tokenlist.json") { | ||
return false | ||
} | ||
if strings.HasPrefix(path, "blockchains") && strings.Index(path, "assets") > 0 { | ||
return true | ||
} | ||
if strings.HasPrefix(path, "blockchains") && strings.HasSuffix(path, "allowlist.json") { | ||
return true | ||
} | ||
if strings.HasPrefix(path, "blockchains") && strings.HasSuffix(path, "validators/list.json") { | ||
return true | ||
} | ||
if strings.HasPrefix(path, "dapps") { | ||
return true | ||
} | ||
|
||
return false | ||
} |