Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gnoweb): connect with Adena Wallet for Sign and Broadcast #2794

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
38a1074
update
linhpn99 Aug 28, 2024
654d279
Merge branch 'gnolang:master' into master
linhpn99 Sep 4, 2024
fd1a983
Merge branch 'gnolang:master' into master
linhpn99 Sep 6, 2024
73fbf9d
first commit
linhpn99 Sep 8, 2024
b9f86d6
rename game
linhpn99 Sep 8, 2024
78cab04
Merge branch 'master' into implement-game-roll-dice
linhpn99 Sep 8, 2024
b058967
wrong adding
linhpn99 Sep 8, 2024
abf50ee
Merge branch 'implement-game-roll-dice' of https://github.com/linhpn9…
linhpn99 Sep 8, 2024
a1f48df
tmp
linhpn99 Sep 8, 2024
5826229
update gameplay
linhpn99 Sep 9, 2024
15c9154
Merge branch 'master' into implement-game-roll-dice
linhpn99 Sep 9, 2024
8d3e520
ignore init
linhpn99 Sep 9, 2024
9b335e0
Merge branch 'implement-game-roll-dice' of https://github.com/linhpn9…
linhpn99 Sep 9, 2024
38531d0
update
linhpn99 Sep 9, 2024
fa8bcf2
fixup
linhpn99 Sep 9, 2024
e4f9fa5
improve Render
linhpn99 Sep 10, 2024
33bc82b
remove unused field
linhpn99 Sep 10, 2024
da318b3
update
linhpn99 Sep 10, 2024
885adef
update
linhpn99 Sep 10, 2024
9306edc
update
linhpn99 Sep 10, 2024
cff6ec1
add rule sorting
linhpn99 Sep 10, 2024
c9e1fbc
wrong condition
linhpn99 Sep 10, 2024
fe7b3fd
update icon
linhpn99 Sep 10, 2024
5b7d632
Merge branch 'master' into implement-game-roll-dice
linhpn99 Sep 11, 2024
1f08eb7
add script to connect adena in realm view
anhnph Sep 13, 2024
319455f
Merge pull request #14 from linhpn99/implement-game-roll-dice
AnhVAR Sep 13, 2024
f9e036a
Revert "Implement game roll dice"
AnhVAR Sep 13, 2024
be9cbf3
remove comment
anhnph Sep 13, 2024
34ff6d3
Merge pull request #15 from VAR-META-Tech/revert-14-implement-game-ro…
AnhVAR Sep 13, 2024
1b4f4e2
Delete gno-key.asc
AnhVAR Sep 13, 2024
dfd2d8e
Merge branch 'master' into dev_gnoweb_adena
AnhVAR Sep 13, 2024
d1618c8
remove comment
anhnph Sep 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 71 additions & 2 deletions gno.land/pkg/gnoweb/static/js/realm_help.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function main() {
async function main() {
// init
var myAddr = getMyAddress()
u("#my_address").first().value = myAddr;
Expand All @@ -12,6 +12,49 @@ function main() {
var x = u(e.currentTarget).closest("div.func_spec");
updateCommand(x);
});

async function fetchAccount() {
try {
const response = await adena.GetAccount();
if (response.code === 0 && response.status === "success") {
const address = response.data.address;
u("#my_address").first().value = address;
setMyAddress(address);
u("div.func_spec").each(function (node, i) {
updateCommand(u(node));
});
}
} catch (error) {
console.error("Error fetching account:", error);
}
}

//check url params have wallet_address or not
var urlParams = new URLSearchParams(window.location.search);
var connectAdena = urlParams.get('connect-adena');
if (connectAdena) {
if (!window.adena) {
//open adena.app in a new tab if the adena object is not found
window.open("https://adena.app/", "_blank");
} else {
//the sample code below displays a method provided by Adena that initiates a connection
await adena.AddEstablish("Adena");
await fetchAccount();
}
}
//check url params have adena_message or not
var adenaMessage = urlParams.get('adena_message');
if (adenaMessage) {
//get current url
var currentUrl = window.location.href;
//remove all url params
currentUrl = currentUrl.split("?")[0];
//redirect to current url
window.location.href = currentUrl;
var message = JSON.parse(atob(adenaMessage));
await adena.DoContract(message);
}

// special case: when address changes.
u("#my_address").on("input", function(e) {
var value = u("#my_address").first().value;
Expand Down Expand Up @@ -99,7 +142,33 @@ function updateCommand(x) {
var args = ["gnokey", "broadcast", "-remote", shq(remote), "call.tx"];
var command = args.join(" ");
command = command;
shell.append(u("<span>").text(command)).append(u("<br>"));
shell.append(u("<span>").text(command)).append(u("<br>")).append(u("<br>"));;

// command 4: Sign and broadcast by Adena
var adenaArgs = [];
vals.forEach(function (arg) {
adenaArgs.push(arg);
});
const message = {
messages: [{
type: "/vm.m_call",
value: {
caller: myAddr,
send: "",
pkg_path: realmPath,
func: funcName,
args: adenaArgs
}
}],
gasFee: 1000000,
gasWanted: 2000000
};
//convert message to base64
const messageBase64 = btoa(JSON.stringify(message));
var currentUrl = window.location.href;
adena_href = currentUrl + "&adena_message=" + messageBase64;
shell.append(u("<span>").text("### SIGN AND BROACAST BY ADENA")).append(u("<br>"));
shell.append(u("<a href=" + adena_href + ">").text("Do Contract")).append(u("<br>"));
}

// Jae: why isn't this a library somewhere?
Expand Down
9 changes: 8 additions & 1 deletion gno.land/pkg/gnoweb/views/realm_help.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<br />
These are the realm's exposed functions ("public smart contracts").<br />
<br />
My address: <input id="my_address" placeholder="ADDRESS" width="40" /> (see <a href="https://docs.gno.land/gno-tooling/cli/gno-tooling-gnokey/#list-all-known-keys" target="_blank">`gnokey list`</a>)<br />
My address: <input id="my_address" placeholder="ADDRESS" width="40" /> (see <a href="https://docs.gno.land/gno-tooling/cli/gno-tooling-gnokey/#list-all-known-keys" target="_blank">`gnokey list`</a> or <a id="connect-adena" href="#"> Connect Adena </a>)<br />
<br />
<br />
{{ template "func_specs" . }}
Expand All @@ -27,6 +27,13 @@
</div>
{{ template "js" . }}
<script src="/static/js/realm_help.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
var currentUrl = window.location.href;
var adenaLink = document.getElementById("connect-adena");
adenaLink.href = currentUrl + "&connect-adena=true";
});
</script>
</body>
</html>
{{- end -}}
Expand Down