Skip to content

Instantly share code, notes, and snippets.

@ritave

ritave/snapui.js Secret

Created September 30, 2022 15:01
Show Gist options
  • Save ritave/936013d84a0111ae27046e940915c5cc to your computer and use it in GitHub Desktop.
Save ritave/936013d84a0111ae27046e940915c5cc to your computer and use it in GitHub Desktop.
const CHAINS = ["Bitcoin", "Ethereum", "Dogecoin", "Garlicoin"];
function accountUI(chains) {
return [
{
type: "section",
children: [
"Select chain you want to create account for",
{ type: "text_input", placeholder: "Search", id: "search" },
],
},
{ type: "section", children: chainsUI(chains) },
];
}
function chainsUI(chains) {
return chains
.flatMap((name) => [
name,
{ type: "button", id: "chain", value: name, text: "Select" },
{ type: "divider" },
])
.splice(-1, 1); // remove last divider
}
function filterChains(chains, needle) {
/* ... */
}
exports.ui = {
onEntry: ({ location }) => {
assert(location === "new_account");
return {
ui: accountUI(CHAINS),
};
},
onChange: ({ action: { id, value } }) => {
assert(id === "search");
return { ui: accountUI(filterChains(CHAINS, value)) };
},
onPress: ({ action: { id, value } }) => {
assert(id === "chain");
assert(CHAINS.includes(value));
newAccountSelectPromiseResolve(value);
return { action: "close" };
},
};
exports.keyrings = {
/* ... */
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment