Skip to content

Commit 7f9d289

Browse files
authored
Merge pull request #48 from kaleido-io/tokencleanup
Clean up some items around tokens
2 parents 064b027 + 6900215 commit 7f9d289

7 files changed

Lines changed: 33 additions & 13 deletions

File tree

server/src/controllers/tokens.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,17 @@ export class TokensController {
8989
@QueryParam('pool') pool: string,
9090
@QueryParam('key') key: string,
9191
): Promise<TokenBalance[]> {
92+
const poolMap = new Map<string, string>();
9293
const balances = await firefly.getTokenBalances({ pool, key, balance: '>0' });
94+
for (const b of balances) {
95+
if (!poolMap.has(b.pool)) {
96+
const pool = await firefly.getTokenPool(b.pool);
97+
poolMap.set(b.pool, pool.name);
98+
}
99+
}
93100
return balances.map((b) => ({
94101
pool: b.pool,
102+
poolName: poolMap.get(b.pool),
95103
key: b.key,
96104
balance: b.balance,
97105
tokenIndex: b.tokenIndex,
@@ -115,7 +123,7 @@ export class TokensTemplateController {
115123
symbol: <%= ${q('symbol')} %>,
116124
type: <%= ${q('type')} %>,
117125
});
118-
return { type: 'message', id: pool.message };
126+
return { type: 'token_pool', id: pool.id };
119127
`);
120128
}
121129

server/src/interfaces.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ export class TokenBalance {
134134
@IsUUID()
135135
pool: string;
136136

137+
@IsString()
138+
poolName: string;
139+
137140
@IsString()
138141
key: string;
139142

server/test/tokens.template.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('Templates: Tokens', () => {
2323
symbol: 'P1',
2424
type: 'fungible',
2525
});
26-
return { type: 'message', id: pool.message };
26+
return { type: 'token_pool', id: pool.id };
2727
`),
2828
);
2929
});

server/test/tokens.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,15 @@ describe('Tokens', () => {
127127
});
128128

129129
test('Get balances', async () => {
130-
const balances = [{ key: '0x123', balance: '1' } as FireFlyTokenBalance];
130+
const balances = [{ key: '0x123', balance: '1', pool: 'pool1' } as FireFlyTokenBalance];
131131

132+
mockFireFly.getTokenPool.mockResolvedValueOnce({ name: 'pool-name' } as FireFlyTokenPool);
132133
mockFireFly.getTokenBalances.mockResolvedValueOnce(balances);
133134

134135
await request(server)
135136
.get('/api/tokens/balances?pool=pool1&key=0x123')
136137
.expect(200)
137-
.expect([{ key: '0x123', balance: '1' }]);
138+
.expect([{ key: '0x123', balance: '1', pool: 'pool1', poolName: 'pool-name' }]);
138139

139140
expect(mockFireFly.getTokenBalances).toHaveBeenCalledWith({
140141
pool: 'pool1',

ui/src/App.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ function App() {
9494
return createTheme(themeOptions);
9595
}, []);
9696

97+
const isFinalEvent = (t: string) => {
98+
return (
99+
t.endsWith('confirmed') || t.endsWith('rejected') || t.endsWith('failed')
100+
);
101+
};
102+
97103
const addLogToHistory = (event: IEvent) => {
98104
setLogHistory((logHistory) => {
99105
// This is bad practice, and should be optimized in the future
@@ -103,23 +109,23 @@ function App() {
103109

104110
const txMap = deepCopyMap.get(event.tx);
105111
if (txMap !== undefined) {
112+
// TODO: Need better logic
106113
const isComplete = event.reference === dumbAwaitedEventID;
107114
if (isComplete) dumbAwaitedEventID = undefined;
108115

109116
return new Map(
110117
deepCopyMap.set(event.tx, {
111118
events: [event, ...txMap.events],
112119
created: event.created,
113-
// TODO: Need better logic
114-
isComplete,
120+
isComplete: isFinalEvent(event.type),
115121
})
116122
);
117123
} else {
118124
return new Map(
119125
deepCopyMap.set(event.tx, {
120126
events: [event],
121127
created: event.created,
122-
isComplete: event.reference === dumbAwaitedEventID,
128+
isComplete: isFinalEvent(event.type),
123129
})
124130
);
125131
}

ui/src/components/Accordion/TokensStateAccordion.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { SnackbarContext } from '../../contexts/SnackbarContext';
1616
import { ITokenBalance } from '../../interfaces/api';
1717
import { fetchCatcher } from '../../utils/fetches';
1818
import { getShortHash, jsNumberForAddress } from '../../utils/strings';
19-
import { HashPopover } from '../Popovers/HashPopover';
2019
import { FFAccordionText } from './FFAccordionText';
2120

2221
export const TokenStateAccordion: React.FC = () => {
@@ -43,12 +42,14 @@ export const TokenStateAccordion: React.FC = () => {
4342
let balanceMap: {
4443
[key: string]: { balances: ITokenBalance[] };
4544
} = {};
46-
balanceRes.map((b) => {
47-
const balanceArr = balanceMap[b.pool]?.balances ?? [];
48-
45+
balanceRes.forEach((b) => {
46+
if (b.key !== selfIdentity?.ethereum_address) {
47+
return;
48+
}
49+
const balanceArr = balanceMap[b.poolName]?.balances ?? [];
4950
balanceMap = {
5051
...balanceMap,
51-
[b.pool]: {
52+
[b.poolName]: {
5253
balances: [...balanceArr, b],
5354
},
5455
};
@@ -155,7 +156,7 @@ export const TokenStateAccordion: React.FC = () => {
155156
xs={11}
156157
alignItems="center"
157158
>
158-
<HashPopover address={poolIDKey} />
159+
<Typography>{poolIDKey}</Typography>
159160
<Typography
160161
sx={{
161162
paddingLeft: 2,

ui/src/interfaces/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ export interface ITokenApproval {
231231

232232
export interface ITokenBalance {
233233
pool: string;
234+
poolName: string;
234235
key: string;
235236
balance: string;
236237
tokenIndex?: string;

0 commit comments

Comments
 (0)