-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from trustwallet/vikmeup/asset-image
Add asset image
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package asset | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/trustwallet/go-primitives/coin" | ||
) | ||
|
||
func GetImageURL(endpoint, asset string) string { | ||
coinId, tokenId, err := ParseID(asset) | ||
if err != nil { | ||
return "" | ||
} | ||
if c, ok := coin.Coins[coinId]; ok { | ||
if len(tokenId) > 0 { | ||
return fmt.Sprintf("%s/blockchains/%s/assets/%s/logo.png", endpoint, c.Handle, tokenId) | ||
} | ||
return fmt.Sprintf("%s/blockchains/%s/info/logo.png", endpoint, c.Handle) | ||
} | ||
return "" | ||
} |
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,47 @@ | ||
package asset | ||
|
||
import "testing" | ||
|
||
func TestGetImageURL(t *testing.T) { | ||
type args struct { | ||
endpoint string | ||
asset string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
}{ | ||
{ | ||
"Test coin", | ||
args{ | ||
endpoint: "https://assets.com", | ||
asset: "c60", | ||
}, | ||
"https://assets.com/blockchains/ethereum/info/logo.png", | ||
}, | ||
{ | ||
"Test coin", | ||
args{ | ||
endpoint: "https://assets.com", | ||
asset: "c60_t123", | ||
}, | ||
"https://assets.com/blockchains/ethereum/assets/123/logo.png", | ||
}, | ||
{ | ||
"Test invalid coin", | ||
args{ | ||
endpoint: "https://assets.com", | ||
asset: "c123", | ||
}, | ||
"", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := GetImageURL(tt.args.endpoint, tt.args.asset); got != tt.want { | ||
t.Errorf("GetImageURL() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |