Skip to content

Commit

Permalink
fix(mobile): Swap domain with app name in TonConnectModal (#683)
Browse files Browse the repository at this point in the history
* fix(mobile): Swap domain with app name in TonConnectModal

* fix(mobile): Add typings
  • Loading branch information
voloshinskii authored Jan 23, 2024
1 parent 09ca445 commit 1d656c2
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 8 deletions.
9 changes: 7 additions & 2 deletions packages/mobile/src/core/TonConnect/TonConnectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { WalletApi, Configuration } from '@tonkeeper/core/src/legacy';
import * as SecureStore from 'expo-secure-store';
import { Address } from '@tonkeeper/core';
import { shouldShowNotifications } from '$store/zustand/notifications/selectors';
import { replaceString } from '@tonkeeper/shared/utils/replaceString';

export const TonConnectModal = (props: TonConnectModalProps) => {
const animation = useTonConnectAnimation();
Expand Down Expand Up @@ -322,11 +323,15 @@ export const TonConnectModal = (props: TonConnectModalProps) => {
<S.Content>
<S.TitleWrapper>
<Text variant="h2" textAlign="center">
{t('ton_login_title', { name: appName })}
{replaceString(t('ton_login_title'), '%domain', () => (
<Text key={domain} variant="h2" color="accentBlue">
{domain}
</Text>
))}
</Text>
</S.TitleWrapper>
<Text color="foregroundSecondary" variant="body1" textAlign="center">
{t('ton_login_caption', { name: domain })}
{t('ton_login_caption', { name: appName })}
<Text color="foregroundTertiary" variant="body1" textAlign="center">
{maskedAddress}{' '}
</Text>
Expand Down
1 change: 1 addition & 0 deletions packages/mobile/src/styled/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export enum COMMON_COLORS {
accentPrimaryDark = '#378BC4',
accentPositive = '#39CC83',
accentNegative = '#FF4766',
accentBlue = '#45AEF5',
accentOrange = '#F2A73D',
accentOrangeActive = '#F2B155',
}
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/i18n/locales/tonkeeper/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@
"ton_login_connect_button" : "Connect wallet",
"ton_login_notice" : "Be sure to check the service address before connecting the wallet.",
"ton_login_success" : "Done",
"ton_login_title" : "Connect to %{name}?",
"ton_login_title" : "Connect to %domain?",
"transaction_bid_collection_name" : "Issuer",
"transaction_bid_date" : "Bid %{date}",
"transaction_bid_dns" : "Name",
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/i18n/locales/tonkeeper/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@
"ton_login_connect_button" : "Collega wallet",
"ton_login_notice" : "Assicurati di controllare l'indirizzo del servizio prima di collegare il wallet.",
"ton_login_success" : "Fatto",
"ton_login_title" : "Connetti a %{name}?",
"ton_login_title" : "Connetti a %domain?",
"transaction_bid_collection_name" : "Emittente",
"transaction_bid_date" : "Offerta %{date}",
"transaction_bid_dns" : "Nome",
Expand Down Expand Up @@ -697,4 +697,4 @@
"wallet_toncommunity_chat_link" : "https://t.me/toncoin_it_chat",
"wallet_toncommunity_link" : "https://t.me/toncoin_it",
"yesterday" : "Ieri"
}
}
2 changes: 1 addition & 1 deletion packages/shared/i18n/locales/tonkeeper/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@
"ton_login_connect_button" : "Подключить кошелёк",
"ton_login_notice" : "Обязательно проверьте адрес сервиса перед подключением кошелька.",
"ton_login_success" : "Готово",
"ton_login_title" : "Войти в %{name}",
"ton_login_title" : "Войти в %domain",
"transaction_bid_collection_name" : "Эмитент",
"transaction_bid_date" : "Ставка %{date}",
"transaction_bid_dns" : "Имя",
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/i18n/locales/tonkeeper/tr-TR.json
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@
"ton_login_connect_button" : "Cüzdanı bağlayın",
"ton_login_notice" : "Cüzdanı bağlamadan önce servis adresini kontrol ettiğinizden emin olun.",
"ton_login_success" : "Tamamlandı",
"ton_login_title" : "%{name}'e bağlanılsın mı?",
"ton_login_title" : "%domain'e bağlanılsın mı?",
"transaction_bid_collection_name" : "Koleksiyon yayıncısı",
"transaction_bid_date" : "%{date} tarihli teklif",
"transaction_bid_dns" : "İsim",
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/i18n/locales/tonkeeper/zh-Hans-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@
"ton_login_connect_button" : "连接钱包",
"ton_login_notice" : "连接钱包之前,请务必检查服务地址。",
"ton_login_success" : "完成",
"ton_login_title" : "连接到%{name}",
"ton_login_title" : "连接到%domain",
"transaction_bid_collection_name" : "发行者",
"transaction_bid_date" : "出价日期 %{date}",
"transaction_bid_dns" : "名称",
Expand Down
45 changes: 45 additions & 0 deletions packages/shared/utils/replaceString.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { isString } from '@tonkeeper/uikit';
import React from 'react';

let escapeRegExp = function escapeRegExp(str: string) {
let reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
reHasRegExpChar = RegExp(reRegExpChar.source);

return str && reHasRegExpChar.test(str) ? str.replace(reRegExpChar, '\\$&') : str;
};

export function replaceString(
str: string,
match: string,
fn: (str: string, i: number, c: number) => React.ReactNode,
): React.ReactNode[] | React.ReactNode {
let curCharStart = 0;
let curCharLen = 0;

if (str === '') {
return str;
} else if (!str || !isString(str)) {
throw new TypeError(
'First argument to react-string-replace#replaceString must be a string',
);
}

let re = new RegExp('(' + escapeRegExp(match) + ')', 'gi');

let matches: undefined | string[] = str.split(re);
let toReturn: React.ReactNode = matches;

for (let i = 1, length = matches.length; i < length; i += 2) {
if (matches[i] === undefined || matches[i - 1] === undefined) {
console.warn('Encountered undefined value during string replacement');
continue;
}

curCharLen = matches[i].length;
curCharStart += matches[i - 1].length;
toReturn[i] = fn(matches[i], i, curCharStart);
curCharStart += curCharLen;
}

return toReturn;
}

0 comments on commit 1d656c2

Please sign in to comment.