-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: follow and community token uris
- Loading branch information
1 parent
fc19826
commit fb51bb9
Showing
7 changed files
with
113 additions
and
22 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 |
---|---|---|
@@ -1,5 +1,60 @@ | ||
pub mod CommunityTokenUri { | ||
pub fn get_token_uri(token_id: u256, mint_timestamp: u64) -> ByteArray { | ||
"TODO" | ||
use coloniz::base::utils::byte_array_extra::FeltTryIntoByteArray; | ||
use coloniz::base::utils::base64_extended::get_base64_encode; | ||
use coloniz::base::token_uris::traits::community::community::get_svg_community; | ||
|
||
pub fn get_token_uri(token_id: u256, community_id: u256, timestamp: u64) -> ByteArray { | ||
let baseuri = 'data:image/svg+xml;base64,'; | ||
|
||
let mut svg_byte_array: ByteArray = get_svg_community(token_id, community_id); | ||
let mut svg_encoded: ByteArray = get_base64_encode(svg_byte_array); | ||
|
||
let mut attribute_byte_array: ByteArray = get_attributes( | ||
token_id, ref svg_encoded, community_id, timestamp | ||
); | ||
|
||
let mut token_uri: ByteArray = baseuri.try_into().unwrap(); | ||
token_uri.append(@attribute_byte_array); | ||
token_uri | ||
} | ||
|
||
fn get_attributes( | ||
token_id: u256, ref svg_encoded_byteArray: ByteArray, community_id: u256, timestamp: u64 | ||
) -> ByteArray { | ||
let token_id_to_felt: felt252 = token_id.low.into(); | ||
let community_id_to_felt: felt252 = community_id.low.into(); | ||
let timestamp_to_felt: felt252 = timestamp.try_into().unwrap(); | ||
|
||
let mut attributespre: ByteArray = Default::default(); | ||
let mut attributespost: ByteArray = Default::default(); | ||
|
||
attributespre.append(@"{\"name\":\"Community #"); | ||
attributespre.append(@format!("{}", community_id_to_felt)); | ||
attributespre.append(@"\",\"description\":\" "); | ||
attributespre.append(@"Coloniz - #"); | ||
attributespre.append(@format!("{}", token_id_to_felt)); | ||
attributespre.append(@" of Community "); | ||
attributespre.append(@format!("{}", community_id_to_felt)); | ||
attributespre.append(@"\",\"image\":\"data:image"); | ||
attributespre.append(@"/svg+xml;base64,"); | ||
|
||
//post base64 follow svg | ||
attributespost.append(@"\",\"attributes\":[{\"display"); | ||
attributespost.append(@"_type\":\"number\",\"trait_type"); | ||
attributespost.append(@"\":\"ID\",\"value\":\""); | ||
attributespost.append(@format!("{}", token_id_to_felt)); | ||
attributespost.append(@"\"},{\"trait_type\":\"mint"); | ||
attributespost.append(@"_timestamp\",\"value\":\""); | ||
attributespost.append(@format!("{}", timestamp_to_felt)); | ||
attributespost.append(@"\"},{\"trait_type\":\"community"); | ||
attributespost.append(@"_id\",\"value\":\""); | ||
attributespost.append(@format!("{}", community_id_to_felt)); | ||
attributespost.append(@"\"}]}"); | ||
|
||
attributespre.append(@svg_encoded_byteArray); | ||
attributespre.append(@attributespost); | ||
|
||
get_base64_encode(attributespre) | ||
} | ||
} | ||
|
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod color; | ||
pub mod handle; | ||
pub mod follow; | ||
pub mod community; |
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
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,43 @@ | ||
pub mod community { | ||
use coloniz::base::utils::byte_array_extra::FeltTryIntoByteArray; | ||
use coloniz::base::token_uris::traits::color::colonizColors::get_random_color; | ||
|
||
pub fn get_svg_community(token_id: u256, community_id: u256) -> ByteArray { | ||
let mut svg: ByteArray = Default::default(); | ||
|
||
let color_code: ByteArray = get_random_color(token_id).try_into().unwrap(); | ||
|
||
/// construct the SVG as ByteArray | ||
svg | ||
.append( | ||
@"<svg width=\"300\" height=\"300\" viewBox=\"0 0 300 300\" xmlns=\"http://www.w3.org/2000/svg\"> | ||
<rect width=\"300\" height=\"300\" fill=\"white\"/> | ||
<circle cx=\"150\" cy=\"150\" r=\"60\" fill=\"" | ||
); | ||
|
||
svg.append(@color_code); | ||
|
||
svg | ||
.append( | ||
@"\" stroke=\"black\" stroke-width=\"4\"/> | ||
<circle cx=\"90\" cy=\"120\" r=\"15\" fill=\"black\" stroke=\"black\" stroke-width=\"3\"/> | ||
<circle cx=\"210\" cy=\"120\" r=\"15\" fill=\"black\" stroke=\"black\" stroke-width=\"3\"/> | ||
<circle cx=\"120\" cy=\"200\" r=\"15\" fill=\"black\" stroke=\"black\" stroke-width=\"3\"/> | ||
<circle cx=\"180\" cy=\"200\" r=\"15\" fill=\"black\" stroke=\"black\" stroke-width=\"3\"/> | ||
<line x1=\"150\" y1=\"150\" x2=\"90\" y2=\"120\" stroke=\"black\" stroke-width=\"3\"/> | ||
<line x1=\"150\" y1=\"150\" x2=\"210\" y2=\"120\" stroke=\"black\" stroke-width=\"3\"/> | ||
<line x1=\"150\" y1=\"150\" x2=\"120\" y2=\"200\" stroke=\"black\" stroke-width=\"3\"/> | ||
<line x1=\"150\" y1=\"150\" x2=\"180\" y2=\"200\" stroke=\"black\" stroke-width=\"3\"/> | ||
<text x=\"50%\" y=\"270\" font-family=\"Arial\" font-size=\"22\" fill=\"black\" text-anchor=\"middle\" font-weight=\"bold\">COMMUNITY # | ||
" | ||
); | ||
|
||
let community_id_to_felt = community_id.into(); | ||
svg.append(@format!("{}", community_id_to_felt)); | ||
|
||
svg.append(@"</text> | ||
</svg>"); | ||
|
||
svg | ||
} | ||
} |
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
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