Skip to content

Commit

Permalink
Create/use factory for Protobuf Address types
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepinho committed Jan 4, 2025
1 parent 6b9ecce commit 145d162
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 18 deletions.
7 changes: 5 additions & 2 deletions react-native-expo/components/ProfileScreen/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import penumbraAddressFactory from '@/factories/penumbraAddress';
import addressFactory from '@/factories/address';
import Avatar from '../Avatar';
import { Sx, Text, View } from 'dripsy';
import Button from '../Button';
Expand All @@ -9,6 +9,9 @@ import AssetIcon from '../AssetIcon';
import ListItemChevronRightSuffix from '../ListItemChevronRightSuffix';
import { useRouter } from 'expo-router';
import { useAppSelector } from '@/store/hooks';
import { bech32mAddress } from '@penumbra-zone/bech32m/penumbra';

const mockAddress = bech32mAddress(addressFactory.build());

export default function ProfileScreen() {
const { t } = useLingui();
Expand All @@ -22,7 +25,7 @@ export default function ProfileScreen() {
<Avatar size='lg' />

<Text sx={sx.address} ellipsizeMode='middle' numberOfLines={1}>
{penumbraAddressFactory.build().value}
{mockAddress}
</Text>

<View sx={sx.buttons}>
Expand Down
8 changes: 4 additions & 4 deletions react-native-expo/components/TransactionList/index.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Meta, StoryObj } from '@storybook/react';

import TransactionList from '.';
import transactionFactory from '@/factories/transaction';
import penumbraAddressFactory from '@/factories/penumbraAddress';
import addressFactory from '@/factories/Address';

const meta: Meta<typeof TransactionList> = {
component: TransactionList,
Expand All @@ -20,18 +20,18 @@ export const Basic: StoryObj<typeof TransactionList> = {
showTitle: true,
transactions: [
transactionFactory.build({
senderAddress: penumbraAddressFactory.build().value,
senderAddress: addressFactory.build().value,
senderUsername: 'henry',
}),
transactionFactory.build({
type: 'send',
recipientAddress: penumbraAddressFactory.build().value,
recipientAddress: addressFactory.build().value,
recipientUsername: 'cate',
via: undefined,
}),
transactionFactory.build({
type: 'send',
recipientAddress: penumbraAddressFactory.build().value,
recipientAddress: addressFactory.build().value,
}),
],
},
Expand Down
13 changes: 13 additions & 0 deletions react-native-expo/factories/address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { PlainMessage } from '@bufbuild/protobuf';
import { Address } from '@penumbra-zone/protobuf/penumbra/core/keys/v1/keys_pb';
import * as Factory from 'factory.ts';
import { generateRandomNumberBetween0And255 } from './helpers';

const addressFactory = Factory.makeFactory<PlainMessage<Address>>({
altBech32m: '',
inner: Factory.each(
() => new Uint8Array(Array(80).fill(null).map(generateRandomNumberBetween0And255)),
),
});

export default addressFactory;
3 changes: 3 additions & 0 deletions react-native-expo/factories/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function generateRandomNumberBetween0And255() {
return Math.round(Math.random() * 255);
}
8 changes: 0 additions & 8 deletions react-native-expo/factories/penumbraAddress.ts

This file was deleted.

9 changes: 5 additions & 4 deletions react-native-expo/store/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import penumbraAddressFactory from '@/factories/penumbraAddress';
import addressFactory from '@/factories/address';
import transactionFactory from '@/factories/transaction';
import Transaction from '@/types/Transaction';
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { bech32mAddress } from '@penumbra-zone/bech32m/penumbra';

export interface TransactionsState {
transactions: Transaction[];
Expand All @@ -12,18 +13,18 @@ const initialState: TransactionsState = {
/** @todo: Populate with real data */
transactions: [
transactionFactory.build({
senderAddress: penumbraAddressFactory.build().value,
senderAddress: bech32mAddress(addressFactory.build()),
senderUsername: 'henry',
}),
transactionFactory.build({
type: 'send',
recipientAddress: penumbraAddressFactory.build().value,
recipientAddress: bech32mAddress(addressFactory.build()),
recipientUsername: 'cate',
via: undefined,
}),
transactionFactory.build({
type: 'send',
recipientAddress: penumbraAddressFactory.build().value,
recipientAddress: bech32mAddress(addressFactory.build()),
}),
],
searchText: '',
Expand Down

0 comments on commit 145d162

Please sign in to comment.