heavy-duty / znap

Performance-first Rust Framework to build APIs compatible with the Solana Actions Spec.
Apache License 2.0
60 stars 1 forks source link

Shorthand syntax for Action Links that redirect to the same URL #61

Closed danmt closed 1 month ago

danmt commented 2 months ago

As of now, you have to manually write the href for Action Links, for actions that redirect to itself it's repetitive, having a shorthand would make this easier to maintain. Actions that call actions in another context would have to enter the full path.

An action that currently looks like this:

#[derive(Action)]
#[action(
    // ..
    link = {
        label = "Send 1 SOL",
        href = "/api/send_donation?amount=1",
    },
    link = {
        label = "Send 5 SOL",
        href = "/api/send_donation?amount=5",
    },
    link = {
        label = "Send SOL",
        href = "/api/send_donation?amount={amount}",
        parameter = { label = "Amount in SOL", name = "amount" }
    },
)]
#[query(amount: u64)]
pub struct SendDonationAction;

Could be written like this instead:

#[derive(Action)]
#[action(
    // ..
    link = {
        label = "Send 1 SOL",
        href = "?amount=1",
    },
    link = {
        label = "Send 5 SOL",
        href = "?amount=5",
    },
    link = {
        label = "Send SOL",
        href = "?amount={amount}",
        parameter = { label = "Amount in SOL", name = "amount" }
    },
)]
#[query(amount: u64)]
pub struct SendDonationAction;