Skip to content

Commit

Permalink
Complete parameterisation
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mueller committed Jan 29, 2025
1 parent 6fd260c commit 93aa861
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 52 deletions.
14 changes: 7 additions & 7 deletions frontend/src/app/[username]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ export default function Profile() {
lucid.wallet().address().then(console.log);
const requestData = {
asset_name: Buffer.from('WST', 'utf8').toString('hex'), // Convert "WST" to hex
issuer: mintAccount.address,
issuer: mintAccount.regular_address,
quantity: sendTokenAmount,
recipient: sendRecipientAddress,
sender: accountInfo.address,
sender: accountInfo.regular_address,
submit_failing_tx: overrideTx
};
try {
Expand All @@ -91,7 +91,7 @@ export default function Profile() {
const tx = await lucid.fromTx(response.data.cborHex);
const txId = await signAndSentTx(lucid, tx);
await updateAccountBalance(sendRecipientAddress);
await updateAccountBalance(accountInfo.address);
await updateAccountBalance(accountInfo.regular_address);
changeAlertInfo({severity: 'success', message: 'Transaction sent successfully!', open: true, link: `${demoEnv.explorer_url}/${txId}`});
} catch (error) {
console.error('Send failed:', error);
Expand All @@ -101,7 +101,7 @@ export default function Profile() {
const updateAccountBalance = async (address: string) => {
const newAccountBalance = await getWalletBalance(demoEnv, address);
const walletKey = (Object.keys(accounts) as (keyof Accounts)[]).find(
(key) => accounts[key].address === address
(key) => accounts[key].regular_address === address
);
if (walletKey) {
changeWalletAccountDetails(walletKey, {
Expand Down Expand Up @@ -136,9 +136,9 @@ export default function Profile() {

const receiveContent = <Box>
<CopyTextField
value={getUserAccountDetails()?.address ?? ''}
value={getUserAccountDetails()?.regular_address ?? ''}
fullWidth={true}
label="Programmable Token Address"
label="Regular Address"
/>
</Box>;

Expand All @@ -150,7 +150,7 @@ export default function Profile() {
<Typography variant='h1'>{getUserAccountDetails()?.balance.wst} WST</Typography>
<Typography variant='h5'>{getUserAccountDetails()?.balance.ada} Ada { (getUserAccountDetails()?.balance.adaOnlyOutputs === 0) && (<span>({getUserAccountDetails()?.balance.adaOnlyOutputs} collateral UTxOs)</span>)}</Typography>
</Box>
<Typography variant='h5'>{getUserAccountDetails()?.address.slice(0,15)}</Typography>
<Typography variant='h5'>{getUserAccountDetails()?.regular_address.slice(0,15)}</Typography>
</Box>
<div className="cardWrapperParent">
<WalletCard tabs={[
Expand Down
28 changes: 21 additions & 7 deletions frontend/src/app/clientLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ async function loadDemoEnvironment(): Promise<DemoEnvironment> {
return response?.data;
}

async function getProgrammableTokenAddress(regular_address: string) {
const response = await axios.get<string>(`/api/v1/query/address/${regular_address}`,
{
headers: {
'Content-Type': 'application/json;charset=utf-8',
},
});
return response?.data;
}


export default function ClientLayout({ children }: { children: React.ReactNode }) {
const { mintAccount, accounts, changeMintAccountDetails, changeWalletAccountDetails, setLucidInstance } = useStore();
const [demoEnv, setDemoEnv] = useState<DemoEnvironment>(previewEnv);
Expand All @@ -39,14 +50,17 @@ export default function ClientLayout({ children }: { children: React.ReactNode }
setDemoEnv(demoEnv);

// retrieve wallet info
const mintAuthorityWallet = await getWalletFromSeed(demoEnv.mint_authority);
const walletA = await getWalletFromSeed(demoEnv.user_a);
const walletB = await getWalletFromSeed(demoEnv.user_b);
const mintAuthorityWallet = await getWalletFromSeed(demoEnv, demoEnv.mint_authority);
const walletA = await getWalletFromSeed(demoEnv, demoEnv.user_a);
const walletB = await getWalletFromSeed(demoEnv, demoEnv.user_b);
const walletATokenAddr = await getProgrammableTokenAddress(walletA.address);
const walletBTokenAddr = await getProgrammableTokenAddress(walletB.address);
const mintAuthorityTokenAddr = await getProgrammableTokenAddress(mintAuthorityWallet.address);

// Update Zustand store with the initialized wallet information
changeMintAccountDetails({ ...mintAccount, address: mintAuthorityWallet.address});
changeWalletAccountDetails('alice', { ...accounts.alice, address: walletA.address},);
changeWalletAccountDetails('bob', { ...accounts.bob, address: walletB.address});
changeMintAccountDetails({ ...mintAccount, regular_address: mintAuthorityWallet.address, programmable_token_address: mintAuthorityTokenAddr});
changeWalletAccountDetails('alice', { ...accounts.alice, regular_address: walletA.address, programmable_token_address: walletATokenAddr},);
changeWalletAccountDetails('bob', { ...accounts.bob, regular_address: walletB.address, programmable_token_address: walletBTokenAddr});

const initialLucid = await makeLucid(demoEnv);
setLucidInstance(initialLucid);
Expand All @@ -59,7 +73,7 @@ export default function ClientLayout({ children }: { children: React.ReactNode }
fetchUserWallets();
},[]);

if(accounts.bob.address === '') {
if(accounts.bob.regular_address === '') {
return <div className="mainLoadingContainer">
<div className="mainLoader" />
</div>;
Expand Down
13 changes: 9 additions & 4 deletions frontend/src/app/components/WSTTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,23 @@ export default function WSTTable() {
<Table size="small" aria-label="simple table" stickyHeader>
<TableHead>
<TableRow>
<TableCell>Address</TableCell>
<TableCell>Regular Address</TableCell>
<TableCell>Programmable Address</TableCell>
<TableCell>Address Status</TableCell>
<TableCell align="right">Address Balance</TableCell>
</TableRow>
</TableHead>
<TableBody>
{
accountArray.filter((acct) => acct.address !== "").map((acct, i) => (
accountArray.filter((acct) => acct.regular_address !== "").map((acct, i) => (
<TableRow key={i}>
<TableCell>
{`${acct?.address.slice(0,15)}...${acct?.address.slice(104,108)}`}
<IconButton onClick={() => copyToClipboard(acct.address)} icon={<ContentCopyIcon />}/>
{`${acct?.regular_address.slice(0,15)}...${acct?.regular_address.slice(104,108)}`}
<IconButton onClick={() => copyToClipboard(acct.regular_address)} icon={<ContentCopyIcon />}/>
</TableCell>
<TableCell>
{`${acct?.programmable_token_address.slice(0,15)}...${acct?.programmable_token_address.slice(104,108)}`}
<IconButton onClick={() => copyToClipboard(acct.programmable_token_address)} icon={<ContentCopyIcon />}/>
</TableCell>
<TableCell sx={{color: acct.status === 'Frozen' ? 'error.main' : 'success.main', fontWeight: '500'}}>
{acct.status}
Expand Down
34 changes: 17 additions & 17 deletions frontend/src/app/mint-authority/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ export default function Home() {
}, [demoEnv]);

const fetchUserDetails = async () => {
const mintBalance = await getWalletBalance(demoEnv, mintAccount.address);
const userABalance = await getWalletBalance(demoEnv, accounts.alice.address);
const userBBalance = await getWalletBalance(demoEnv, accounts.bob.address);
const mintBalance = await getWalletBalance(demoEnv, mintAccount.regular_address);
const userABalance = await getWalletBalance(demoEnv, accounts.alice.regular_address);
const userBBalance = await getWalletBalance(demoEnv, accounts.bob.regular_address);

// Update Zustand store with the initialized wallet information
await changeMintAccountDetails({ ...mintAccount, balance: mintBalance});
Expand All @@ -66,11 +66,11 @@ export default function Home() {
const { accounts, changeWalletAccountDetails } = useStore.getState();

Object.entries(accounts).map(async ([key, account]) => {
if (!account.address || account.address.trim() === "") {
if (!account.regular_address || account.regular_address.trim() === "") {
// console.log(`${key} has no address yet, skipping`);
return;
}
const credential : LucidCredential = await paymentCredentialOf(account.address);
const credential : LucidCredential = await paymentCredentialOf(account.regular_address);
if(blacklist.includes(credential.hash)) {
// console.log('a match was found', key as keyof typeof accounts);
changeWalletAccountDetails(key as keyof typeof accounts, { ...account, status: 'Frozen',});
Expand All @@ -92,7 +92,7 @@ export default function Home() {
lucid.selectWallet.fromSeed(demoEnv.mint_authority);
const requestData = {
asset_name: Buffer.from('WST', 'utf8').toString('hex'), // Convert "WST" to hex
issuer: mintAccount.address,
issuer: mintAccount.regular_address,
quantity: mintTokensAmount,
recipient: mintRecipientAddress
};
Expand Down Expand Up @@ -125,10 +125,10 @@ export default function Home() {
changeAlertInfo({severity: 'info', message: 'Transaction processing', open: true, link: ''});
const requestData = {
asset_name: Buffer.from('WST', 'utf8').toString('hex'), // Convert "WST" to hex
issuer: mintAccount.address,
issuer: mintAccount.regular_address,
quantity: sendTokensAmount,
recipient: sendRecipientAddress,
sender: mintAccount.address,
sender: mintAccount.regular_address,
};
try {
const response = await axios.post(
Expand All @@ -145,7 +145,7 @@ export default function Home() {
const txId = await signAndSentTx(lucid, tx);
const newAccountBalance = await getWalletBalance(demoEnv, sendRecipientAddress);
const recipientWalletKey = (Object.keys(accounts) as (keyof Accounts)[]).find(
(key) => accounts[key].address === sendRecipientAddress
(key) => accounts[key].regular_address === sendRecipientAddress
);
if (recipientWalletKey) {
changeWalletAccountDetails(recipientWalletKey, {
Expand All @@ -165,7 +165,7 @@ export default function Home() {
lucid.selectWallet.fromSeed(demoEnv.mint_authority);
changeAlertInfo({severity: 'info', message: 'Freeze request processing', open: true, link: ''});
const requestData = {
issuer: mintAccount.address,
issuer: mintAccount.regular_address,
blacklist_address: freezeAccountNumber,
reason: freezeReason,
};
Expand All @@ -185,7 +185,7 @@ export default function Home() {
console.log(txId);
changeAlertInfo({severity: 'success', message: 'Address successfully frozen', open: true, link: `${demoEnv.explorer_url}/${txId}`});
const frozenWalletKey = (Object.keys(accounts) as (keyof Accounts)[]).find(
(key) => accounts[key].address === freezeAccountNumber
(key) => accounts[key].regular_address === freezeAccountNumber
);
if (frozenWalletKey) {
changeWalletAccountDetails(frozenWalletKey, {
Expand All @@ -212,7 +212,7 @@ export default function Home() {
lucid.selectWallet.fromSeed(demoEnv.mint_authority);
changeAlertInfo({severity: 'info', message: 'Unfreeze request processing', open: true, link: ''});
const requestData = {
issuer: mintAccount.address,
issuer: mintAccount.regular_address,
blacklist_address: unfreezeAccountNumber,
reason: "(unfreeze)"
};
Expand All @@ -231,7 +231,7 @@ export default function Home() {
const txId = await signAndSentTx(lucid, tx);
changeAlertInfo({severity: 'success', message: 'Address successfully unfrozen', open: true, link: `${demoEnv.explorer_url}/${txId}`});
const unfrozenWalletKey = (Object.keys(accounts) as (keyof Accounts)[]).find(
(key) => accounts[key].address === freezeAccountNumber
(key) => accounts[key].regular_address === freezeAccountNumber
);
if (unfrozenWalletKey) {
changeWalletAccountDetails(unfrozenWalletKey, {
Expand All @@ -258,7 +258,7 @@ export default function Home() {
lucid.selectWallet.fromSeed(demoEnv.mint_authority);
changeAlertInfo({severity: 'info', message: 'WST seizure processing', open: true, link: ''});
const requestData = {
issuer: mintAccount.address,
issuer: mintAccount.regular_address,
target: seizeAccountNumber,
reason: seizeReason,
};
Expand All @@ -277,7 +277,7 @@ export default function Home() {
const txId = await signAndSentTx(lucid, tx);
const newAccountBalance = await getWalletBalance(demoEnv, seizeAccountNumber);
const seizeWalletKey = (Object.keys(accounts) as (keyof Accounts)[]).find(
(key) => accounts[key].address === seizeAccountNumber
(key) => accounts[key].regular_address === seizeAccountNumber
);
if (seizeWalletKey) {
changeWalletAccountDetails(seizeWalletKey, {
Expand Down Expand Up @@ -374,7 +374,7 @@ maxRows={3}

const receiveContent = <Box>
<CopyTextField
value={mintAccount.address}
value={mintAccount.regular_address}
fullWidth={true}
label="Your Address"
/>
Expand All @@ -390,7 +390,7 @@ maxRows={3}
<Typography variant='h1'>{mintAccount.balance.wst} WST</Typography>
<Typography variant='h5'>{mintAccount.balance.ada} Ada { (mintAccount.balance.adaOnlyOutputs === 0) && (<span>({mintAccount.balance.adaOnlyOutputs} collateral UTxOs)</span>)}</Typography>
</Box>
<Typography variant='h5'>UserID: {mintAccount.address.slice(0,15)}</Typography>
<Typography variant='h5'>UserID: {mintAccount.regular_address.slice(0,15)}</Typography>
</Box>
<div className="cardWrapperParent">
<WalletCard tabs={[
Expand Down
14 changes: 9 additions & 5 deletions frontend/src/app/store/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,26 @@ export type Actions = {
const useStore = create<State & Actions>((set) => ({
mintAccount: {
name: 'Mint Authority',
address: 'addr_test1qq986m3uel86pl674mkzneqtycyg7csrdgdxj6uf7v7kd857kquweuh5kmrj28zs8czrwkl692jm67vna2rf7xtafhpqk3hecm',
regular_address: '',
programmable_token_address: '',
balance: {ada: 0, wst: 0, adaOnlyOutputs: 0},
},
accounts: {
alice: {
address: '',
regular_address: '',
programmable_token_address: '',
balance: {ada: 0, wst: 0, adaOnlyOutputs: 0},
status: 'Active',
},
bob: {
address: '',
regular_address: '',
programmable_token_address: '',
balance: {ada: 0, wst: 0, adaOnlyOutputs: 0},
status: 'Active',
},
walletUser: {
address: '',
regular_address: '',
programmable_token_address: '',
balance: {ada: 0, wst: 0, adaOnlyOutputs: 0},
status: 'Active',
},
Expand Down Expand Up @@ -83,7 +87,7 @@ const useStore = create<State & Actions>((set) => ({
firstAccessibleTab = 'Wallet';
break;
case 'Connected Wallet':
if (useStore.getState().accounts.walletUser.address === useStore.getState().mintAccount.address)
if (useStore.getState().accounts.walletUser.regular_address === useStore.getState().mintAccount.regular_address)
firstAccessibleTab = 'Mint Actions';
else
firstAccessibleTab = 'Wallet';
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/app/store/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ export type MenuTab = 'Mint Actions' | 'Addresses' | 'Wallet';
import { Network } from "@lucid-evolution/lucid";

export type AccountInfo = {
address: string,
regular_address: string,
programmable_token_address: string,
balance: WalletBalance,
status?: 'Active' | 'Frozen',
};
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/app/utils/walletUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export async function makeLucid(demoEnvironment: DemoEnvironment) {
return lucid;
}

export async function getWalletFromSeed(mnemonic: string) {
export async function getWalletFromSeed(demoEnvironment: DemoEnvironment, mnemonic: string) {
try {
const wallet = walletFromSeed(mnemonic, {password: '', addressType: 'Base', accountIndex: 0, network: "Preview"});
const wallet = walletFromSeed(mnemonic, {password: '', addressType: 'Base', accountIndex: 0, network: demoEnvironment.network });
return wallet;
} catch (error) {
console.error('Failed to initialize KeyAgent:', error);
Expand Down Expand Up @@ -54,7 +54,7 @@ export async function getWalletBalance(demoEnv: DemoEnvironment, address: string

return {wst: stableBalance, ada: response.data.user_lovelace / 1000000, adaOnlyOutputs: response.data.ada_only_outputs };
} catch (error) {
console.error('Failed to get balance', error);
console.warn('Failed to get balance', error);
return { wst: 0, ada: 0, adaOnlyOutputs: 0};
}
}
Expand Down Expand Up @@ -227,6 +227,7 @@ export function adjustMintOutput(demoEnv: DemoEnvironment, tx: CML.Transaction,

export async function deriveProgrammableAddress(demoEnv: DemoEnvironment, lucid: LucidEvolution, userAddress: Address){
const network = lucid.config().network!;
console.log("Network", network, demoEnv.network);
// user's payment credential
const ownerCred : LucidCredential = paymentCredentialOf(userAddress);

Expand Down
Loading

0 comments on commit 93aa861

Please sign in to comment.