The other side of the Ownable package will contain the visual elements: HTML, and media files like images and videos.
HTML
The index.html file will be rendered as widget in the wallet. It should have a structure resembling the following:
<html> <head> <style> // all the styles for your ownable </style> </head> <body> <div> // your ownable html </div> <script> // any necessary functions </script> </body>
Styling
The styling should be responsive on all devices. As the wallet will render your provided template, you are in complete control of how it will be displayed.
The widgets in which the Ownables will be placed always have a 1:1 aspect ratio (square). Use the viewport unitsvh and vw, and/or aspect-ratio to ensure the content of the widget properly scales.
If we consider the potion example which you can find in our demo repository, the script part of our HTML template may contain methods like this:
// Listen for a click on the button defined in the html template// which will trigger the consume methoddocument.getElementById("drink-button").addEventListener('click', () =>consume());functionconsume() {// building the message to be passed to WASM for execution// this should match the msg expected by the lib.rs entry pointslet msg = {"consume": {"amount":getDrinkAmount(), }, };// posting the message to the wallet which will relay it to WASM// check index.js for the listener to see how it does it// https://github.com/ltonetwork/ownable-demo/blob/eb0bda9c323659a78d69bd669861f46473d16fa2/www/index.js#L163window.parent.postMessage({type:"execute", ownable_id, msg},"*");}// gets the selected amount to drink from the html sliderfunctiongetDrinkAmount() {let stringAmount =document.getElementsByClassName('slider')[0].valueOf().value;returnparseInt(stringAmount);}// listener for the wallet messages indicating the state after the execute msg// see wasm-wrappers.js for details:// https://github.com/ltonetwork/ownable-demo/blob/main/www/wasm-wrappers.js#L210-L217window.addEventListener("message", (event) => {conststate=event.data.state;updateTemplate(state.color,state.current_amount)});// method to update the visual template defined in the html filefunctionupdateTemplate(color, amt) {document.getElementsByClassName('juice')[0].style.backgroundColor = color;document.getElementsByClassName('juice')[0].style.top = (100- amt) +'%';document.getElementsByClassName('juice')[0].style.height = amt +'%';document.getElementsByClassName('amount')[0].textContent = amt;}