diff --git a/src/lib/stores/contractStore.js b/src/lib/stores/contractStore.js new file mode 100644 index 0000000..e1d3c88 --- /dev/null +++ b/src/lib/stores/contractStore.js @@ -0,0 +1,33 @@ +import { writable } from 'svelte/store'; +import Contract from 'stellar-sdk'; + +function createContractStore() { + const { subscribe, set, update } = writable({ + savedContracts: loadSavedContracts() + }); + + return { + subscribe, + saveContract: (contract) => update(store => { + const newSavedContracts = [...store.savedContracts, contract]; + localStorage.setItem('savedContracts', JSON.stringify(newSavedContracts)); + return { ...store, savedContracts: newSavedContracts }; + }), + removeContract: (contractId) => update(store => { + const newSavedContracts = store.savedContracts.filter(c => c.id !== contractId); + localStorage.setItem('savedContracts', JSON.stringify(newSavedContracts)); + return { ...store, savedContracts: newSavedContracts }; + }), + setCurrentContract: (contract) => update(store => ({ + ...store, + currentContract: contract + })) + }; +} + +function loadSavedContracts() { + const saved = localStorage.getItem('savedContracts'); + return saved ? JSON.parse(saved) : []; +} + +export const contractStore = createContractStore(); \ No newline at end of file diff --git a/src/lib/utils/contractUtils.js b/src/lib/utils/contractUtils.js new file mode 100644 index 0000000..87bff80 --- /dev/null +++ b/src/lib/utils/contractUtils.js @@ -0,0 +1,24 @@ +import Contract from 'stellar-sdk'; + +export async function generateContractClient(contractId, server) { + try { + // Validate contract ID format + if (!contractId.match(/^C[A-Z2-7]{55}$/)) { + throw new Error('Invalid contract ID format'); + } + + // Get the contract's footprint which includes the WASM hash + const footprintResponse = await server.getFootprint(contractId); + + // Create contract instance + const contract = new Contract(contractId); + + // You might want to add the contract's interface here + // This would involve parsing the WASM to get available methods + + return contract; + } catch (error) { + console.error('Error generating contract client:', error); + throw new Error(`Failed to generate contract client: ${error.message}`); + } +} \ No newline at end of file diff --git a/src/routes/dashboard/components/SidebarMenu.svelte b/src/routes/dashboard/components/SidebarMenu.svelte index c172e89..721a8af 100644 --- a/src/routes/dashboard/components/SidebarMenu.svelte +++ b/src/routes/dashboard/components/SidebarMenu.svelte @@ -17,6 +17,7 @@ list of menu links that can be used to navigate throughout the dashboard. { route: '/dashboard/assets', text: 'Assets' }, { route: '/dashboard/contacts', text: 'Contacts' }, { route: '/dashboard/transfers', text: 'Transfers' }, + { route: '/dashboard/contracts', text: 'Smart Contracts' } ] diff --git a/src/routes/dashboard/contracts/+page.svelte b/src/routes/dashboard/contracts/+page.svelte new file mode 100644 index 0000000..3121440 --- /dev/null +++ b/src/routes/dashboard/contracts/+page.svelte @@ -0,0 +1,93 @@ + + +
+

Stellar Smart Contract Interaction

+ +
+ + +
+ +
+ + +
+ + + + {#if error} +
{error}
+ {/if} + +

Saved Contracts

+ {#each $contractStore.savedContracts as contract} +
+
+ {contract.name || 'Unnamed Contract'} + {contract.id} +
+ +
+ {/each} +
\ No newline at end of file