Skip to content

Commit

Permalink
added full native token info to chains response
Browse files Browse the repository at this point in the history
  • Loading branch information
1henny committed Jun 8, 2023
1 parent 9695029 commit ef8a835
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 12 deletions.
7 changes: 3 additions & 4 deletions docs/spec/components/schemas/Chain.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ allOf:
- swap_contract_address
- swap_contract_version
- explorer_url
- native_symbol
- native_token
properties:
name:
type: string
Expand Down Expand Up @@ -57,6 +57,5 @@ allOf:
explorer_url:
type: string
example: "https://bscscan.com/"
native_symbol:
type: string
example: "BNB"
native_token:
$ref: '#/components/schemas/NativeTokenInfo'
23 changes: 23 additions & 0 deletions docs/spec/components/schemas/NativeTokenInfo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
type: object
required:
- name
- symbol
- decimals
properties:
name:
type: string
description: |
The name of the token.
example: "Binance Coin"
symbol:
type: string
description: |
The symbol of the token.
example: "BNB"
decimals:
type: integer
format: int64
description: |
The number of decimals the token uses - e.g. 18, means to divide the token amount by 1000000000000000000 to get its user representation.
example: 18

16 changes: 14 additions & 2 deletions internal/services/api/handlers/list_supported_chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func ListSupportedChain(w http.ResponseWriter, r *http.Request) {
}

func chainToResource(chain chains.Chain) resources.Chain {
return resources.Chain{
c := resources.Chain{
Key: resources.Key{
ID: strconv.FormatInt(chain.ID, 10),
Type: resources.CHAINS,
Expand All @@ -83,9 +83,21 @@ func chainToResource(chain chains.Chain) resources.Chain {
SwapContractVersion: string(chain.SwapContractVersion),
Type: chainTypeToResource(chain.Type),
ExplorerUrl: chain.ExplorerURL,
NativeSymbol: chain.NativeSymbol,
},
}

for _, token := range chain.TokensInfo.Tokens {
if token.Native {
c.Attributes.NativeToken = resources.NativeTokenInfo{
Symbol: token.Symbol,
Name: token.Name,
Decimals: token.Decimals,
}
break
}
}

return c
}

func chainKindToResource(kind chains.Kind) resources.ChainKind {
Expand Down
12 changes: 6 additions & 6 deletions resources/model_chain_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ type ChainAttributes struct {
ExplorerUrl string `json:"explorer_url"`
Icon string `json:"icon"`
// The kind of the chain
Kind ChainKind `json:"kind"`
Name string `json:"name"`
NativeSymbol string `json:"native_symbol"`
Rpc string `json:"rpc"`
SwapContractAddress string `json:"swap_contract_address"`
SwapContractVersion string `json:"swap_contract_version"`
Kind ChainKind `json:"kind"`
Name string `json:"name"`
NativeToken NativeTokenInfo `json:"native_token"`
Rpc string `json:"rpc"`
SwapContractAddress string `json:"swap_contract_address"`
SwapContractVersion string `json:"swap_contract_version"`
// The type of the chain
Type ChainType `json:"type"`
}
14 changes: 14 additions & 0 deletions resources/model_native_token_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* GENERATED. Do not modify. Your changes might be overwritten!
*/

package resources

type NativeTokenInfo struct {
// The number of decimals the token uses - e.g. 18, means to divide the token amount by 1000000000000000000 to get its user representation.
Decimals int64 `json:"decimals"`
// The name of the token.
Name string `json:"name"`
// The symbol of the token.
Symbol string `json:"symbol"`
}

0 comments on commit ef8a835

Please sign in to comment.