Skip to content

Commit

Permalink
Merge pull request #345 from tonkeeper/feature/trx-usdt
Browse files Browse the repository at this point in the history
Tron USDT
  • Loading branch information
KuznetsovNikita authored Jan 7, 2025
2 parents 7fbaac8 + 15803ab commit 2f5bfdf
Show file tree
Hide file tree
Showing 124 changed files with 3,109 additions and 4,838 deletions.
1 change: 1 addition & 0 deletions apps/desktop/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ REACT_APP_TONCONSOLE_API=https://dev-pro.tonconsole.com
REACT_APP_TG_BOT_ID=6345183204
REACT_APP_TG_BOT_ORIGIN=https://tonkeeper.com
REACT_APP_STONFI_REFERRAL_ADDRESS=UQCthC8ICK7K8Hkfm9smblLFroKrYrEMwZuoD4Nbm5LswUnc
REACT_APP_TRON_API_KEY=
5 changes: 4 additions & 1 deletion apps/desktop/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import { useGlobalPreferencesQuery } from '@tonkeeper/uikit/dist/state/global-pr
import { DesktopManageMultisigsPage } from '@tonkeeper/uikit/dist/desktop-pages/manage-multisig-wallets/DesktopManageMultisigs';
import { useGlobalSetup } from '@tonkeeper/uikit/dist/state/globalSetup';
import { DesktopMultisigOrdersPage } from '@tonkeeper/uikit/dist/desktop-pages/multisig-orders/DesktopMultisigOrders';
import { TronApi } from '@tonkeeper/core/dist/tronApi';

const queryClient = new QueryClient({
defaultOptions: {
Expand Down Expand Up @@ -134,6 +135,7 @@ const langs = 'en,zh_TW,zh_CN,id,ru,it,es,uk,tr,bg,uz,bn';
declare const REACT_APP_TONCONSOLE_API: string;
declare const REACT_APP_TG_BOT_ID: string;
declare const REACT_APP_STONFI_REFERRAL_ADDRESS: string;
declare const REACT_APP_TRON_API_KEY: string;

export const Providers = () => {
const { t: tSimple, i18n } = useTranslation();
Expand Down Expand Up @@ -333,7 +335,8 @@ export const Loader: FC = () => {
ios: false,
env: {
tgAuthBotId: REACT_APP_TG_BOT_ID,
stonfiReferralAddress: REACT_APP_STONFI_REFERRAL_ADDRESS
stonfiReferralAddress: REACT_APP_STONFI_REFERRAL_ADDRESS,
tronApiKey: REACT_APP_TRON_API_KEY
},
defaultWalletVersion: WalletVersion.V5R1
};
Expand Down
3 changes: 2 additions & 1 deletion apps/desktop/webpack.plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const plugins = [
process.env.REACT_APP_STONFI_REFERRAL_ADDRESS
),
REACT_APP_APTABASE: JSON.stringify(process.env.REACT_APP_APTABASE),
REACT_APP_APTABASE_HOST: JSON.stringify(process.env.REACT_APP_APTABASE_HOST)
REACT_APP_APTABASE_HOST: JSON.stringify(process.env.REACT_APP_APTABASE_HOST),
REACT_APP_TRON_API_KEY: JSON.stringify(process.env.REACT_APP_TRON_API_KEY)
})
];
3 changes: 2 additions & 1 deletion apps/extension/config-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module.exports = function override(config, env) {
...config.resolve.fallback,
buffer: require.resolve('buffer'),
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify')
stream: require.resolve('stream-browserify'),
'process/browser': require.resolve('process/browser')
};

config.resolve.alias = {
Expand Down
5 changes: 4 additions & 1 deletion apps/extension/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@ export const Loader: FC = React.memo(() => {
hideSigner: true,
hideMam: true,
hideMultisig: true,
defaultWalletVersion: WalletVersion.V5R1
defaultWalletVersion: WalletVersion.V5R1,
env: {
tronApiKey: process.env.REACT_APP_TRON_API_KEY
}
};

return (
Expand Down
1 change: 1 addition & 0 deletions apps/tablet/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ VITE_APP_TONCONSOLE_HOST=https://pro.tonconsole.com
VITE_APP_TG_BOT_ID=6345183204
VITE_APP_TG_BOT_ORIGIN=https://tonkeeper.com
VITE_APP_STONFI_REFERRAL_ADDRESS=UQCthC8ICK7K8Hkfm9smblLFroKrYrEMwZuoD4Nbm5LswUnc
VITE_APP_TRON_API_KEY=
3 changes: 2 additions & 1 deletion apps/tablet/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ export const Loader: FC = () => {
ios: false,
env: {
tgAuthBotId: import.meta.env.VITE_APP_TG_BOT_ID,
stonfiReferralAddress: import.meta.env.VITE_APP_STONFI_REFERRAL_ADDRESS
stonfiReferralAddress: import.meta.env.VITE_APP_STONFI_REFERRAL_ADDRESS,
tronApiKey: import.meta.env.VITE_APP_TRON_API_KEY
},
defaultWalletVersion: WalletVersion.V5R1
};
Expand Down
5 changes: 4 additions & 1 deletion apps/twa/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,10 @@ export const Loader: FC<{ sdk: TwaAppSdk }> = ({ sdk }) => {
hideMam: true,
hideMultisig: true,
defaultWalletVersion: WalletVersion.V5R1,
browserLength: 4
browserLength: 4,
env: {
tronApiKey: import.meta.env.VITE_APP_TRON_API_KEY
}
};

return (
Expand Down
45 changes: 34 additions & 11 deletions apps/twa/src/components/transfer/SendNotifications.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { TransferInitParams } from '@tonkeeper/core/dist/AppSdk';
import { BLOCKCHAIN_NAME } from '@tonkeeper/core/dist/entries/crypto';
import { AssetAmount } from '@tonkeeper/core/dist/entries/crypto/asset/asset-amount';
import { toTronAsset } from '@tonkeeper/core/dist/entries/crypto/asset/constants';
import { jettonToTonAsset } from '@tonkeeper/core/dist/entries/crypto/asset/ton-asset';
import { RecipientData } from '@tonkeeper/core/dist/entries/send';
import {
Expand Down Expand Up @@ -34,7 +33,7 @@ import { useAppSdk } from '@tonkeeper/uikit/dist/hooks/appSdk';
import { openIosKeyboard } from '@tonkeeper/uikit/dist/hooks/ios';
import { useTranslation } from '@tonkeeper/uikit/dist/hooks/translation';
import { useJettonList } from '@tonkeeper/uikit/dist/state/jetton';
import { useTronBalances } from '@tonkeeper/uikit/dist/state/tron/tron';
import { useActiveTronWallet, useTronBalances } from "@tonkeeper/uikit/dist/state/tron/tron";
import BigNumber from 'bignumber.js';
import { FC, PropsWithChildren, useCallback, useEffect, useMemo, useRef, useState } from "react";
import { CSSTransition, TransitionGroup } from 'react-transition-group';
Expand All @@ -52,6 +51,8 @@ import {
RecipientTwaHeaderBlock
} from './SendNotificationHeader';
import { useAnalyticsTrack } from '@tonkeeper/uikit/dist/hooks/amplitude';
import { TRON_USDT_ASSET } from "@tonkeeper/core/dist/entries/crypto/asset/constants";
import { seeIfValidTronAddress } from "@tonkeeper/core/dist/utils/common";

const Body = styled.div`
padding: 0 16px 16px;
Expand Down Expand Up @@ -93,10 +94,10 @@ const SendContent: FC<{
}
}, []);

const { data: tronBalances } = useTronBalances();

const { mutateAsync: getAccountAsync, isLoading: isAccountLoading } = useGetToAccount();

const activeTronWallet = useActiveTronWallet();

const setRecipient = (value: RecipientData) => {
if (
amountViewState?.token?.blockchain &&
Expand All @@ -106,8 +107,8 @@ const SendContent: FC<{
}

_setRecipient(value);
if (tronBalances && value.address.blockchain === BLOCKCHAIN_NAME.TRON) {
setAmountViewState({ token: toTronAsset(tronBalances.balances[0]) });
if (activeTronWallet && value.address.blockchain === BLOCKCHAIN_NAME.TRON) {
setAmountViewState({ token: TRON_USDT_ASSET });
}
};

Expand Down Expand Up @@ -152,6 +153,9 @@ const SendContent: FC<{
};

const processTron = (address: string) => {
if (!activeTronWallet) {
return;
}
const item = { address: address, blockchain: BLOCKCHAIN_NAME.TRON } as const;

setRecipient({
Expand Down Expand Up @@ -228,10 +232,9 @@ const SendContent: FC<{
return;
}

// TODO: ENABLE TRON
// if (seeIfValidTronAddress(signature)) {
// return processTron(signature);
// }
if (seeIfValidTronAddress(signature)) {
return processTron(signature);
}

return sdk.uiEvents.emit('copy', {
method: 'copy',
Expand All @@ -258,6 +261,19 @@ const SendContent: FC<{
});
}, [amountViewState?.token, amountViewState?.coinValue]);

let acceptBlockchains: BLOCKCHAIN_NAME[] = [];
if (chain) {
if (chain === BLOCKCHAIN_NAME.TRON && !activeTronWallet) {
acceptBlockchains = [BLOCKCHAIN_NAME.TON];
} else {
acceptBlockchains = [chain];
}
} else {
acceptBlockchains = activeTronWallet
? [BLOCKCHAIN_NAME.TON, BLOCKCHAIN_NAME.TRON]
: [BLOCKCHAIN_NAME.TON];
}

return (
<Wrapper standalone={false} extension={true}>
<HideTwaMainButton />
Expand All @@ -279,7 +295,7 @@ const SendContent: FC<{
onScan={onScan}
keyboard="decimal"
isExternalLoading={isAccountLoading}
acceptBlockchains={chain ? [chain] : undefined}
acceptBlockchains={acceptBlockchains}
MainButton={RecipientTwaMainButton}
HeaderBlock={() => <RecipientTwaHeaderBlock onClose={onClose} />}
fitContent
Expand Down Expand Up @@ -348,6 +364,13 @@ export const TwaSendNotification: FC<PropsWithChildren> = ({ children }) => {
reset();
const transfer = options.params;
setChain(chain);

if (transfer.chain === BLOCKCHAIN_NAME.TRON) {
setOpen(true);
track('send_open', { from: transfer.from });
return;
}

if (transfer.address) {
getAccountAsync({ address: transfer.address }).then(account => {
setTonTransfer(makeTransferInitData(transfer, account, jettons));
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ const Loader: FC = () => {
hideMultisig: isMobile,
env: {
tgAuthBotId: import.meta.env.VITE_APP_TG_BOT_ID,
stonfiReferralAddress: import.meta.env.VITE_APP_STONFI_REFERRAL_ADDRESS
stonfiReferralAddress: import.meta.env.VITE_APP_STONFI_REFERRAL_ADDRESS,
tronApiKey: import.meta.env.VITE_APP_TRON_API_KEY
}
};

Expand Down
5 changes: 3 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"start": "tsc -w",
"sdk": "npm-run-all -p generate:*",
"generate:sdkV2": "rm -fr src/tonApiV2 && docker build -f resource/Dockerfile.apiV2 . -t tonapisdkv2 && docker run --rm --user=$(id -u):$(id -g) -v \"$PWD\":/local tonapisdkv2",
"generate:tronApi": "rm -fr src/tronApi && docker build -f resource/Dockerfile.tronApi . -t tronapisdk && docker run --rm --user=$(id -u):$(id -g) -v \"$PWD\":/local tronapisdk",
"generate:tonConsoleApi": "rm -r ./src/tonConsoleApi || true && npx openapi-typescript-codegen --input 'https://raw.githubusercontent.com/tonkeeper/tonconsole_backend/refs/heads/main/swagger.yaml?token=GHSAT0AAAAAACJYQUOCGQXJBM2BFNOB6XREZ2ZZZCA' --output ./src/tonConsoleApi",
"generate:swapsApi": "rm -r ./src/swapsApi || true && npx openapi-typescript-codegen --input 'https://raw.githubusercontent.com/tonkeeper/swaps-backend/master/swagger.yaml?token=GHSAT0AAAAAACJYQUODBKR67AB7WULZBFWEZSUUGFQ' --output ./src/swapsApi",
"generate:batteryApi": "rm -fr ./src/batteryApi && docker build -f resource/Dockerfile.batteryApi . -t batteryapi && docker run --rm --user=$(id -u):$(id -g) -v \"$PWD\":/local batteryapi",
Expand All @@ -27,13 +26,15 @@
"@ledgerhq/hw-transport-webusb": "^6.28.6",
"@ton-community/ton-ledger": "^7.2.0-pre.3",
"@ton-keychain/core": "^0.0.4",
"@ton-keychain/trx": "^0.0.7",
"@ton/core": "0.56.0",
"@ton/crypto": "3.2.0",
"@ton/ton": "^15.1.0",
"bignumber.js": "^9.1.1",
"bip39": "^3.1.0",
"ethers": "^6.6.5",
"ethers": "^6.13.4",
"query-string": "^8.1.0",
"tronweb": "^6.0.0",
"tweetnacl": "^1.0.3"
}
}
3 changes: 0 additions & 3 deletions packages/core/resource/Dockerfile.tronApi

This file was deleted.

5 changes: 5 additions & 0 deletions packages/core/src/AppSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ export type TransferInitParams =
chain: BLOCKCHAIN_NAME.TON;
from: string;
})
| {
chain: BLOCKCHAIN_NAME.TRON;
from: string;
address?: string;
}
| Record<string, never>;

export type ReceiveInitParams = {
Expand Down
Loading

0 comments on commit 2f5bfdf

Please sign in to comment.