-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: complete initial joyID NFT view & iframe provider.
- Loading branch information
1 parent
c88a72a
commit 52ea04f
Showing
9 changed files
with
243 additions
and
103 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
javascript/tokenscript-viewer/src/assets/test-iframe-provider.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<html> | ||
<head> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/ethers/5.7.2/ethers.umd.min.js" integrity="sha512-FDcVY+g7vc5CXANbrTSg1K5qLyriCsGDYCE02Li1tXEYdNQPvLPHNE+rT2Mjei8N7fZbe0WLhw27j2SrGRpdMg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> | ||
</head> | ||
<body> | ||
<div style="width: 600px; margin: 0 auto; min-height: 800px;"> | ||
<iframe id="frame" src="https://viewer-staging.tokenscript.org/?viewType=joyid-token&chain=11155111&contract=0xA04664f6191D9A65F5F48c6F9d6Dd81CB636E65c&tokenId=1" | ||
style="border: 0; width: 100%; height: 100%;"></iframe> | ||
</div> | ||
<script> | ||
const provider = new ethers.providers.Web3Provider(window.ethereum); | ||
const iframe = document.getElementById("frame"); | ||
|
||
window.addEventListener("message", async (message) => { | ||
if (message.origin !== "http://localhost:3333") | ||
return; | ||
|
||
console.log("Message received: ", message); | ||
|
||
try { | ||
switch (message.data.method) { | ||
case "eth_accounts": | ||
case "eth_requestAccounts": | ||
await window.ethereum.enable(); | ||
const accounts = await provider.listAccounts(); | ||
sendResponse(message.data, accounts); | ||
break; | ||
case "eth_chainId": | ||
case "eth_blockNumber": | ||
case "eth_estimateGas": | ||
case "eth_sendTransaction": | ||
case "eth_sendRawTransaction": | ||
case "eth_getTransactionByHash": | ||
case "eth_getTransactionReceipt": | ||
case "eth_getTransactionCount": | ||
case "personal_sign": | ||
case "eth_signTypedData": | ||
const result = await provider.send(message.data.method, message.data.params); | ||
sendResponse(message.data, result); | ||
break; | ||
|
||
default: | ||
sendResponse(message.data, null, {code: -1, message: "RPC Method " + message.data.method + " is not implemented"}); | ||
} | ||
} catch (e){ | ||
console.error(e); | ||
sendResponse(message.data, null, { | ||
code: e.code, | ||
message: e.message | ||
}); | ||
} | ||
}); | ||
|
||
function sendResponse(messageData, response, error){ | ||
|
||
const data = messageData; | ||
|
||
if (response){ | ||
data.result = response; | ||
} else { | ||
data.error = error; | ||
} | ||
|
||
iframe.contentWindow.postMessage(data, "https://viewer-staging.tokenscript.org"); | ||
} | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.