Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preview field to JettonInfo #551

Merged
merged 4 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3739,6 +3739,10 @@
"example": true,
"type": "boolean"
},
"preview": {
"example": "https://cache.tonapi.io/images/jetton.jpg",
"type": "string"
},
"total_supply": {
"example": "5887105890579978",
"type": "string",
Expand All @@ -3753,7 +3757,8 @@
"total_supply",
"metadata",
"verification",
"holders_count"
"holders_count",
"preview"
],
"type": "object"
},
Expand Down Expand Up @@ -3787,7 +3792,8 @@
"type": "string"
},
"image": {
"example": "https://cache.tonapi.io/images/jetton.jpg",
"description": "this field currently returns a cached image URL (e.g., \"https://cache.tonapi.io/images/jetton.jpg\"). In the future, this will be replaced with the original URL from the metadata. The cached image is already available in the `preview` field of `JettonInfo` and will remain there.",
"example": "https://bitcoincash-example.github.io/website/logo.png",
"type": "string"
},
"name": {
Expand Down
7 changes: 6 additions & 1 deletion api/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6900,7 +6900,8 @@ components:
example: "9"
image:
type: string
example: "https://cache.tonapi.io/images/jetton.jpg"
example: "https://bitcoincash-example.github.io/website/logo.png"
description: this field currently returns a cached image URL (e.g., "https://cache.tonapi.io/images/jetton.jpg"). In the future, this will be replaced with the original URL from the metadata. The cached image is already available in the `preview` field of `JettonInfo` and will remain there.
description:
type: string
example: Wrapped Toncoin
Expand Down Expand Up @@ -6972,6 +6973,7 @@ components:
- metadata
- verification
- holders_count
- preview
properties:
mintable:
type: boolean
Expand All @@ -6984,6 +6986,9 @@ components:
$ref: '#/components/schemas/AccountAddress'
metadata:
$ref: '#/components/schemas/JettonMetadata'
preview:
type: string
example: "https://cache.tonapi.io/images/jetton.jpg"
verification:
$ref: '#/components/schemas/JettonVerificationType'
holders_count:
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/jetton_converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func jettonPreview(master ton.AccountID, meta NormalizedMetadata) oas.JettonPrev
Symbol: meta.Symbol,
Verification: oas.JettonVerificationType(meta.Verification),
Decimals: meta.Decimals,
Image: meta.Image,
Image: meta.PreviewImage,
}
if meta.CustomPayloadApiUri != "" {
preview.CustomPayloadAPIURI = oas.NewOptString(meta.CustomPayloadApiUri)
Expand Down Expand Up @@ -178,5 +178,6 @@ func (h *Handler) convertJettonInfo(ctx context.Context, master core.JettonMaste
Verification: oas.JettonVerificationType(meta.Verification),
HoldersCount: holders[master.Address],
Admin: convertOptAccountAddress(master.Admin, h.addressBook),
Preview: meta.PreviewImage,
}
}
1 change: 1 addition & 0 deletions pkg/api/jetton_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (h *Handler) GetJettonInfo(ctx context.Context, params oas.GetJettonInfoPar
Verification: oas.JettonVerificationType(meta.Verification),
HoldersCount: holdersCount[account.ID],
Admin: convertOptAccountAddress(data.Admin, h.addressBook),
Preview: meta.PreviewImage,
}, nil
}

Expand Down
11 changes: 7 additions & 4 deletions pkg/api/normalized_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type NormalizedMetadata struct {
Social []string
Websites []string
CustomPayloadApiUri string
PreviewImage string // path to the converted image
}

func NormalizeMetadata(meta tep64.Metadata, info *addressbook.KnownJetton, trust core.TrustType) NormalizedMetadata {
Expand All @@ -41,7 +42,7 @@ func NormalizeMetadata(meta tep64.Metadata, info *addressbook.KnownJetton, trust
if name == "" {
name = "Unknown Token"
}
image := references.Placeholder
var image string
if meta.Image != "" {
image = meta.Image
}
Expand All @@ -57,19 +58,21 @@ func NormalizeMetadata(meta tep64.Metadata, info *addressbook.KnownJetton, trust
websites = info.Websites
trust = core.TrustWhitelist
}

image = imgGenerator.DefaultGenerator.GenerateImageUrl(image, 200, 200)
previewImage := references.Placeholder
previewImage = rewriteIfNotEmpty(previewImage, image)
previewImage = imgGenerator.DefaultGenerator.GenerateImageUrl(previewImage, 200, 200)

return NormalizedMetadata{
Name: name,
Description: description,
Image: image,
Image: previewImage, // TODO: replace with `image` after migration to `previewImage`
Symbol: symbol,
Decimals: convertJettonDecimals(meta.Decimals),
Verification: trust,
Social: social,
Websites: websites,
CustomPayloadApiUri: meta.CustomPayloadAPIURL,
PreviewImage: previewImage,
}
}

Expand Down
29 changes: 23 additions & 6 deletions pkg/oas/oas_json_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 18 additions & 4 deletions pkg/oas/oas_schemas_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading