Skip to content

Commit

Permalink
fix(mobile): TON Content provider fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
voloshinskii committed Apr 11, 2024
1 parent 017dd17 commit 50eda5e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ import { DependencyPrototype } from './utils/prototype';
import { tk } from '$wallet';
import { BalancesState } from '$wallet/managers/BalancesManager';

export enum TonBalanceType {
Liquid = 'Liquid',
Locked = 'Locked',
Restricted = 'Restricted',
}

export type TonBalance = {
type: TonBalanceType;
balance: string;
};

export class TonBalancesDependency extends DependencyPrototype<
BalancesState,
Pick<BalancesState, 'ton' | 'tonLocked' | 'tonRestricted'>
Expand All @@ -18,4 +29,22 @@ export class TonBalancesDependency extends DependencyPrototype<
this.dataProvider = wallet.balances.state;
super.setWallet(wallet);
}

get balances() {
const balances: TonBalance[] = [
{ type: TonBalanceType.Liquid, balance: this.state.ton },
];

if (this.wallet.isLockup) {
balances.push(
{ type: TonBalanceType.Locked, balance: this.state.tonLocked },
{
type: TonBalanceType.Restricted,
balance: this.state.tonRestricted,
},
);
}

return balances;
}
}
39 changes: 9 additions & 30 deletions packages/mobile/src/tabs/Wallet/content-providers/ton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,11 @@ import { openWallet } from '$core/Wallet/ToncoinScreen';
import { CryptoCurrencies } from '$shared/constants';
import { Providers } from './providers';
import { TonPriceDependency } from './dependencies/tonPrice';
import { TonBalancesDependency } from './dependencies/tonBalances';

export enum TonBalanceType {
Liquid = 'Liquid',
Locked = 'Locked',
Restricted = 'Restricted',
}

export type TonBalance = {
type: TonBalanceType;
balance: string;
};
import {
TonBalancesDependency,
TonBalanceType,
TonBalance,
} from './dependencies/tonBalances';

export const mappedTonBalanceTitle = {
[TonBalanceType.Liquid]: 'Toncoin',
Expand All @@ -26,31 +19,17 @@ export const mappedTonBalanceTitle = {

export class TONContentProvider extends ContentProviderPrototype<{
tonPrice: TonPriceDependency;
balances: TonBalancesDependency;
tonBalances: TonBalancesDependency;
}> {
name = Providers.TON;
renderPriority = 999;

constructor(tonPrice: TonPriceDependency, balances: TonBalancesDependency) {
super({ tonPrice, balances });
constructor(tonPrice: TonPriceDependency, tonBalances: TonBalancesDependency) {
super({ tonPrice, tonBalances });
}

get itemsArray() {
const balances: TonBalance[] = [
{ type: TonBalanceType.Liquid, balance: this.deps.balances.state.ton },
];

if (this.wallet.isLockup) {
balances.push(
{ type: TonBalanceType.Locked, balance: this.deps.balances.state.tonLocked },
{
type: TonBalanceType.Restricted,
balance: this.deps.balances.state.tonRestricted,
},
);
}

return balances;
return this.deps.tonBalances.balances;
}

makeCellItemFromData(data: TonBalance): CellItemToRender {
Expand Down

0 comments on commit 50eda5e

Please sign in to comment.