Skip to content

Commit a820001

Browse files
authored
Merge branch 'main' into 1653-typo-fixes
2 parents 99a9122 + a87c41f commit a820001

File tree

7 files changed

+82
-79
lines changed

7 files changed

+82
-79
lines changed

.github/workflows/lint.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ env:
2121

2222
jobs:
2323
lint:
24-
name: Lint Code Base, Spelling, Link Check
24+
name: Lint Code Base
2525
runs-on: ubuntu-latest
2626
permissions:
2727
contents: read
@@ -30,8 +30,19 @@ jobs:
3030

3131
- name: Lint
3232
uses: ConsenSys/docs-gha/lint@cc8b9d9065f5f20b105954f8e806f55c1e235ecd
33+
34+
spelling:
35+
name: Spelling
36+
runs-on: ubuntu-latest
37+
strategy:
38+
matrix:
39+
file-extensions: [".md", ".mdx"]
40+
steps:
41+
- uses: actions/checkout@v4
42+
- name: Vale
43+
uses: Consensys/docs-gha/spelling@main
3344
with:
34-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
FILEPATHS: "snaps,services,wallet,developer-tools,docs"
3546

3647
linkCheck:
3748
name: Link Checking

docs/whats-new.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ of the [MetaMask developer page](https://metamask.io/developer/).
1717
- Updated [Wallet landing page](/wallet) and added [Connect to MetaMask](/wallet/connect) section
1818
with SDK, third-party libraries, and Wallet API connection options.
1919
([#1494](https://github.com/MetaMask/metamask-docs/pull/1494))
20+
- Documented [`snap_getPreferences`](/snaps/reference/snaps-api/#snap_getpreferences).
21+
([#1681](https://github.com/MetaMask/metamask-docs/pull/1681))
2022

2123
## September 2024
2224

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,13 @@
11
---
22
title: "eth_hashrate"
3+
hide_title: true
4+
hide_table_of_contents: true
35
---
46

5-
import Tabs from "@theme/Tabs"
6-
import TabItem from "@theme/TabItem"
7+
import ParserOpenRPC from "@site/src/components/ParserOpenRPC"
8+
import { NETWORK_NAMES } from "@site/src/plugins/plugin-json-rpc"
79

8-
import Description from "/services/reference/_partials/_eth_hashrate-description.mdx"
9-
10-
<Description />
11-
12-
## Parameters
13-
14-
import Params from "/services/reference/_partials/_eth_hashrate-parameters.mdx"
15-
16-
<Params />
17-
18-
## Returns
19-
20-
import Returns from "/services/reference/_partials/_eth_hashrate-returns.mdx"
21-
22-
<Returns />
23-
24-
## Example
25-
26-
import Example from "/services/reference/_partials/_eth_hashrate-example.mdx"
27-
28-
<Example />
29-
30-
### Request
31-
32-
import Request from "./_eth_hashrate-request.mdx"
33-
34-
<Request />
35-
36-
### Response
37-
38-
import Response from "/services/reference/_partials/_eth_hashrate-response.mdx"
39-
40-
<Response />
10+
<ParserOpenRPC
11+
network={NETWORK_NAMES.linea}
12+
method="eth_hashrate"
13+
/>
Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,13 @@
11
---
22
title: "eth_mining"
3+
hide_title: true
4+
hide_table_of_contents: true
35
---
46

5-
import Tabs from "@theme/Tabs"
6-
import TabItem from "@theme/TabItem"
7+
import ParserOpenRPC from "@site/src/components/ParserOpenRPC"
8+
import { NETWORK_NAMES } from "@site/src/plugins/plugin-json-rpc"
79

8-
import Description from "/services/reference/_partials/_eth_mining-description.mdx"
9-
10-
<Description />
11-
12-
## Parameters
13-
14-
import Params from "/services/reference/_partials/_eth_mining-parameters.mdx"
15-
16-
<Params />
17-
18-
## Returns
19-
20-
import Returns from "/services/reference/_partials/_eth_mining-returns.mdx"
21-
22-
<Returns />
23-
24-
## Example
25-
26-
import Example from "/services/reference/_partials/_eth_mining-example.mdx"
27-
28-
<Example />
29-
30-
### Request
31-
32-
import Request from "./_eth_mining-request.mdx"
33-
34-
<Request />
35-
36-
### Response
37-
38-
import Response from "/services/reference/_partials/_eth_mining-response.mdx"
39-
40-
<Response />
10+
<ParserOpenRPC
11+
network={NETWORK_NAMES.linea}
12+
method="eth_mining"
13+
/>

snaps/features/localization.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ title and description) in the user's language.
1313
### 1. Get the user's language
1414

1515
In your Snap's code, determine the user's language by using the
16-
[`snap_getLocale`](../reference/snaps-api.md#snap_getlocale) API method.
17-
To call `snap_getLocale`, first request the required permission by adding it to the
16+
[`snap_getPreferences`](../reference/snaps-api.md#snap_getpreferences) API method.
17+
To call `snap_getPreferences`, first request the required permission by adding it to the
1818
`initialPermissions` field in your manifest file:
1919

2020
```json title="snap.manifest.json"
2121
"initialPermissions": {
22-
"snap_getLocale": {}
22+
"snap_getPreferences": {}
2323
}
2424
```
2525

26-
Your Snap can then call `snap_getLocale` to get the user's language code (for example, `en` or `es`).
26+
Your Snap can then call `snap_getPreferences` to get the user's language code (for example, `en` or `es`).
2727

2828
### 2. Localize the Snap's UI
2929

@@ -65,7 +65,9 @@ export const locales = {
6565
export type Locale = keyof typeof locales
6666

6767
export async function getMessage(id: keyof (typeof locales)[Locale]) {
68-
const locale = (await snap.request({ method: "snap_getLocale" })) as Locale
68+
const { locale } = (await snap.request({ method: "snap_getPreferences" })) as {
69+
locale: Locale
70+
}
6971
const { message } = locales[locale]?.[id] ?? locales[FALLBACK_LANGUAGE][id]
7072

7173
return message
@@ -113,7 +115,7 @@ The following is an example of a localized manifest file:
113115
"locales": ["locales/da.json", "locales/en.json", "locales/nl.json"]
114116
},
115117
"initialPermissions": {
116-
"snap_getLocale": {}
118+
"snap_getPreferences": {}
117119
},
118120
"manifestVersion": "0.1"
119121
}

snaps/how-to/get-allowlisted.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ The following is a list of permissions that do not require allowlisting:
162162
- [`endowment:transaction-insight`](../reference/permissions.md#endowmenttransaction-insight)
163163
- [`snap_dialog`](../reference/snaps-api.md#snap_dialog)
164164
- [`snap_getLocale`](../reference/snaps-api.md#snap_getlocale)
165+
- [`snap_getPreferences`](../reference/snaps-api.md#snap_getpreferences)
165166
- [`snap_manageState`](../reference/snaps-api.md#snap_managestate)
166167
- [`snap_notify`](../reference/snaps-api.md#snap_notify)
167168

snaps/reference/snaps-api.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,15 @@ console.log(contents)
484484
</TabItem>
485485
</Tabs>
486486

487-
## `snap_getLocale`
487+
## `snap_getLocale` (deprecated)
488488

489489
Gets the user's locale setting. You can use this method to localize text in your snap.
490490

491+
:::warning
492+
This method is deprecated.
493+
Use [`snap_getPreferences`](#snap_getpreferences) instead.
494+
:::
495+
491496
#### Returns
492497

493498
The user's locale setting as a [language code](https://github.com/MetaMask/metamask-extension/blob/develop/app/_locales/index.json).
@@ -545,6 +550,42 @@ await snap.request({
545550
</TabItem>
546551
</Tabs>
547552

553+
## `snap_getPreferences`
554+
555+
Gets the user's preferences.
556+
557+
#### Returns
558+
559+
An object containing the user's preferences:
560+
561+
- `locale` - The user's locale setting as a language code.
562+
- `currency` - The user's preferred fiat currency code.
563+
564+
#### Example
565+
566+
```tsx title="index.tsx"
567+
import { Box, Text } from "@metamask/snaps-sdk/jsx";
568+
569+
const { locale } = await snap.request({ method: "snap_getPreferences" });
570+
571+
let greeting = "Hello";
572+
if(locale === "es") {
573+
greeting = "Hola";
574+
}
575+
576+
await snap.request({
577+
method: "snap_dialog",
578+
params: {
579+
type: "alert",
580+
content: (
581+
<Box>
582+
<Text>{greeting}</Text>
583+
</Box>
584+
),
585+
},
586+
});
587+
```
588+
548589
## `snap_manageAccounts`
549590

550591
Manages [account management Snap](../features/custom-evm-accounts/index.md) accounts.

0 commit comments

Comments
 (0)