Skip to content

Commit

Permalink
fix(mobile): Show locked jettons with zero balances (#783)
Browse files Browse the repository at this point in the history
* update TonAPI JettonBalance type

* fix(mobile): Show in app locked jettons with zero balance

* Remove unnecessary logic

* Fix crash

* fix(mobile): Dot color
  • Loading branch information
voloshinskii authored Apr 9, 2024
1 parent b2b52ec commit f95612a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 20 deletions.
9 changes: 9 additions & 0 deletions packages/@core-js/src/TonAPI/TonAPIGenerated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,15 @@ export interface JettonBalance {
price?: TokenRates;
wallet_address: AccountAddress;
jetton: JettonPreview;
lock?: {
/** @example 597968399 */
amount: string;
/**
* @format int64
* @example 1678223064
*/
till: number;
};
}

export interface JettonsBalances {
Expand Down
5 changes: 3 additions & 2 deletions packages/mobile/src/core/Jetton/Jetton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ export const Jetton: React.FC<JettonProps> = ({ route }) => {
currency: jetton.metadata.symbol,
currencySeparator: 'wide',
})}
 ·
{' '}
<Text variant="body2" color="textTertiary">
{' '}·{' '}
</Text>
{lockedJettonPrice.formatted.totalFiat}
</Text>
<Text variant="body2" color="textTertiary">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const CoinDropdownComponent: FC<Props> = (props) => {

const balances = useBalancesState();

const { enabled: jettons } = useJettonBalances(false, true);
const { enabled: jettons } = useJettonBalances(true);
const inscriptions = useTonInscriptions();
const { format } = useHideableFormatter();

Expand Down
17 changes: 2 additions & 15 deletions packages/mobile/src/hooks/useJettonBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ export interface IBalances {
enabled: JettonBalanceModel[];
disabled: JettonBalanceModel[];
}
export const useJettonBalances = (
withZeroBalances?: boolean,
showStakingJettons = false,
) => {
export const useJettonBalances = (showStakingJettons = false) => {
const { jettonBalances } = useJettons();
const approvalStatuses = useTokenApproval();
const stakingJettons = useStakingState(getStakingJettons);
Expand All @@ -28,10 +25,6 @@ export const useJettonBalances = (
const approvalStatus = approvalStatuses.tokens[jettonAddress];
const isBlacklisted = jetton.verification === JettonVerification.BLACKLIST;

if (!withZeroBalances && jetton.balance === '0') {
return;
}

if (
!showStakingJettons &&
stakingJettons.includes(Address.parse(jetton.jettonAddress).toRaw())
Expand All @@ -50,13 +43,7 @@ export const useJettonBalances = (
});

return balances;
}, [
approvalStatuses.tokens,
jettonBalances,
showStakingJettons,
stakingJettons,
withZeroBalances,
]);
}, [approvalStatuses.tokens, jettonBalances, showStakingJettons, stakingJettons]);

return jettons;
};
2 changes: 1 addition & 1 deletion packages/mobile/src/wallet/managers/JettonsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class JettonsManager {

const jettonBalances = accountJettons.balances
.filter((item) => {
return item.balance !== '0';
return item.balance !== '0' || (item.lock && item.lock.amount !== '0');
})
.sort((a, b) => {
// Unverified or blacklisted tokens have to be at the end of array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class JettonBalanceModel {
jettonBalance.balance,
jettonBalance.jetton.decimals,
);
// @ts-ignore will be implemented in API later

this.lock = jettonBalance.lock && {
amount: AmountFormatter.fromNanoStatic(
jettonBalance.lock.amount,
Expand Down

0 comments on commit f95612a

Please sign in to comment.