Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

battery hotfix #700

Merged
merged 5 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/@core-js/src/TonAPI/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type CancelToken = Symbol | string | number;

export type HttpClientOptions = {
baseUrl: string | (() => string);
token?: string | (() => string);
baseHeaders?: { [key: string]: string } | (() => { [key: string]: string });
};

export class HttpClient {
Expand Down Expand Up @@ -143,18 +143,18 @@ export class HttpClient {
typeof this.options.baseUrl === 'function'
? this.options.baseUrl()
: this.options.baseUrl;
const token =
typeof this.options.token === 'function'
? this.options.token()
: this.options.token;
const baseHeaders =
typeof this.options.baseHeaders === 'function'
? this.options.baseHeaders()
: this.options.baseHeaders;

const response = await this.customFetch(
`${baseUrl}${path}${queryString ? `?${queryString}` : ''}`,
{
method,
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
...(baseHeaders ?? {}),
...(headers ?? {}),
},
signal: cancelToken ? this.createAbortSignal(cancelToken) : null,
Expand Down
2 changes: 1 addition & 1 deletion packages/mobile/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ android {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 433
versionName "3.6.1"
versionName "3.6.2"
missingDimensionStrategy 'react-native-camera', 'general'
missingDimensionStrategy 'store', 'play'
}
Expand Down
4 changes: 2 additions & 2 deletions packages/mobile/ios/ton_keeper.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 3.6.1;
MARKETING_VERSION = 3.6.2;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
Expand Down Expand Up @@ -1328,7 +1328,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 3.6.1;
MARKETING_VERSION = 3.6.2;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const AccessConfirmation: FC = () => {
}
}
},
[dispatch, isBiometryFailed, isUnlock, triggerError, wallet],
[dispatch, isBiometryFailed, isUnlock, obtainTonProof, triggerError, wallet],
);

const handleBiometry = useCallback(() => {
Expand All @@ -175,6 +175,9 @@ export const AccessConfirmation: FC = () => {
setTimeout(async () => {
// Lock screen
if (isUnlock) {
const keyPair = await (unlockedVault as any).getKeyPair();
// createTronAddress(privateKey);
obtainTonProof(keyPair);
dispatch(mainActions.setUnlocked(true));
} else {
goBack();
Expand All @@ -187,7 +190,7 @@ export const AccessConfirmation: FC = () => {
setBiometryFailed(true);
triggerError();
});
}, [dispatch, isUnlock, triggerError, wallet]);
}, [dispatch, isUnlock, obtainTonProof, triggerError, wallet]);

useEffect(() => {
if (params.withoutBiometryOnOpen) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { t } from '@tonkeeper/shared/i18n';
import { Ton } from '$libs/Ton';
import { getServerConfig } from '$shared/constants';
import { Configuration, NFTApi } from '@tonkeeper/core/src/legacy';
import { sendBocWithBattery } from '@tonkeeper/shared/utils/blockchain';
import { tonapi } from '@tonkeeper/shared/tonkeeper';

const { NftItem } = TonWeb.token.nft;
Expand Down Expand Up @@ -172,7 +171,7 @@ export class NFTOperations {
const queryMsg = await methods.getQuery();
const boc = Base64.encodeBytes(await queryMsg.toBoc(false));

await sendBocWithBattery(boc);
await tonapi.blockchain.sendBlockchainMessage({ boc }, { format: 'text' });

onDone?.(boc);
},
Expand Down
2 changes: 1 addition & 1 deletion packages/mobile/src/core/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const Settings: FC = () => {
const shouldShowTokensButton = useShouldShowTokensButton();
const showNotifications = useNotificationsStore(shouldShowNotifications);

const isBatteryVisible = !config.get('disable_battery');
const isBatteryVisible = !!wallet && !config.get('disable_battery');

const searchEngine = useBrowserStore((state) => state.searchEngine);
const setSearchEngine = useBrowserStore((state) => state.actions.setSearchEngine);
Expand Down
19 changes: 12 additions & 7 deletions packages/shared/components/RefillBattery/RefillBattery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export const RefillBattery = memo(() => {
const { balance } = useBatteryBalance();
const batteryState = getBatteryState(balance ?? '0');
const iconName = iconNames[batteryState];
const availableNumOfTransactionsCount = calculateAvailableNumOfTransactions(
balance ?? '0',
);

const isInAppPurchasesDisabled = config.get('disable_battery_iap_module');

Expand All @@ -39,10 +42,14 @@ export const RefillBattery = memo(() => {
<Text textAlign="center" type="body2" color="textSecondary">
{t(
`battery.description.${
batteryState === BatteryState.Empty ? 'empty' : 'other'
batteryState === BatteryState.Empty
? 'empty'
: availableNumOfTransactionsCount
? 'other'
: 'less_10'
}`,
{
cnt: calculateAvailableNumOfTransactions(balance ?? '0'),
cnt: availableNumOfTransactionsCount,
},
)}
</Text>
Expand All @@ -52,11 +59,9 @@ export const RefillBattery = memo(() => {
{!isInAppPurchasesDisabled ? <RefillBatteryIAP /> : null}
<RechargeByPromoButton />
<Spacer y={16} />
{!isInAppPurchasesDisabled && (
<Text type="label2" textAlign="center" color="textTertiary">
{t('battery.packages.disclaimer')}
</Text>
)}
<Text type="label2" textAlign="center" color="textTertiary">
{t('battery.packages.disclaimer')}
</Text>
</View>
</>
);
Expand Down
9 changes: 5 additions & 4 deletions packages/shared/i18n/locales/tonkeeper/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@
},
"description": {
"empty": "Send tokens and NFTs, pay for staking actions with empty main balance.",
"other": "You have enough charge battery for more than %{cnt} transactions."
"other": "You have enough charge battery for more than %{cnt} transactions.",
"less_10": "You have enough charge battery for less than 10 transactions."
},
"promocode": {
"button": "Recharge by Promo Code",
Expand All @@ -148,9 +149,9 @@
"packages": {
"title": "{{cnt}} transactions for {{price}}",
"subtitle": {
"large": "Large gas fees pack",
"medium": "Medium gas fees pack",
"small": "Small gas fees pack"
"large": "Large pack",
"medium": "Medium pack",
"small": "Small pack"
},
"disclaimer": "This is approximate transactions number. Some your transactions may cost more.",
"buy": "Buy",
Expand Down
4 changes: 3 additions & 1 deletion packages/shared/i18n/locales/tonkeeper/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,7 @@
},
"comment" : "Комментарий",
"insufficientFunds" : {
"rechargeBattery": "Зарядить батарейку",
"rechargeWallet" : "Пополнить кошелёк",
"stakingFee" : {
"few" : "Для совершения транзакции необходимо %{count} TON. Предполагаемая комиссия в размере %{fee} TON будет удержана, остаток будет возвращён.",
Expand Down Expand Up @@ -1072,7 +1073,8 @@
},
"description": {
"empty": "Отправляйте токены и NFT, взаимодействуйте со стейкингом при нулевом балансе кошелька.",
"other": "У вас достаточно заряда для более чем {{cnt}} транзакций."
"other": "У вас достаточно заряда для более чем {{cnt}} транзакций.",
"less_10": "У вас достаточно заряда для менее чем 10 транзакций."
},
"promocode": {
"button": "Зарядить с помощью промокода",
Expand Down
8 changes: 7 additions & 1 deletion packages/shared/tonkeeper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ import { queryClient } from './queryClient';
import { TonAPI } from '@tonkeeper/core';
import { config } from './config';
import { BatteryAPI } from '@tonkeeper/core/src/BatteryAPI';
import { i18n } from './i18n';

export const sse = new AppServerSentEvents({
baseUrl: () => config.get('tonapiIOEndpoint'),
token: () => config.get('tonApiV2Key'),
});

export const tonapi = new TonAPI({
token: () => config.get('tonApiV2Key'),
baseHeaders: () => ({
Authorization: `Bearer ${config.get('tonApiV2Key')}`,
}),
baseUrl: () => {
if (tk.wallet?.identity.network === WalletNetwork.testnet) {
return config.get('tonapiTestnetHost');
Expand Down Expand Up @@ -43,6 +46,9 @@ export const batteryapi = new BatteryAPI({

return config.get('batteryHost');
},
baseHeaders: {
'Accept-Language': i18n.locale,
},
});

export const storage = new AppStorage();
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/utils/battery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ export function calculateAvailableNumOfTransactions(batteryBalance: string) {
.div(10)
.decimalPlaces(0, BigNumber.ROUND_DOWN)
.times(10)
.toString();
.toNumber();
}
6 changes: 6 additions & 0 deletions packages/uikit/src/components/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,17 @@ export const Input = forwardRef<InputRef, InputProps>((props, ref) => {
const handlePastePress = useCallback(async () => {
try {
const str = await Clipboard.getString();
if (onChangeText) {
onChangeText(str);
}
setInputValue(str);
} catch {}
}, []);

const handlePressClear = useCallback(() => {
if (onChangeText) {
onChangeText('');
}
setInputValue('');
}, []);

Expand Down
Loading