Skip to content

Commit

Permalink
Merge pull request #37 from Montoya/zorro
Browse files Browse the repository at this point in the history
version 2.0 now with Spanish language support
  • Loading branch information
Montoya authored Oct 19, 2023
2 parents 33cdf2c + 4b64e22 commit 07fd0e5
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mystery-fox",
"version": "1.2.1",
"version": "2.0.0",
"description": "A simple MetaMask snap that returns random numbers and answers.",
"repository": {
"type": "git",
Expand Down
7 changes: 4 additions & 3 deletions snap.manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"version": "1.2.1",
"version": "2.0.0",
"description": "A simple MetaMask snap that returns random numbers and answers.",
"proposedName": "Mystery Fox",
"repository": {
"type": "git",
"url": "https://github.com/Montoya/random-snap.git"
},
"source": {
"shasum": "/+/p9W0fzIKXPHI0jnboT0QMpE7bx/HAorGlw+wCDrk=",
"shasum": "wDirutuUj5vsQjaBNpVFcyGNbkx2PT3OrTSUHaDDRT4=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand All @@ -22,7 +22,8 @@
"dapps": true,
"snaps": true
},
"snap_dialog": {}
"snap_dialog": {},
"snap_getLocale": {}
},
"manifestVersion": "0.1"
}
117 changes: 97 additions & 20 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,100 @@
import { panel, text, divider } from '@metamask/snaps-ui';

const uiText = {
header: {
en: 'The Mysterious 🦊 Has Spoken',
es: 'El 🦊 Misterioso Dice'
},
youasked: {
en: 'You asked:',
es: 'Usted preguntó:'
},
says: {
en: 'The fox says:',
es: 'El zorro respondió:'
}
};

const answers = [
'Certainly',
'Without a doubt',
'Absolutely yes',
'You betcha',
'Confirmed',
'I think so',
'It is likely',
'Consensus is yes',
'Unlikely',
'Unconfirmed',
'Not looking good',
'Doubtful',
'Unsure, ask again later...',
'Hard to say, ask again later...',
'Undetermined, ask again later...',
'Unclear, ask again later...',
{
en: 'Certainly',
es: 'Ciertamente'
},
{
en: 'Without a doubt',
es: 'Sin duda'
},
{
en: 'Absolutely',
es: 'Absolutamente'
},
{
en: 'You betcha',
es: 'Tu lo sabes'
},
{
en: 'Confirmed',
es: 'Confirmado'
},
{
en: 'I think so',
es: 'Creo que sí'
},
{
en: 'It is likely',
es: 'Es probable'
},
{
en: 'Consensus is yes',
es: 'Hay acuerdo'
},
{
en: 'Unlikely',
es: 'Improbable'
},
{
en: 'Unconfirmed',
es: 'Sin confirmación'
},
{
en: 'Not looking good',
es: 'No parece bueno'
},
{
en: 'Doubtful',
es: 'Dudoso'
},
{
en: 'Unsure, ask again later...',
es: 'No estoy seguro, pregúntame más tarde...'
},
{
en: 'Hard to say, ask again later...',
es: 'Es dificil decir, pregúntame más tarde...'
},
{
en: 'Undetermined, ask again later...',
es: 'No hay indicación, pregúntame más tarde...'
},
{
en: 'Unclear, ask again later...',
es: 'No es claro, pregúntame más tarde...'
}
];

const getLocale = async function() {
const locale = await snap.request({ method: 'snap_getLocale' });
switch(locale) {
case 'es':
case 'es_419':
return 'es';
break;
default:
return 'en';
break;
}
};

module.exports.onRpcRequest = async ({ origin, request }) => {
switch (request.method) {
case 'random':
Expand All @@ -29,19 +105,20 @@ module.exports.onRpcRequest = async ({ origin, request }) => {
}
return Math.random();
case 'mystery':
const mysteryResponse = answers[Math.floor(Math.random() * answers.length)];
const locale = await getLocale();
const mysteryResponse = answers[Math.floor(Math.random() * answers.length)][locale];
const question = request.params.question.trim();
return snap.request({
method: 'snap_dialog',
params: {
type: 'alert',
content: panel([
text(`**The Mysterious 🦊 Has Spoken**`),
text(`**${uiText.header[locale]}**`),
divider(),
text('You asked:'),
text(uiText.youasked[locale]),
text(`_${question}_`),
divider(),
text('The mysterious fox says:'),
text(uiText.says[locale]),
text(`**${mysteryResponse}**`),
]),
},
Expand Down

0 comments on commit 07fd0e5

Please sign in to comment.