Skip to content

Commit

Permalink
chore(wallet-mobile): storage initialization / new types
Browse files Browse the repository at this point in the history
  • Loading branch information
stackchain committed Apr 26, 2024
1 parent 3786ecc commit 0ebfc5b
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 54 deletions.
2 changes: 1 addition & 1 deletion apps/wallet-mobile/src/WalletNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const WalletTabNavigator = () => {
// keyboardWillShow keyboardWillHiden dont work on android
display: isKeyboardOpen ? 'none' : undefined,
},
tabBarHideOnKeyboard: Platform.OS === 'android',
tabBarHideOnKeyboard: true,
}}
initialRouteName={initialRoute}
backBehavior="initialRoute"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export const buildPortfolioBalanceManager = ({
network: Chain.Network
}) => {
const primaryTokenInfo = network === Chain.Network.Main ? primaryTokenInfoMainnet : primaryTokenInfoAnyTestnet
const balanceStorageMounted = mountMMKVStorage<Portfolio.Token.Id>({path: `/balance/${walletId}/`})
const primaryBreakdownStorageMounted = mountMMKVStorage<Portfolio.Token.Id>({
path: `/primary-breakdown/${walletId}/`,
})
const storage = mountMMKVStorage<Portfolio.Token.Id>({path: `/`, id: `${network}.balance-manager`})
const walletStorage = storage.join(`${walletId}/`)
const balanceStorageMounted = walletStorage.join('secondaries/')
const primaryBreakdownStorageMounted = walletStorage.join('primary/')

const balanceStorage = portfolioBalanceStorageMaker({
balanceStorage: observableStorageMaker(balanceStorageMounted),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ export const usePortfolioTokenManager = ({network}: {network: Chain.Network}) =>
}

export const buildPortfolioTokenManager = ({network}: {network: Chain.Network}) => {
const tokenDiscoveryStorageMounted = mountMMKVStorage<Portfolio.Token.Id>({path: `${network}/token-discovery/`})
const tokenInfoStorageMounted = mountMMKVStorage<Portfolio.Token.Id>({path: `${network}/token-info/`})
const networkStorageMounted = mountMMKVStorage<Portfolio.Token.Id>({path: '/', id: `${network}.token-manager`})
const tokenDiscoveryStorageMounted = networkStorageMounted.join('token-discovery/')
const tokenInfoStorageMounted = networkStorageMounted.join('token-info/')

const tokenStorage = portfolioTokenStorageMaker({
tokenDiscoveryStorage: observableStorageMaker(tokenDiscoveryStorageMounted),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ describe('toBalanceManagerSyncArgs', () => {

expect(result.primaryStated.totalFromTxs).toBe(300n)
expect(result.primaryStated.lockedAsStorageCost).toBe(10n)
expect(result.secondaryBalances.get(`${policyId}.DEAD`)?.balance).toBe(120n)
expect(result.secondaryBalances.get(`${policyId}.DEADFEED`)?.balance).toBe(30n)
expect(result.secondaryBalances.get(`${policyId}.3031`)?.balance).toBe(80n)
expect(result.secondaryBalances.get(`${policyId}.DEAD`)?.quantity).toBe(120n)
expect(result.secondaryBalances.get(`${policyId}.DEADFEED`)?.quantity).toBe(30n)
expect(result.secondaryBalances.get(`${policyId}.3031`)?.quantity).toBe(80n)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import {RawUtxo} from '../../../../yoroi-wallets/types'

export function toBalanceManagerSyncArgs(rawUtxos: RawUtxo[], lockedAsStorageCost: bigint) {
let primaryTokenBalance = 0n
const secondaries = new Map<Portfolio.Token.Id, Omit<Portfolio.Token.Balance, 'info'>>()
const secondaries = new Map<Portfolio.Token.Id, Omit<Portfolio.Token.Amount, 'info'>>()
for (const utxo of rawUtxos) {
primaryTokenBalance += BigInt(utxo.amount)
for (const record of utxo.assets) {
const tokenId: Portfolio.Token.Id = `${record.policyId}.${record.name}`
const balance = (secondaries.get(tokenId)?.balance ?? 0n) + BigInt(record.amount)
const quantity = (secondaries.get(tokenId)?.quantity ?? 0n) + BigInt(record.amount)
secondaries.set(tokenId, {
balance,
quantity,
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const PortfolioScreen = () => {
<View>
<Text>walelt: {walletId}</Text>

<Text>balance: {wallet.primaryBalance.balance.toString()}</Text>
<Text>balance: {wallet.primaryBalance.quantity.toString()}</Text>

<Text>locked: {wallet.primaryBreakdown.lockedAsStorageCost.toString()}</Text>
</View>
Expand All @@ -62,7 +62,7 @@ export const PortfolioScreen = () => {
<View style={{padding: 8, backgroundColor: 'lightgray', marginVertical: 4}}>
<Text>{item.info.name}</Text>

<Text>{item.balance.toString()}</Text>
<Text>{item.quantity.toString()}</Text>
</View>
)}
/>
Expand Down
2 changes: 1 addition & 1 deletion apps/wallet-mobile/src/yoroi-wallets/mocks/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const wallet: YoroiWallet = {
nfts: [],
},
primaryBalance: {
balance: 0n,
quantity: 0n,
info: primaryTokenInfoMainnet,
},
primaryBreakdown: {
Expand Down
16 changes: 8 additions & 8 deletions apps/wallet-mobile/translations/messages/src/AppNavigator.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"start": {
"line": 192,
"column": 17,
"index": 6653
"index": 6734
},
"end": {
"line": 195,
"column": 3,
"index": 6743
"index": 6824
}
},
{
Expand All @@ -21,12 +21,12 @@
"start": {
"line": 196,
"column": 18,
"index": 6763
"index": 6844
},
"end": {
"line": 199,
"column": 3,
"index": 6861
"index": 6942
}
},
{
Expand All @@ -36,12 +36,12 @@
"start": {
"line": 200,
"column": 25,
"index": 6888
"index": 6969
},
"end": {
"line": 203,
"column": 3,
"index": 7002
"index": 7083
}
},
{
Expand All @@ -51,12 +51,12 @@
"start": {
"line": 204,
"column": 27,
"index": 7031
"index": 7112
},
"end": {
"line": 207,
"column": 3,
"index": 7152
"index": 7233
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@
"defaultMessage": "!!!Note:",
"file": "src/TxHistory/TxHistory.tsx",
"start": {
"line": 133,
"line": 129,
"column": 9,
"index": 4322
"index": 4195
},
"end": {
"line": 136,
"line": 132,
"column": 3,
"index": 4421
"index": 4294
}
},
{
"id": "components.txhistory.txhistory.warningbanner.message",
"defaultMessage": "!!!The Shelley protocol upgrade adds a new Shelley wallet type which supports delegation.",
"file": "src/TxHistory/TxHistory.tsx",
"start": {
"line": 137,
"line": 133,
"column": 11,
"index": 4434
"index": 4307
},
"end": {
"line": 140,
"line": 136,
"column": 3,
"index": 4616
"index": 4489
}
}
]
44 changes: 22 additions & 22 deletions apps/wallet-mobile/translations/messages/src/WalletNavigator.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"start": {
"line": 247,
"column": 22,
"index": 8732
"index": 8711
},
"end": {
"line": 250,
"column": 3,
"index": 8835
"index": 8814
}
},
{
Expand All @@ -21,12 +21,12 @@
"start": {
"line": 251,
"column": 14,
"index": 8851
"index": 8830
},
"end": {
"line": 254,
"column": 3,
"index": 8950
"index": 8929
}
},
{
Expand All @@ -36,12 +36,12 @@
"start": {
"line": 255,
"column": 17,
"index": 8969
"index": 8948
},
"end": {
"line": 258,
"column": 3,
"index": 9074
"index": 9053
}
},
{
Expand All @@ -51,12 +51,12 @@
"start": {
"line": 259,
"column": 19,
"index": 9095
"index": 9074
},
"end": {
"line": 262,
"column": 3,
"index": 9192
"index": 9171
}
},
{
Expand All @@ -66,12 +66,12 @@
"start": {
"line": 263,
"column": 18,
"index": 9212
"index": 9191
},
"end": {
"line": 266,
"column": 3,
"index": 9307
"index": 9286
}
},
{
Expand All @@ -81,12 +81,12 @@
"start": {
"line": 267,
"column": 16,
"index": 9325
"index": 9304
},
"end": {
"line": 270,
"column": 3,
"index": 9423
"index": 9402
}
},
{
Expand All @@ -96,12 +96,12 @@
"start": {
"line": 271,
"column": 17,
"index": 9442
"index": 9421
},
"end": {
"line": 274,
"column": 3,
"index": 9507
"index": 9486
}
},
{
Expand All @@ -111,12 +111,12 @@
"start": {
"line": 275,
"column": 14,
"index": 9523
"index": 9502
},
"end": {
"line": 278,
"column": 3,
"index": 9617
"index": 9596
}
},
{
Expand All @@ -126,12 +126,12 @@
"start": {
"line": 279,
"column": 14,
"index": 9633
"index": 9612
},
"end": {
"line": 282,
"column": 3,
"index": 9685
"index": 9664
}
},
{
Expand All @@ -141,12 +141,12 @@
"start": {
"line": 283,
"column": 18,
"index": 9705
"index": 9684
},
"end": {
"line": 286,
"column": 3,
"index": 9794
"index": 9773
}
},
{
Expand All @@ -156,12 +156,12 @@
"start": {
"line": 287,
"column": 31,
"index": 9827
"index": 9806
},
"end": {
"line": 290,
"column": 3,
"index": 9936
"index": 9915
}
}
]

0 comments on commit 0ebfc5b

Please sign in to comment.