Skip to content

Commit

Permalink
token uri for profile
Browse files Browse the repository at this point in the history
  • Loading branch information
mubarak23 committed Jul 26, 2024
1 parent 2afd3ed commit 833797f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
32 changes: 31 additions & 1 deletion src/base/token_uris/token_uris.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,37 @@ mod TokenURIComponent {
fn profile_get_token_uri(
token_id: u256, mint_timestamp: u64, profile: Profile
) -> ByteArray {
"TODO"
let mut encoded_inner: Bytes = BytesTrait::new(0, array![]);
let profile_svg_example =
'<svg xmlns="http://www.w3.org/2000/svg" width="210" height="335" fill="none"><path fill="url(#a)" d="M143.3 104.8c-.8.8-2.2.3-2.2-.9v-3.3c-1.3-46.1-71-46.1-72.2 0v3.3c0 1.1-1.4 1.7-2.2 1a145 145 0 0 0-2.4-2.4c-33.6-31.7-82.8 17.4-51 50.9l2.3 2.4A138.4 138.4 0 0 0 105 194s51 0 89.4-38.2l2.4-2.4c31.7-33.5-17.5-82.6-51-51l-2.5 2.4Z"/><circle cx="4" cy="4" r="4" fill="#fff" fill-opacity=".5" transform="matrix(-1 0 0 1 199.3 126)"/><path fill="#fff" fill-opacity=".5" d="M195.5 117.5a5 5 0 0 1-9 4 6.7 6.7 0 0 0-.3-.7l-1.2-2c-1-1.7-2.3-3.5-3.6-4.6-1.5-1.2-2.6-2-3.7-2.5l-1.7-.8a3 3 0 0 1-1.4-4l.1-.3c.8-1.5 0-3.3-1.5-3.5-1.9-.3-3.4-.3-5-.2h-.1a1.8 1.8 0 0 1-.3-3.5 23.6 23.6 0 0 1 16.6 4.8c1 .7 2.2 1.5 3.3 2.5a29.2 29.2 0 0 1 7.7 10.4v.3h.1"/><path stroke="#000" stroke-linecap="square" stroke-linejoin="round" stroke-width="4" d="M143.3 104.8v0c-.8.8-2.2.3-2.2-.9v0-3.3c-1.3-46.1-71-46.1-72.2 0v3.3c0 1.1-1.4 1.7-2.2 1v0a145 145 0 0 0-2.4-2.4c-33.6-31.7-82.8 17.4-51 50.9l2.3 2.4A138.4 138.4 0 0 0 105 194s51 0 89.4-38.2l2.4-2.4c31.7-33.5-17.5-82.6-51-51l-2.5 2.4Z"/><defs><radialGradient id="a" cx="0" cy="0" r="1" gradientTransform="matrix(0 128 -204 0 105 66)" gradientUnits="userSpaceOnUse"><stop stop-color="#FFDB76"/><stop offset="1" stop-color="#F8C944"/></radialGradient></defs></svg>';
let json = format!(
"{{\"name\":\"Profile #{}\",\"description\":\"Karst Protocol - Profile #{}\",\"image\":\"data:image/svg+xml;base64,{}",
profile.metadata_URI.into(),
profile.profile_owner,
encoded_inner.encode_packed(profile_svg_example)
);

let mut encoded: Bytes = BytesTrait::new(0, array![]);
let mut encoded_empty: Bytes = BytesTrait::new_empty();

return format!(
"data:application/json;base64,",
encoded
.encode_packed(
encoded_empty(
format!(
{},
{},
{},
{},
json,
profile.profile_owner,
byte(profile.profile_owner.into()),
mint_timestamp
)
)
)
);
}
fn handle_get_token_uri(
token_id: u256, local_name: felt252, namespace: felt252
Expand Down
13 changes: 6 additions & 7 deletions src/interfaces/ITokenURI.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ use starknet::ContractAddress;
// INTERFACE of TOKEN URI
// *************************************************************************
#[starknet::interface]
pub trait ITokenURI<TState>{
fn profile_get_token_uri(token_id: u256, mint_timestamp: u64, profile: Profile) -> ByteArray;
pub trait ITokenURI<TState> {
fn profile_get_token_uri(token_id: u256, mint_timestamp: u64, profile: Profile) -> ByteArray;

fn handle_get_token_uri(token_id: u256, local_name: felt252, namespace: felt252) -> ByteArray;
fn handle_get_token_uri(token_id: u256, local_name: felt252, namespace: felt252) -> ByteArray;

fn follow_get_token_uri(
fn follow_get_token_uri(
follow_token_id: u256, followed_profile_address: ContractAddress, follow_timestamp: u64
) -> ByteArray

}
) -> ByteArray;
}
11 changes: 5 additions & 6 deletions src/karstnft/karstnft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub mod KarstNFT {
use karst::interfaces::IKarstNFT;
use karst::base::{
utils::hubrestricted::HubRestricted::hub_only, constants::errors::Errors::ALREADY_MINTED,
// token_uris::profile_token_uri::ProfileTokenUri,
// token_uris::profile_token_uri::ProfileTokenUri,
};
use openzeppelin::{
account, access::ownable::OwnableComponent,
Expand All @@ -52,10 +52,10 @@ pub mod KarstNFT {
introspection::{src5::SRC5Component}
};


use karst::base::token_uris::token_uris::TokenURIComponent;
component!(path: TokenURIComponent, storage: token_uri, event: TokenUriEvent);

use karst::profile::profile::ProfileComponent;
component!(path: ProfileComponent, storage: profile, event: ProfileEvent);

Expand Down Expand Up @@ -120,7 +120,7 @@ pub mod KarstNFT {
#[flat]
OwnableEvent: OwnableComponent::Event,
#[flat]
ProfileEvent: ProfileComponent::Event
ProfileEvent: ProfileComponent::Event,
#[flat]
TokenUriEvent: TokenURIComponent::Event
}
Expand Down Expand Up @@ -198,8 +198,7 @@ pub mod KarstNFT {
let profile = self.profile.get_profile(get_caller_address());

// call token uri component
self.token_uri.profile_get_token_uri(token_id, mint_timestamp, profile);

self.token_uri.profile_get_token_uri(token_id, mint_timestamp, profile);
}
}
}

0 comments on commit 833797f

Please sign in to comment.