Skip to content

Commit

Permalink
Merge pull request #741 from near/dev
Browse files Browse the repository at this point in the history
v7.9.2 Release (dev -> main)
  • Loading branch information
kujtimprenkuSQA authored Mar 24, 2023
2 parents 785776d + 4f30d03 commit f9e7566
Show file tree
Hide file tree
Showing 40 changed files with 245 additions and 74 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "near-wallet-selector",
"version": "7.9.1",
"version": "7.9.2",
"description": "NEAR Wallet Selector makes it easy for users to interact with your dApp by providing an abstraction over various wallets within the NEAR ecosystem",
"keywords": [
"near",
Expand Down
2 changes: 1 addition & 1 deletion packages/account-export/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-wallet-selector/account-export",
"version": "7.9.1",
"version": "7.9.2",
"description": "This is the Export Selector UI package for NEAR Wallet Selector.",
"keywords": [
"near",
Expand Down
56 changes: 31 additions & 25 deletions packages/account-export/src/lib/components/AccountSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,32 +132,38 @@ export const AccountSelect: React.FC<AccountSelectProps> = ({
</div>
))}
</div>
<span className="account-unavailable">
{translate("modal.exportAccounts.selectAccounts.unavailable")}
</span>
<div className="account-selection">
{disabledAccounts.map(({ accountId, type, hasBalance }) => (
<div className="account-selection-row" key={accountId}>
<div className="checkbox">
<input
onChange={(e) => {
onAccountSelect(accountId, e.target.checked);
}}
checked={selectedAccounts.includes(accountId)}
type="checkbox"
id={accountId}
name={accountId}
value={accountId}
disabled
/>
<label htmlFor={accountId} title={accountId}>
<span>{accountId}</span>
{getWarningLabel({ hasBalance, type })}
</label>
</div>
{disabledAccounts.length > 0 && (
<>
<span className="account-unavailable">
{translate(
"modal.exportAccounts.selectAccounts.unavailable"
)}
</span>
<div className="account-selection">
{disabledAccounts.map(({ accountId, type, hasBalance }) => (
<div className="account-selection-row" key={accountId}>
<div className="checkbox">
<input
onChange={(e) => {
onAccountSelect(accountId, e.target.checked);
}}
checked={selectedAccounts.includes(accountId)}
type="checkbox"
id={accountId}
name={accountId}
value={accountId}
disabled
/>
<label htmlFor={accountId} title={accountId}>
<span>{accountId}</span>
{getWarningLabel({ hasBalance, type })}
</label>
</div>
</div>
))}
</div>
))}
</div>
</>
)}
<div className="filler" />
<button
className="middleButton account-export-button"
Expand Down
7 changes: 5 additions & 2 deletions packages/account-export/src/lib/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@

.checkbox {
position: relative;
display: block;
display: flex;
margin: 10px;
}

.checkbox label {
Expand Down Expand Up @@ -93,6 +94,7 @@
position: absolute;
left: 0;
margin-left: -20px;
margin-top: 0px;
}

.checkbox input[type="checkbox"]:checked + label::before {
Expand Down Expand Up @@ -198,7 +200,9 @@
justify-content: space-between;
width: 100%;
max-height: 200px;
min-height: 50px;
overflow-y: auto;
overflow-x: hidden;
margin: 20px 0;
}

Expand All @@ -222,7 +226,6 @@
flex-direction: row;
align-items: center;
width: 100%;
padding: 15px 12px;
border-bottom: 1px solid #313030;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/coin98-wallet/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-wallet-selector/coin98-wallet",
"version": "7.9.1",
"version": "7.9.2",
"description": "Coin 98 wallet package for NEAR Wallet Selector.",
"keywords": [
"near",
Expand Down
1 change: 1 addition & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const selector = await setupWalletSelector({
- `optimizeWalletOrder` (`boolean?`): Enable automatic wallet order. Reorders last signed in wallet on top, then installed wallets over not installed and deprecated wallets.
- `randomizeWalletOrder` (`boolean?`): Randomize wallets order in the `More` section of the UI.
- `allowMultipleSelectors` (`boolean?`): Optionally allow creating new instances of wallet selector.
- `languageCode` (`string?`): Optionally set specific ISO 639-1 two-letter language code, disables language detection based on the browser's settings.
- `storage` (`StorageService?`): Async storage implementation. Useful when [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) is unavailable. Defaults to `localStorage`.
- `modules` (`Array<WalletModuleFactory>`): List of wallets to support in your dApp.

Expand Down
29 changes: 18 additions & 11 deletions packages/core/docs/guides/multilanguage-support.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# Multilanguage support
# Multilanguage support

- Languages are detected from browser language settings.
- If user preffered language is not supported, english is rendered as default.
- If user preffered language is not supported, english is rendered as default.

## Supported languages

- English
- Spanish
- Spanish
- Chinese
- Bulgarian
- Vietnamese
- Vietnamese
- Korean
- Arabic
- Hindi


## How to use
## How to use

- Language files are located in locale folder in `packages\core\src\lib\locale`
- In order for text to be translated `translate` function should be used
- In order for text to be translated `translate` function should be used
as in example below
- Can be extended when needed following `packageName.section.translationKey`structure

Expand All @@ -32,7 +32,7 @@
}
```

- File where translated text is rendered
- File where translated text is rendered

```ts
import { translate } from "@near-wallet-selector/core";
Expand All @@ -49,8 +49,8 @@
<p>${translate("modal.wallet.whatIsAWallet")}</p>
```


## Adding new language

- Language files are located in locale folder in `packages\core\src\lib\locale`
- Files are named after ISO 639-1: two-letter language code
- Keys are named in camelCase as the beginning of the string always in English, with the following pattern used :
Expand All @@ -65,7 +65,7 @@
}
```

- When new language is introduced it must be added to `packages\core\src\lib\translate\translate.ts`
- When new language is introduced it must be added to `packages\core\src\lib\translate\translate.ts`

```ts
import en from "../locale/en.json";
Expand All @@ -87,6 +87,13 @@
};
```

- Supported language should be added to **Supported Languages** [list](https://github.com/near/wallet-selector/blob/dev/packages/core/docs/guides/multilanguage-support.md#supported-languages).
- Supported language should be added to **Supported
Languages** [list](https://github.com/near/wallet-selector/blob/dev/packages/core/docs/guides/multilanguage-support.md#supported-languages) and type list
.

- Pull request title should be named as **"Add support for `LanguageName` language"**.

## Set custom language
- Set the `languageCode` in the [Options](../../README.md#options) of `setupWalletSelector(options)`
- This disables language detection and allows to set only one to be used.
- The `languageCode` must be an ISO 639-1: two-letter language code from [Supported Languages](#supported-languages)
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-wallet-selector/core",
"version": "7.9.1",
"version": "7.9.2",
"description": "This is the core package for NEAR Wallet Selector.",
"keywords": [
"near",
Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export type {

export type { FinalExecutionOutcome } from "near-api-js/lib/providers";

export { waitFor, getActiveAccount } from "./lib/helpers";
export {
waitFor,
getActiveAccount,
isCurrentBrowserSupported,
} from "./lib/helpers";

export { translate } from "./lib/translate/translate";
export { translate, allowOnlyLanguage } from "./lib/translate/translate";
119 changes: 119 additions & 0 deletions packages/core/src/lib/helpers/detect-browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/* eslint-disable no-useless-escape */
// https://github.com/DamonOehlman/detect-browser/blob/master/src/index.ts

export type Browser =
| "aol"
| "edge"
| "edge-ios"
| "yandexbrowser"
| "kakaotalk"
| "samsung"
| "silk"
| "miui"
| "beaker"
| "edge-chromium"
| "chrome"
| "chromium-webview"
| "phantomjs"
| "crios"
| "firefox"
| "fxios"
| "opera-mini"
| "opera"
| "pie"
| "netfront"
| "ie"
| "bb10"
| "android"
| "ios"
| "safari"
| "facebook"
| "instagram"
| "ios-webview"
| "curl"
| "searchbot";

type UserAgentMatch = [Browser, RegExpExecArray] | false;
type UserAgentRule = [Browser, RegExp];

const SEARCHBOX_UA_REGEX =
/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/;
const userAgentRules: Array<UserAgentRule> = [
["aol", /AOLShield\/([0-9\._]+)/],
["edge", /Edge\/([0-9\._]+)/],
["edge-ios", /EdgiOS\/([0-9\._]+)/],
["yandexbrowser", /YaBrowser\/([0-9\._]+)/],
["kakaotalk", /KAKAOTALK\s([0-9\.]+)/],
["samsung", /SamsungBrowser\/([0-9\.]+)/],
["silk", /\bSilk\/([0-9._-]+)\b/],
["miui", /MiuiBrowser\/([0-9\.]+)$/],
["beaker", /BeakerBrowser\/([0-9\.]+)/],
["edge-chromium", /EdgA?\/([0-9\.]+)/],
[
"chromium-webview",
/(?!Chrom.*OPR)wv\).*Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/,
],
["chrome", /(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],
["phantomjs", /PhantomJS\/([0-9\.]+)(:?\s|$)/],
["crios", /CriOS\/([0-9\.]+)(:?\s|$)/],
["firefox", /Firefox\/([0-9\.]+)(?:\s|$)/],
["fxios", /FxiOS\/([0-9\.]+)/],
["opera-mini", /Opera Mini.*Version\/([0-9\.]+)/],
["opera", /Opera\/([0-9\.]+)(?:\s|$)/],
["opera", /OPR\/([0-9\.]+)(:?\s|$)/],
["pie", /^Microsoft Pocket Internet Explorer\/(\d+\.\d+)$/],
[
"pie",
/^Mozilla\/\d\.\d+\s\(compatible;\s(?:MSP?IE|MSInternet Explorer) (\d+\.\d+);.*Windows CE.*\)$/,
],
["netfront", /^Mozilla\/\d\.\d+.*NetFront\/(\d.\d)/],
["ie", /Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],
["ie", /MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],
["ie", /MSIE\s(7\.0)/],
["bb10", /BB10;\sTouch.*Version\/([0-9\.]+)/],
["android", /Android\s([0-9\.]+)/],
["ios", /Version\/([0-9\._]+).*Mobile.*Safari.*/],
["safari", /Version\/([0-9\._]+).*Safari/],
["facebook", /FB[AS]V\/([0-9\.]+)/],
["instagram", /Instagram\s([0-9\.]+)/],
["ios-webview", /AppleWebKit\/([0-9\.]+).*Mobile/],
["ios-webview", /AppleWebKit\/([0-9\.]+).*Gecko\)$/],
["curl", /^curl\/([0-9\.]+)$/],
["searchbot", SEARCHBOX_UA_REGEX],
];

const matchUserAgent = (ua: string): UserAgentMatch => {
return (
ua !== "" &&
userAgentRules.reduce<UserAgentMatch>(
(matched: UserAgentMatch, [browser, regex]) => {
if (matched) {
return matched;
}

const uaMatch = regex.exec(ua);
return !!uaMatch && [browser, uaMatch];
},
false
)
);
};

export const isCurrentBrowserSupported = (
supportedBrowser: Array<Browser>
): boolean => {
if (typeof navigator === "undefined") {
return false;
}
const matchedRule: UserAgentMatch = matchUserAgent(navigator.userAgent);
if (!matchedRule) {
return false;
}

const [name] = matchedRule;
if (name === "searchbot") {
return false;
}

return !!supportedBrowser.find((item) => item === name);
};
1 change: 1 addition & 0 deletions packages/core/src/lib/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./waitFor";
export * from "./getActiveAccount";
export * from "./detect-browser";
1 change: 1 addition & 0 deletions packages/core/src/lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const resolveNetwork = (network: NetworkId | Network): Network => {

export const resolveOptions = (params: WalletSelectorParams) => {
const options: Options = {
languageCode: params.languageCode || undefined,
network: resolveNetwork(params.network),
debug: params.debug || false,
optimizeWalletOrder: params.optimizeWalletOrder === false ? false : true,
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/lib/options.types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { SupportedLanguage } from "./translate/translate";

export type NetworkId = "mainnet" | "testnet";

export interface Network {
Expand All @@ -9,6 +11,7 @@ export interface Network {
}

export interface Options {
languageCode: SupportedLanguage | undefined;
network: Network;
debug: boolean;
optimizeWalletOrder: boolean;
Expand Down
Loading

0 comments on commit f9e7566

Please sign in to comment.