-
-
Save ritave/936013d84a0111ae27046e940915c5cc to your computer and use it in GitHub Desktop.
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
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