feat(one_shot): apply params to script
This commit is contained in:
parent
e35ccc9e0c
commit
a82cedbd92
|
@ -4,7 +4,7 @@ import { Blockfrost, Lucid } from "~/vendor/lucid@0.9.4/mod.ts";
|
||||||
import { Input } from "~/components/Input.tsx";
|
import { Input } from "~/components/Input.tsx";
|
||||||
import { Button } from "~/components/Button.tsx";
|
import { Button } from "~/components/Button.tsx";
|
||||||
|
|
||||||
import { Validators } from "~/utils.ts";
|
import { applyParams, Validators } from "~/utils.ts";
|
||||||
|
|
||||||
export interface AppProps {
|
export interface AppProps {
|
||||||
validators: Validators;
|
validators: Validators;
|
||||||
|
@ -12,6 +12,7 @@ export interface AppProps {
|
||||||
|
|
||||||
export default function App({ validators }: AppProps) {
|
export default function App({ validators }: AppProps) {
|
||||||
const [lucid, setLucid] = useState<Lucid | null>(null);
|
const [lucid, setLucid] = useState<Lucid | null>(null);
|
||||||
|
const [tokenName, setTokenName] = useState<string>("");
|
||||||
|
|
||||||
const setupLucid = async (blockfrostApiKey: string) => {
|
const setupLucid = async (blockfrostApiKey: string) => {
|
||||||
const lucid = await Lucid.new(
|
const lucid = await Lucid.new(
|
||||||
|
@ -32,13 +33,26 @@ export default function App({ validators }: AppProps) {
|
||||||
.enable()
|
.enable()
|
||||||
.then((wallet) => {
|
.then((wallet) => {
|
||||||
lucid.selectWallet(wallet);
|
lucid.selectWallet(wallet);
|
||||||
|
});
|
||||||
return lucid.wallet.getUtxos();
|
|
||||||
})
|
|
||||||
.then((utxos) => console.log(utxos));
|
|
||||||
}
|
}
|
||||||
}, [lucid]);
|
}, [lucid]);
|
||||||
|
|
||||||
|
const submitTokenName = async (e: Event) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const utxos = await lucid?.wallet.getUtxos()!;
|
||||||
|
|
||||||
|
const utxo = utxos[0];
|
||||||
|
const outputReference = {
|
||||||
|
txHash: utxo.txHash,
|
||||||
|
outputIndex: utxo.outputIndex,
|
||||||
|
};
|
||||||
|
|
||||||
|
const { lock, mint } = applyParams(tokenName, outputReference, validators);
|
||||||
|
|
||||||
|
console.log(lock, mint);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{!lucid
|
{!lucid
|
||||||
|
@ -56,14 +70,24 @@ export default function App({ validators }: AppProps) {
|
||||||
</Input>
|
</Input>
|
||||||
)
|
)
|
||||||
: (
|
: (
|
||||||
<form class="mt-10 grid grid-cols-1 gap-y-8">
|
<form
|
||||||
<Input type="text" name="tokenName" id="tokenName">
|
class="mt-10 grid grid-cols-1 gap-y-8"
|
||||||
|
onSubmit={submitTokenName}
|
||||||
|
>
|
||||||
|
<Input
|
||||||
|
type="text"
|
||||||
|
name="tokenName"
|
||||||
|
id="tokenName"
|
||||||
|
onInput={(e) => setTokenName(e.currentTarget.value)}
|
||||||
|
>
|
||||||
Token Name
|
Token Name
|
||||||
</Input>
|
</Input>
|
||||||
|
|
||||||
|
{tokenName && (
|
||||||
<Button type="submit">
|
<Button type="submit">
|
||||||
Make Contract
|
Make Contracts
|
||||||
</Button>
|
</Button>
|
||||||
|
)}
|
||||||
</form>
|
</form>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -44,12 +44,11 @@ export async function readValidators(): Promise<Validators> {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function applyParams(
|
export function applyParams(
|
||||||
tokenName: string,
|
tokenName: string,
|
||||||
outputReference: OutRef,
|
outputReference: OutRef,
|
||||||
): Promise<{ lock: string; mint: string }> {
|
validators: Validators,
|
||||||
const validators = await readValidators();
|
): { lock: string; mint: string } {
|
||||||
|
|
||||||
const mint = applyParamsToScript(validators.mint.script, [
|
const mint = applyParamsToScript(validators.mint.script, [
|
||||||
tokenName,
|
tokenName,
|
||||||
outputReference,
|
outputReference,
|
||||||
|
|
Loading…
Reference in New Issue