mirror of
https://github.com/Instadapp/trustwallet-assets.git
synced 2024-07-29 22:37:31 +00:00
Refactor code (#17251)
This commit is contained in:
parent
35ad6cb9fa
commit
cec78fe487
|
@ -1,25 +1,25 @@
|
|||
package file
|
||||
|
||||
const (
|
||||
TypeAssetInfoFile = "asset_info"
|
||||
TypeAssetLogoFile = "asset_logo"
|
||||
TypeChainInfoFile = "chain_info"
|
||||
TypeChainLogoFile = "chain_logo"
|
||||
TypeTokenListFile = "chain_token_list"
|
||||
TypeValidatorsListFile = "validators_list"
|
||||
TypeValidatorsLogoFile = "validators_logo"
|
||||
TypeDappsLogoFile = "dapps_logo"
|
||||
|
||||
TypeAssetFolder = "asset"
|
||||
TypeAssetsFolder = "assets"
|
||||
TypeChainFolder = "chain"
|
||||
TypeChainsFolder = "chains"
|
||||
TypeDappsFolder = "dapps"
|
||||
TypeRootFolder = "root"
|
||||
TypeAssetFolder = "asset_folder"
|
||||
TypeAssetsFolder = "assets_folder"
|
||||
TypeChainFolder = "chain_folder"
|
||||
TypeChainInfoFolder = "chain_info_folder"
|
||||
TypeValidatorsFolder = "validators"
|
||||
TypeValidatorsAssetFolder = "validators_asset"
|
||||
TypeValidatorsAssetsFolder = "validators_assets"
|
||||
TypeChainsFolder = "chains_folder"
|
||||
TypeDappsFolder = "dapps_folder"
|
||||
TypeRootFolder = "root_folder"
|
||||
TypeValidatorsFolder = "validators_folder"
|
||||
TypeValidatorsAssetFolder = "validators_asset_folder"
|
||||
TypeValidatorsAssetsFolder = "validators_assets_folder"
|
||||
|
||||
TypeUnknown = "unknown"
|
||||
TypeAssetInfoFile = "asset_info_file"
|
||||
TypeAssetLogoFile = "asset_logo_file"
|
||||
TypeChainInfoFile = "chain_info_file"
|
||||
TypeChainLogoFile = "chain_logo_file"
|
||||
TypeTokenListFile = "chain_tokenlist_file"
|
||||
TypeDappsLogoFile = "dapps_logo_file"
|
||||
TypeValidatorsListFile = "validators_list_file"
|
||||
TypeValidatorsLogoFile = "validators_logo_file"
|
||||
|
||||
TypeUnknown = "unknown_file"
|
||||
)
|
||||
|
|
|
@ -16,52 +16,53 @@ func (s *Service) GetValidator(f *file.AssetFile) []Validator {
|
|||
jsonValidator := Validator{Name: "JSON validation", Run: s.ValidateJSON}
|
||||
|
||||
switch f.Type() {
|
||||
case file.TypeRootFolder:
|
||||
case file.TypeAssetFolder:
|
||||
return []Validator{
|
||||
{Name: "Root folder contains only allowed files", Run: s.ValidateRootFolder},
|
||||
{Name: "Each asset folder has valid asset address and contains only allowed files", Run: s.ValidateAssetFolder},
|
||||
}
|
||||
case file.TypeChainFolder:
|
||||
return []Validator{
|
||||
{Name: "Chain folders are lowercase and contains only allowed files", Run: s.ValidateChainFolder},
|
||||
}
|
||||
case file.TypeChainLogoFile, file.TypeAssetLogoFile, file.TypeValidatorsLogoFile, file.TypeDappsLogoFile:
|
||||
return []Validator{
|
||||
{Name: "Logos (size, dimension)", Run: s.ValidateImage},
|
||||
}
|
||||
case file.TypeAssetFolder:
|
||||
return []Validator{
|
||||
{Name: "Each asset folder has valid asset address and contains logo/info", Run: s.ValidateAssetFolder},
|
||||
}
|
||||
case file.TypeDappsFolder:
|
||||
return []Validator{
|
||||
{Name: "Dapps folder (allowed only png files, lowercase)", Run: s.ValidateDappsFolder},
|
||||
}
|
||||
case file.TypeAssetInfoFile:
|
||||
return []Validator{
|
||||
jsonValidator,
|
||||
{Name: "Asset info", Run: s.ValidateAssetInfoFile},
|
||||
}
|
||||
case file.TypeChainInfoFile:
|
||||
return []Validator{
|
||||
{Name: "Chain Info", Run: s.ValidateChainInfoFile},
|
||||
}
|
||||
case file.TypeValidatorsListFile:
|
||||
return []Validator{
|
||||
jsonValidator,
|
||||
{Name: "Validators list file", Run: s.ValidateValidatorsListFile},
|
||||
}
|
||||
case file.TypeTokenListFile:
|
||||
return []Validator{
|
||||
jsonValidator,
|
||||
{Name: "Token list", Run: s.ValidateTokenListFile},
|
||||
}
|
||||
case file.TypeChainInfoFolder:
|
||||
return []Validator{
|
||||
{Name: "Chain Info Folder (has files)", Run: s.ValidateInfoFolder},
|
||||
}
|
||||
case file.TypeDappsFolder:
|
||||
return []Validator{
|
||||
{Name: "Dapps folder contains only allowed png files in lowercase", Run: s.ValidateDappsFolder},
|
||||
}
|
||||
case file.TypeRootFolder:
|
||||
return []Validator{
|
||||
{Name: "Root folder contains only allowed files", Run: s.ValidateRootFolder},
|
||||
}
|
||||
case file.TypeValidatorsAssetFolder:
|
||||
return []Validator{
|
||||
{Name: "Validators asset folder (has logo, valid asset address)", Run: s.ValidateValidatorsAssetFolder},
|
||||
{Name: "Validators asset folder has logo and valid asset address)", Run: s.ValidateValidatorsAssetFolder},
|
||||
}
|
||||
|
||||
case file.TypeAssetLogoFile, file.TypeChainLogoFile, file.TypeDappsLogoFile, file.TypeValidatorsLogoFile:
|
||||
return []Validator{
|
||||
{Name: "Logos size and dimension are valid", Run: s.ValidateImage},
|
||||
}
|
||||
case file.TypeAssetInfoFile:
|
||||
return []Validator{
|
||||
jsonValidator,
|
||||
{Name: "Asset info file is valid", Run: s.ValidateAssetInfoFile},
|
||||
}
|
||||
case file.TypeChainInfoFile:
|
||||
return []Validator{
|
||||
{Name: "Chain info file is valid", Run: s.ValidateChainInfoFile},
|
||||
}
|
||||
case file.TypeTokenListFile:
|
||||
return []Validator{
|
||||
jsonValidator,
|
||||
{Name: "Tokenlist file is valid", Run: s.ValidateTokenListFile},
|
||||
}
|
||||
case file.TypeValidatorsListFile:
|
||||
return []Validator{
|
||||
jsonValidator,
|
||||
{Name: "Validators list file is valid", Run: s.ValidateValidatorsListFile},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,28 +76,28 @@ func (s *Service) GetFixers(f *file.AssetFile) []Fixer {
|
|||
}
|
||||
|
||||
switch f.Type() {
|
||||
case file.TypeChainInfoFile:
|
||||
case file.TypeAssetFolder:
|
||||
return []Fixer{
|
||||
jsonFixer,
|
||||
{Name: "Fixing chain info.json files", Run: s.FixChainInfoJSON},
|
||||
{Name: "Renaming EVM's asset folder to valid address checksum", Run: s.FixETHAddressChecksum},
|
||||
}
|
||||
case file.TypeAssetInfoFile:
|
||||
return []Fixer{
|
||||
jsonFixer,
|
||||
{Name: "Fixing asset info.json files", Run: s.FixAssetInfo},
|
||||
}
|
||||
case file.TypeValidatorsListFile:
|
||||
case file.TypeChainInfoFile:
|
||||
return []Fixer{
|
||||
jsonFixer,
|
||||
}
|
||||
case file.TypeAssetFolder:
|
||||
return []Fixer{
|
||||
{Name: "Renaming EVM's asset folder to valid address checksum", Run: s.FixETHAddressChecksum},
|
||||
{Name: "Fixing chain info.json files", Run: s.FixChainInfoJSON},
|
||||
}
|
||||
case file.TypeChainLogoFile, file.TypeAssetLogoFile, file.TypeValidatorsLogoFile, file.TypeDappsLogoFile:
|
||||
return []Fixer{
|
||||
{Name: "Resizing and compressing logo images", Run: s.FixLogo},
|
||||
}
|
||||
case file.TypeValidatorsListFile:
|
||||
return []Fixer{
|
||||
jsonFixer,
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue
Block a user