Skip to content
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

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

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

73 changes: 73 additions & 0 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ pub struct LeaderboardRecord {
distance: i32,
}

#[derive(SimpleObject, Clone)]
pub struct NextShipTokenName {
ship_name: String,
pilot_name: String,
}

#[derive(SimpleObject, Clone)]
pub struct LatestSlotNumber {
slot: i32,
}

#[derive(Union)]
pub enum MapObject {
Ship(Ship),
Expand Down Expand Up @@ -567,6 +578,68 @@ impl QueryRoot {

Ok(map_objects)
}

async fn next_ship_token_name(
&self,
ctx: &Context<'_>,
spacetime_address: String,
spacetime_policy_id: String,
) -> Result<NextShipTokenName, Error> {
let pool = ctx
.data::<sqlx::PgPool>()
.map_err(|e| Error::new(e.message))?;

let fetched_objects = sqlx::query!(
"
SELECT
CAST(REPLACE(CAST(utxo_plutus_data(era, cbor) -> 'fields' -> 2 ->> 'bytes' AS TEXT), '53484950', '') AS INTEGER) AS ship_number
FROM
utxos
WHERE
utxo_address(era, cbor) = from_bech32($1::varchar) AND utxo_has_policy_id(era, cbor, decode($2::varchar, 'hex'))
ORDER BY ship_number DESC
LIMIT 1
",
spacetime_address,
spacetime_policy_id,
)
.fetch_all(pool)
.await
.map_err(|e| Error::new(e.to_string()))?;

let ship_number_encoded = fetched_objects
.get(0)
.and_then(|r| r.ship_number.clone())
.unwrap_or_default();

let ship_number = String::from_utf8(hex::decode(format!("{}", ship_number_encoded))?)?.parse::<i32>().unwrap_or_default() + 1;

Ok(NextShipTokenName {
ship_name: format!("SHIP{}", ship_number),
pilot_name: format!("PILOT{}", ship_number),
})
}

async fn last_slot(
&self,
ctx: &Context<'_>,
) -> Result<LatestSlotNumber, Error> {
let pool = ctx
.data::<sqlx::PgPool>()
.map_err(|e| Error::new(e.message))?;

let fetched_objects = sqlx::query!("SELECT slot FROM blocks ORDER BY slot DESC LIMIT 1")
.fetch_all(pool)
.await
.map_err(|e| Error::new(e.to_string()))?;

let slot = fetched_objects
.get(0)
.and_then(|r| Some(r.slot.clone()))
.unwrap_or_default();

Ok(LatestSlotNumber { slot })
}
}

type AsteriaSchema = Schema<QueryRoot, EmptyMutation, EmptySubscription>;
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.frontend
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ENV PREVIEW_API_URL=https://8000-skillful-employee-kb9ou6.us1.demeter.run
ENV MAINNET_API_URL=https://8000-ethereal-audience-bb83g6.us1.demeter.run

ENV PREVIEW_TRP_URL=https://cardano-preview.trp-m1.demeter.run
ENV PREVIEW_TRP_API_KEY=trp1ffyf88ugcyg6j6n3yuh
ENV PREVIEW_TRP_API_KEY=trpjodqbmjblunzpbikpcrl

ENV MAINNET_TRP_URL=https://cardano-mainnet.trp-m1.demeter.run
ENV MAINNET_TRP_API_KEY=trp1lrnhzcax5064cgxsaup
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/home/ChallengeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default function ChallengeCard({ comingSoon, image, day, month, name, net
onClick={!comingSoon ? onSelect : undefined}
disabled={comingSoon || !onSelect}
>
{comingSoon ? 'Coming Soon' : 'Explore'}
{comingSoon ? 'Coming Soon' : onSelect ? 'Select' : 'Selected' }
</button>

{sponsors && sponsors.length > 0 && (
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/home/HeroSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ export default function HeroSection() {
<span>Build your own bot</span>
<BotIcon />
</Link>
<Link href="/how-to-play" className="btn btn-primary-outline w-fit">
{/* <Link href="/how-to-play" className="btn btn-primary-outline w-fit">
<GamepadIcon />
<span>How to play</span>
</Link>
</Link> */}
</div>
</div>

Expand Down
10 changes: 9 additions & 1 deletion frontend/src/components/ui/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@ const NavBar: React.FunctionComponent = () => {
</span>
</div>
<div className="flex flex-row items-center flex-initial">
<Link href="/how-to-play" data-active={isActive('how-to-play')} className="font-mono py-2 px-4 rounded-full mx-4 text-[#F1E9D9] data-active:text-[#FFF75D]">
{/* <Link href="/how-to-play" data-active={isActive('how-to-play')} className="font-mono py-2 px-4 rounded-full mx-4 text-[#F1E9D9] data-active:text-[#FFF75D]">
How to play
</Link> */}
<Link
href="https://github.com/txpipe/asteria-starter-kit"
target="_blank"
rel="noopener noreferrer"
className="font-mono py-2 px-4 rounded-full mx-4 text-[#F1E9D9] data-active:text-[#FFF75D]"
>
Starter Kit
</Link>
<span className="border-l border-l-solid border-l-[#F1E9D9] w-0 h-7 opacity-50" />
<Link href="/explorer" data-active={isActive('explorer')} className="font-mono py-2 px-4 rounded-full mx-4 text-[#F1E9D9] data-active:text-[#FFF75D]">
Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/challenge/mainnet-challenge.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ export default ({ children }) => <Layout>{children}</Layout>;
| Asteria | `addr1w824uvev63kj40lzfhaq2kxzmmwsz9xsqsjr2t4cq74vzdcdw8c77` | `d55e332cd46d2abfe24dfa0558c2dedd0114d00424352eb807aac137` |
| Pellet | `addr1wya6hnluvypwcfww6s8p5f8m5gphryjugmcznxetj3trvrsc307jj` | `3babcffc6102ec25ced40e1a24fba20371925c46f0299b2b9456360e` |
| Spacetime | `addr1wypfrtn6awhsvjmc24pqj0ptzvtfalang33rq8ng6j6y7scnlkytx` | `0291ae7aebaf064b785542093c2b13169effb34462301e68d4b44f43` |
| Admin | | `db0d968cda2cc636b28c0f377e66691a065b8004e57be5129aeef822` |
16 changes: 8 additions & 8 deletions frontend/src/pages/leaderboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const getShipByAddress = (address: string): string => {
}

const LeaderboardChip: React.FunctionComponent<RecordProps> = (props: RecordProps) => (
<a href={`${props.challenge.explorerUrl}${props.record.address.replace('#0', '')}`} target="_blank">
<a href={`${props.challenge.explorerUrl}${props.record.address}`} target="_blank">
<div className="flex-initial flex flex-row items-center mx-4 pl-8 pr-6 py-4 rounded-full bg-linear-to-r from-[#46434312] to-[#FFFFFF12]">
<h1 className="flex-initial pb-1 mr-6 font-mono text-5xl text-[#07F3E6]">
{props.record.ranking}
Expand Down Expand Up @@ -88,10 +88,10 @@ const LeaderboardRow: React.FunctionComponent<RecordProps> = (props: RecordProps
<img className="inline mr-4 w-8 h-8" src={getShipByAddress(props.record.address)} />
<a
className="text-[#07F3E6] underline"
href={`${props.challenge.explorerUrl}${props.record.address.replace('#0', '')}`}
href={`${props.challenge.explorerUrl}${props.record.address}`}
target="_blank"
>
{props.record.address.replace('#0', '')}
{props.record.address}
</a>
</td>
<td className="p-4 text-[#D7D7D7] text-left border border-[#333333]">
Expand Down Expand Up @@ -129,7 +129,7 @@ export function Leaderboard() {

const hasNextPage = () => {
if (leaderboard) {
return data && data.leaderboardPlayers && offset + PAGE_SIZE < data.leaderboardPlayers.slice(3).length;
return data && data.leaderboardPlayers && offset + PAGE_SIZE < data.leaderboardPlayers.length;
} else {
return data && data.leaderboardWinners && offset + PAGE_SIZE < data.leaderboardWinners.length;
}
Expand All @@ -153,7 +153,7 @@ export function Leaderboard() {

const getPagination = () => {
if (leaderboard) {
return `Displaying ${offset+1}-${offset+PAGE_SIZE} of ${data && data.leaderboardPlayers ? data.leaderboardPlayers.length-3 : 0}`;
return `Displaying ${offset+1}-${offset+PAGE_SIZE} of ${data && data.leaderboardPlayers ? data.leaderboardPlayers.length : 0}`;
} else {
return `Displaying ${offset+1}-${offset+PAGE_SIZE} of ${data && data.leaderboardWinners ? data.leaderboardWinners.length : 0}`;
}
Expand All @@ -162,7 +162,7 @@ export function Leaderboard() {
const getPageData = () => {
if (leaderboard) {
if (!data || !data.leaderboardPlayers) return [];
return data.leaderboardPlayers.slice(3).slice(offset, offset+PAGE_SIZE);
return data.leaderboardPlayers.slice(offset, offset+PAGE_SIZE);
} else {
if (!data || !data.leaderboardWinners) return [];
return data.leaderboardWinners.slice(offset, offset+PAGE_SIZE);
Expand All @@ -186,14 +186,14 @@ export function Leaderboard() {
{`ASTERIA ${ leaderboard ? 'PLAYERS' : 'WINNERS' } >`}
</span>
</h1>
<input
{/* <input
type="text"
placeholder="Type your ADDRESS / SHIP NAME"
className="form-input flex-initial basis-2/5 mr-6 px-6 py-4 rounded-3xl bg-[#242424] border-transparent focus:border-[#919090] text-[#919090] focus:ring-0"
/>
<button className="flex-initial font-mono text-black bg-[#07F3E6] py-4 px-8 rounded-full text-base">
Find me
</button>
</button> */}
</div>

{leaderboard && (
Expand Down
Loading