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: {
|
defaultValues: {
|
||||||
to: pubKey ? pubKey : undefined,
|
to: pubKey ? pubKey : undefined,
|
||||||
asset: selectedAsset?.id,
|
asset: selectedAsset?.id,
|
||||||
amount: persistedDeposit.amount,
|
amount: persistedDeposit?.amount,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -70,7 +70,8 @@ export const DepositManager = ({
|
|||||||
|
|
||||||
const onAmountChange = useCallback(
|
const onAmountChange = useCallback(
|
||||||
(amount: string) => {
|
(amount: string) => {
|
||||||
savePersistentDeposit({ ...persistentDeposit, amount });
|
persistentDeposit &&
|
||||||
|
savePersistentDeposit({ ...persistentDeposit, amount });
|
||||||
},
|
},
|
||||||
[savePersistentDeposit, persistentDeposit]
|
[savePersistentDeposit, persistentDeposit]
|
||||||
);
|
);
|
||||||
|
@ -4,7 +4,7 @@ import { usePersistentDeposit } from './use-persistent-deposit';
|
|||||||
describe('usePersistenDeposit', () => {
|
describe('usePersistenDeposit', () => {
|
||||||
it('should return empty data', () => {
|
it('should return empty data', () => {
|
||||||
const { result } = renderHook(() => usePersistentDeposit());
|
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 () => {
|
it('should return empty and properly saved data', async () => {
|
||||||
const aId = 'test';
|
const aId = 'test';
|
||||||
|
@ -32,10 +32,14 @@ const usePersistentDepositStore = create<{
|
|||||||
|
|
||||||
export const usePersistentDeposit = (
|
export const usePersistentDeposit = (
|
||||||
assetId?: string
|
assetId?: string
|
||||||
): [PersistedDeposit, (entry: PersistedDeposit) => void] => {
|
): [PersistedDeposit | undefined, (entry: PersistedDeposit) => void] => {
|
||||||
const { deposits, lastVisited, saveValue } = usePersistentDepositStore();
|
const { deposits, lastVisited, saveValue } = usePersistentDepositStore();
|
||||||
const discoveredData = useMemo(() => {
|
const discoveredData = useMemo(() => {
|
||||||
return deposits[assetId || ''] || lastVisited || { assetId: assetId || '' };
|
return assetId
|
||||||
|
? deposits[assetId]
|
||||||
|
? deposits[assetId]
|
||||||
|
: { assetId }
|
||||||
|
: lastVisited;
|
||||||
}, [deposits, lastVisited, assetId]);
|
}, [deposits, lastVisited, assetId]);
|
||||||
|
|
||||||
return [discoveredData, saveValue];
|
return [discoveredData, saveValue];
|
||||||
|
Loading…
Reference in New Issue
Block a user