Compare commits

...
Author SHA1 Message Date
maciek eb888d69ca fix: deposit dialog doesnt respect given assetId 2023-04-11 15:50:18 +02:00
maciek 43d726f25c fix: deposit dialog doesnt respect given assetId 2023-04-11 15:40:21 +02:00
4 changed files with 10 additions and 5 deletions
+1 -1
View File
@@ -100,7 +100,7 @@ export const DepositForm = ({
defaultValues: {
to: pubKey ? pubKey : undefined,
asset: selectedAsset?.id,
amount: persistedDeposit.amount,
amount: persistedDeposit?.amount,
},
});
+2 -1
View File
@@ -70,7 +70,8 @@ export const DepositManager = ({
const onAmountChange = useCallback(
(amount: string) => {
savePersistentDeposit({ ...persistentDeposit, amount });
persistentDeposit &&
savePersistentDeposit({ ...persistentDeposit, amount });
},
[savePersistentDeposit, persistentDeposit]
);
@@ -4,7 +4,7 @@ import { usePersistentDeposit } from './use-persistent-deposit';
describe('usePersistenDeposit', () => {
it('should return empty data', () => {
const { result } = renderHook(() => usePersistentDeposit());
expect(result.current).toEqual([{ assetId: '' }, expect.any(Function)]);
expect(result.current).toEqual([undefined, expect.any(Function)]);
});
it('should return empty and properly saved data', async () => {
const aId = 'test';
@@ -32,10 +32,14 @@ const usePersistentDepositStore = create<{
export const usePersistentDeposit = (
assetId?: string
): [PersistedDeposit, (entry: PersistedDeposit) => void] => {
): [PersistedDeposit | undefined, (entry: PersistedDeposit) => void] => {
const { deposits, lastVisited, saveValue } = usePersistentDepositStore();
const discoveredData = useMemo(() => {
return deposits[assetId || ''] || lastVisited || { assetId: assetId || '' };
return assetId
? deposits[assetId]
? deposits[assetId]
: { assetId }
: lastVisited;
}, [deposits, lastVisited, assetId]);
return [discoveredData, saveValue];