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

Airdrop Link Backend Integration #513

Closed
wants to merge 13 commits into from
Closed
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
6 changes: 3 additions & 3 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions ssr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ firestore = { version = "0.43.1", default-features = false, features = [
], optional = true }
speedate = { version = "0.14.4", optional = true }
urlencoding = "2.1.3"
yral-types = { git = "https://github.com/yral-dapp/yral-common.git", rev = "2e432882052a69d5a625e7188cd69ad8aa5bcec7" }
yral-qstash-types = { git = "https://github.com/yral-dapp/yral-common.git", rev = "2e432882052a69d5a625e7188cd69ad8aa5bcec7" }
yral-canisters-client = { git = "https://github.com/yral-dapp/yral-common.git", rev = "2e432882052a69d5a625e7188cd69ad8aa5bcec7", features = ["full"] }
yral-types = { git = "https://github.com/yral-dapp/yral-common.git", rev = "2dd7bbcedd3a0faa947c1393f7791608f1b66117" }
yral-qstash-types = { git = "https://github.com/yral-dapp/yral-common.git", rev = "2dd7bbcedd3a0faa947c1393f7791608f1b66117" }
yral-canisters-client = { git = "https://github.com/yral-dapp/yral-common.git", rev = "2dd7bbcedd3a0faa947c1393f7791608f1b66117", features = ["full"] }
pulldown-cmark = "0.12.1"
ic-certification = "2.6.0"
ciborium = "0.2.2"
Expand Down
14 changes: 7 additions & 7 deletions ssr/src/component/auth_providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ mod server_fn_impl {
use leptos::ServerFnError;

use crate::state::canisters::unauth_canisters;
use yral_canisters_client::individual_user_template::KnownPrincipalType;
use yral_canisters_client::individual_user_template::{
KnownPrincipalType, Result13, Result25,
};

pub async fn issue_referral_rewards_impl(
referee_canister: Principal,
Expand Down Expand Up @@ -270,24 +272,22 @@ mod server_fn_impl {
user_canister: Principal,
) -> Result<bool, ServerFnError> {
use crate::state::admin_canisters::admin_canisters;
use yral_canisters_client::individual_user_template::{
Result12, Result23, SessionType,
};
use yral_canisters_client::individual_user_template::SessionType;

let admin_cans = admin_canisters();
let user = admin_cans.individual_user_for(user_canister).await;
if matches!(
user.get_session_type().await?,
Result12::Ok(SessionType::RegisteredSession)
Result13::Ok(SessionType::RegisteredSession)
) {
return Ok(false);
}
user.update_session_type(SessionType::RegisteredSession)
.await
.map_err(ServerFnError::from)
.and_then(|res| match res {
Result23::Ok(_) => Ok(()),
Result23::Err(e) => Err(ServerFnError::new(format!(
Result25::Ok(_) => Ok(()),
Result25::Err(e) => Err(ServerFnError::new(format!(
"failed to mark user as registered {e}"
))),
})?;
Expand Down
6 changes: 3 additions & 3 deletions ssr/src/page/profile/profile_iter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use candid::Principal;
use futures::stream::{FuturesOrdered, StreamExt, TryStreamExt};
use yral_canisters_client::individual_user_template::{GetPostsOfUserProfileError, Result11};
use yral_canisters_client::individual_user_template::{GetPostsOfUserProfileError, Result12};

use crate::{
state::canisters::Canisters,
Expand Down Expand Up @@ -70,15 +70,15 @@ impl<const LIMIT: u64> ProfVideoStream<LIMIT> for ProfileVideoStream<LIMIT> {
.get_posts_of_this_user_profile_with_pagination_cursor(cursor.start, cursor.limit)
.await?;
match posts {
Result11::Ok(v) => {
Result12::Ok(v) => {
let end = v.len() < LIMIT as usize;
let posts = v
.into_iter()
.map(|details| PostDetails::from_canister_post(AUTH, user_canister, details))
.collect::<Vec<_>>();
Ok(PostsRes { posts, end })
}
Result11::Err(GetPostsOfUserProfileError::ReachedEndOfItemsList) => Ok(PostsRes {
Result12::Err(GetPostsOfUserProfileError::ReachedEndOfItemsList) => Ok(PostsRes {
posts: vec![],
end: true,
}),
Expand Down
9 changes: 4 additions & 5 deletions ssr/src/page/refer_earn/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ mod history_provider {
mod canister {
use super::*;
use ic_agent::AgentError;
use yral_canisters_client::individual_user_template::Result16;

#[derive(Clone)]
pub struct ReferralHistory(pub Canisters<true>);
Expand All @@ -113,9 +114,7 @@ mod history_provider {
end: usize,
) -> Result<PageEntry<HistoryDetails>, AgentError> {
use crate::utils::route::failure_redirect;
use yral_canisters_client::individual_user_template::{
MintEvent, Result15, TokenEvent,
};
use yral_canisters_client::individual_user_template::{MintEvent, TokenEvent};
let individual = self.0.authenticated_user().await;
let history = individual
.get_user_utility_token_transaction_history_with_pagination(
Expand All @@ -124,8 +123,8 @@ mod history_provider {
)
.await?;
let history = match history {
Result15::Ok(history) => history,
Result15::Err(_) => {
Result16::Ok(history) => history,
Result16::Err(_) => {
failure_redirect("failed to get posts");
return Ok(PageEntry {
data: vec![],
Expand Down
116 changes: 111 additions & 5 deletions ssr/src/page/token/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ use crate::{
page::wallet::{transactions::Transactions, txn::IndexOrLedger},
utils::{token::TokenMetadata, web::copy_to_clipboard},
};
use candid::Nat;
use candid::Principal;
use leptos::*;
use leptos_icons::*;
use leptos_router::*;
use serde::{Deserialize, Serialize};
use yral_canisters_client::individual_user_template::AirdropError;
use yral_canisters_client::individual_user_template::Result21;

#[component]
fn TokenField(
Expand Down Expand Up @@ -172,14 +175,20 @@ fn TokenInfoInner(
pub struct TokenKeyParam {
key_principal: Principal,
}

#[derive(Params, PartialEq, Clone, Serialize, Deserialize)]
pub struct AirdropAmount {
airdrop_amt: u64,
}
#[component]
pub fn TokenInfo() -> impl IntoView {
let params = use_params::<TokenInfoParams>();
let airdrop_param = use_query::<AirdropAmount>();
let key_principal = use_params::<TokenKeyParam>();
let key_principal = move || key_principal.with(|p| p.as_ref().map(|p| p.key_principal).ok());
let token_metadata_fetch = authenticated_canisters().derive(
move || (params(), key_principal()),
move |cans_wire, (params, key_principal)| async move {
move || (params(), key_principal(), airdrop_param()),
move |cans_wire, (params, key_principal, airdrop_param)| async move {
let Ok(params) = params else {
return Ok::<_, ServerFnError>(None);
};
Expand All @@ -189,39 +198,136 @@ pub fn TokenInfo() -> impl IntoView {
.token_root
.get_metadata(key_principal, cans.clone())
.await;

let mut airdrop_res: Option<(String, u64)> = None;
if let Some(key_principal) = key_principal {
if let Ok(airdrop_amt) = airdrop_param {
if let RootType::Other(root) = params.token_root {
let user = cans
.get_individual_canister_by_user_principal(key_principal)
.await?;
let user = cans.individual_user(user.unwrap()).await;

let res = user
.request_airdrop(
root,
None,
Into::<Nat>::into(airdrop_amt.airdrop_amt)
* 10u64.pow(
meta.as_ref()
.ok_or(ServerFnError::new(
"Failed to get metadata to extract decimals",
))?
.decimals
.into(),
),
cans.user_canister(),
)
.await?;

airdrop_res = match res {
Result21::Ok => {
let user = cans.individual_user(cans.user_canister()).await;
user.add_token(root).await?;
Some((
"Airdrop Claimed Successfully!".to_string(),
airdrop_amt.airdrop_amt,
))
}
Result21::Err(AirdropError::NoBalance) => Some((
"Airdrops Cannot be Claimed...".to_string(),
airdrop_amt.airdrop_amt,
)),
_ => None,
};
}
}
}

Ok(meta.map(|m| {
(
m,
params.token_root,
key_principal,
Some(cans.user_principal()) == key_principal,
airdrop_res,
)
}))
},
);

let (airdrop, set_airdrop) = create_signal(true);
view! {
<Suspense fallback=FullScreenSpinner>
{move || {
token_metadata_fetch()
.and_then(|info| info.ok())
.map(|info| {
match info {
Some((metadata, root, key_principal, is_user_principal)) => {
Some((metadata, root, key_principal, is_user_principal, res)) => {

view! {
{
res.map(|(airdrop_status, amt)|{
if airdrop.get(){
Some(
view! {
<AirdropPopup airdrop_status metadata=metadata.clone() toggle_signal=set_airdrop amt/>
}
)
}else{
None
}
})
}
<TokenInfoInner
root
key_principal
meta=metadata
is_user_principal=is_user_principal
/>
}

}.into_view()
}
None => view! { <Redirect path="/" /> },
None => view! { <Redirect path="/" /> }.into_view(),
}
})
}}

</Suspense>
}
}
#[component]
fn AirdropPopup(
airdrop_status: String,
metadata: TokenMetadata,
amt: u64,
toggle_signal: WriteSignal<bool>,
) -> impl IntoView {
view! {
// Wrapper div to center the popup
<div class="fixed inset-0 flex items-center justify-center bg-black/75 z-[69]" on:click=move |_| toggle_signal(false)>
<div class="w-[315px] h-[263px] px-[30px] py-[62px] bg-[#191919] rounded-sm flex flex-col justify-start items-center gap-4 relative">

// Cancel button in the top right corner
<button class="absolute top-3 right-3 text-white" on:click=move |_| toggle_signal(false)>
<div class="rounded-xl hover:bg-white/10 p-1">
<Icon class="text-sm text-white" icon=icondata::AiCloseOutlined />
</div>
</button>

<div class="flex justify-center items-center">
<img class="w-[84px] h-[83px] rounded-full shadow" src={metadata.logo_b64} />
</div>
<div class="self-stretch text-center">
<span class="text-white text-xl font-bold font-['Kumbh Sans'] leading-[30px]">
{format!("{} {}", amt, metadata.symbol)} <br/>
</span>
<span class="text-[#1ec981] text-xl font-bold font-['Kumbh Sans'] leading-[30px]">
{airdrop_status}
</span>
</div>
</div>
</div>
}
}
6 changes: 3 additions & 3 deletions ssr/src/page/wallet/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
};
use futures::stream::{self, StreamExt};
use leptos::*;
use yral_canisters_client::individual_user_template::Result14;
use yral_canisters_client::individual_user_template::Result15;
use yral_canisters_client::sns_ledger::{Account, SnsLedger};
#[derive(Clone)]
pub struct TokenRootList {
Expand Down Expand Up @@ -65,11 +65,11 @@ impl CursoredDataProvider for TokenRootList {
.get_token_roots_of_this_user_with_pagination_cursor(start as u64, end as u64)
.await?;
let mut tokens: Vec<RootType> = match tokens {
Result14::Ok(v) => v
Result15::Ok(v) => v
.into_iter()
.map(|t| RootType::from_str(&t.to_text()).unwrap())
.collect(),
Result14::Err(_) => vec![],
Result15::Err(_) => vec![],
};
let list_end = tokens.len() < (end - start);
if start == 0 {
Expand Down
6 changes: 3 additions & 3 deletions ssr/src/state/canisters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use yral_metadata_client::MetadataClient;
use yral_metadata_types::UserMetadata;

use yral_canisters_client::{
individual_user_template::{IndividualUserTemplate, Result23, Result7, UserCanisterDetails},
individual_user_template::{IndividualUserTemplate, Result25, Result7, UserCanisterDetails},
platform_orchestrator::PlatformOrchestrator,
post_cache::PostCache,
sns_governance::SnsGovernance,
Expand Down Expand Up @@ -310,8 +310,8 @@ pub async fn do_canister_auth(
.await
.map_err(|e| e.to_string())
{
Ok(Result23::Ok(_)) => (),
Err(e) | Ok(Result23::Err(e)) => log::warn!("Failed to update last access time: {}", e),
Ok(Result25::Ok(_)) => (),
Err(e) | Ok(Result25::Err(e)) => log::warn!("Failed to update last access time: {}", e),
}
let profile_details = user.get_profile_details().await?.into();

Expand Down
6 changes: 3 additions & 3 deletions ssr/src/utils/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use leptos::{RwSignal, SignalUpdateUntracked};
use serde::{Deserialize, Serialize};

use yral_canisters_client::individual_user_template::{
BetDirection, BetOutcomeForBetMaker, PlacedBetDetail, Result11, UserProfileDetailsForFrontend,
BetDirection, BetOutcomeForBetMaker, PlacedBetDetail, Result12, UserProfileDetailsForFrontend,
};

use crate::{
Expand Down Expand Up @@ -226,8 +226,8 @@ impl CursoredDataProvider for PostsProvider {
.get_posts_of_this_user_profile_with_pagination_cursor(start as u64, limit as u64)
.await?;
let posts = match posts {
Result11::Ok(v) => v,
Result11::Err(_) => {
Result12::Ok(v) => v,
Result12::Err(_) => {
log::warn!("failed to get posts");
return Ok(PageEntry {
data: vec![],
Expand Down
Loading