fix(deposits): deposit dialog doesn't respect given assetId (#3414)
This commit is contained in:
parent
03f5ca3096
commit
f3fe43724e
@ -100,7 +100,7 @@ export const DepositForm = ({
|
||||
defaultValues: {
|
||||
to: pubKey ? pubKey : undefined,
|
||||
asset: selectedAsset?.id,
|
||||
amount: persistedDeposit.amount,
|
||||
amount: persistedDeposit?.amount,
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -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];
|
||||
|
Loading…
Reference in New Issue
Block a user