Skip to content

Commit

Permalink
chore: fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
khanti42 committed Jan 28, 2025
1 parent 09bd51d commit 50f73b3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const TransactionListItemView = ({ transaction }: Props) => {
const [txnUsdValue, setTxnUsdValue] = useState('0.00');
const { translate } = useMultiLanguage();

const { language } = useAppSelector((state) => state.wallet);
const { locale } = useAppSelector((state) => state.wallet);

useEffect(() => {
const fetchData = async () => {
Expand All @@ -74,7 +74,7 @@ export const TransactionListItemView = ({ transaction }: Props) => {
}, []);

const txnName = getTxnName(transaction, tokenAddress);
const txnDate = getTxnDate(transaction, language);
const txnDate = getTxnDate(transaction, locale);
const txnStatus = getTxnStatus(transaction);
const txnToFromLabel = '';
const txnFailureReason = getTxnFailureReason(transaction);
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet-ui/src/services/useMultiLanguage.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useAppSelector } from 'hooks/redux';

export const useMultiLanguage = () => {
const { locale } = useAppSelector((state) => state.wallet);
const { translations } = useAppSelector((state) => state.wallet);

const translate = (key: string, ...args: (string | undefined)[]): string => {
const template = locale[key]?.message ?? `{${key}}`;
const template = translations[key]?.message ?? `{${key}}`;

return template.replace(/\{(\d+)\}/g, (_, index: string) => {
const argIndex = parseInt(index, 10) - 1;
Expand Down
14 changes: 7 additions & 7 deletions packages/wallet-ui/src/services/useStarkNetSnap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
setTransactions,
setTransactionDeploy,
setForceReconnect,
setLanguage,
setLocale,
setTranslations,
} from '../slices/walletSlice';
import Toastr from 'toastr2';
import {
Expand Down Expand Up @@ -110,9 +110,9 @@ export const useStarkNetSnap = () => {
});
};

const loadPreferences = async () => {
const loadLocale = async () => {
try {
const { locale: userLocale } = await provider.request({
const { locale } = await provider.request({
method: 'wallet_invokeSnap',
params: {
snapId,
Expand All @@ -121,9 +121,9 @@ export const useStarkNetSnap = () => {
},
},
});
const messages = await import(`../assets/locales/${userLocale}.json`);
dispatch(setLanguage(userLocale as string));
dispatch(setLocale(messages.messages));
const messages = await import(`../assets/locales/${locale}.json`);
dispatch(setLocale(locale));
dispatch(setTranslations(messages.messages));
} catch (error) {
console.error(
'Failed to load user preferences. Falling back to default locale.',
Expand Down Expand Up @@ -257,7 +257,7 @@ export const useStarkNetSnap = () => {
dispatch(setActiveNetwork(idx));
const chainId = net.chainId;
await getWalletData(chainId, nets);
await loadPreferences();
await loadLocale();
} catch (err: any) {
if (err.code && err.code === 4100) {
const toastr = new Toastr();
Expand Down
16 changes: 8 additions & 8 deletions packages/wallet-ui/src/slices/walletSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import defaultLocale from '../assets/locales/en.json';
export interface WalletState {
connected: boolean;
isLoading: boolean;
language: string;
locale: Locale;
locale: string;
translations: Locale;
forceReconnect: boolean;
accounts: Account[];
erc20TokenBalances: Erc20TokenBalance[];
Expand All @@ -22,8 +22,8 @@ export interface WalletState {
const initialState: WalletState = {
connected: false,
isLoading: false,
language: 'en',
locale: defaultLocale.messages,
locale: 'en',
translations: defaultLocale.messages,
forceReconnect: false,
accounts: [],
erc20TokenBalances: [],
Expand All @@ -37,12 +37,12 @@ export const walletSlice = createSlice({
name: 'wallet',
initialState,
reducers: {
setLanguage: (state, { payload }) => {
state.language = payload;
},
setLocale: (state, { payload }) => {
state.locale = payload;
},
setTranslations: (state, { payload }) => {
state.translations = payload;
},
setProvider: (state, { payload }) => {
state.provider = payload;
},
Expand Down Expand Up @@ -128,7 +128,7 @@ export const {
setTransactionDeploy,
resetWallet,
setProvider,
setLanguage,
setTranslations,
setLocale,
} = walletSlice.actions;

Expand Down

0 comments on commit 50f73b3

Please sign in to comment.