-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57dc734
commit ca6feb5
Showing
4 changed files
with
133 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from 'react'; | ||
import { Box, BoxProps } from '@nelson-ui/react'; | ||
|
||
export const CloseIcon: React.FC<BoxProps> = props => { | ||
return ( | ||
<Box display="inline-block" height="12px" width="13px" {...props}> | ||
<svg | ||
width="12" | ||
height="13" | ||
viewBox="0 0 12 13" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M1 1.5L11 11.5" | ||
stroke="#FFA953" | ||
strokeWidth="1.5" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
/> | ||
<path | ||
d="M11 1.5L1 11.5" | ||
stroke="#FFA953" | ||
strokeWidth="1.5" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
/> | ||
</svg> | ||
</Box> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { Box, SpaceBetween, Stack } from '@nelson-ui/react'; | ||
import { useAtomValue } from 'jotai/utils'; | ||
import { useRouter } from 'next/router'; | ||
import React, { useCallback, useMemo, useState } from 'react'; | ||
import { allSwapsState } from '../common/store/swaps'; | ||
import { CloseIcon } from './icons/close'; | ||
import { PendingIcon } from './icons/pending'; | ||
import { SafeSuspense } from './safe-suspense'; | ||
import { Text } from './text'; | ||
|
||
export const PendingSwap: React.FC = () => { | ||
const allSwaps = useAtomValue(allSwapsState); | ||
const router = useRouter(); | ||
const [hidden, setHidden] = useState(false); | ||
|
||
const pendingSwap = useMemo(() => { | ||
return allSwaps.find(swap => { | ||
if ('secret' in swap) { | ||
// outbound | ||
if (!('btcTxid' in swap)) return false; | ||
if (!('recoveryTxid' in swap) && !('finalizeTxid' in swap)) { | ||
return true; | ||
} | ||
} else { | ||
if (typeof swap.finalizeTxid === 'undefined') return true; | ||
} | ||
}); | ||
}, [allSwaps]); | ||
|
||
const goToSwap = useCallback(() => { | ||
if (typeof pendingSwap === 'undefined') return; | ||
if ('secret' in pendingSwap) { | ||
void router.push({ | ||
pathname: '/inbound/[swapId]', | ||
query: { swapId: pendingSwap.id }, | ||
}); | ||
} else { | ||
void router.push({ | ||
pathname: '/outbound/[txId]', | ||
query: { txId: pendingSwap.txId }, | ||
}); | ||
} | ||
}, [pendingSwap, router]); | ||
|
||
const hide = useCallback(() => { | ||
setHidden(true); | ||
}, [setHidden]); | ||
|
||
if (typeof pendingSwap === 'undefined') return null; | ||
if (hidden) return null; | ||
|
||
return ( | ||
<Box | ||
backgroundColor="$dark-surface-warning" | ||
border="1px solid $dark-border-warning-subdued" | ||
p="30px" | ||
borderRadius="16px" | ||
> | ||
<SpaceBetween> | ||
<Stack isInline alignItems="center"> | ||
<PendingIcon color="var(--colors-dark-warning-action-warning)" /> | ||
<Text variant="Label02" color="$dark-warning-action-warning"> | ||
You may have a{' '} | ||
<Text | ||
variant="Label02" | ||
textDecoration="underline" | ||
color="inherit" | ||
display="inline-block" | ||
cursor="pointer" | ||
onClick={goToSwap} | ||
style={{ | ||
textDecoration: 'underline', | ||
}} | ||
> | ||
swap in progress | ||
</Text> | ||
{'.'} | ||
</Text> | ||
</Stack> | ||
<CloseIcon onClick={hide} cursor="pointer" /> | ||
</SpaceBetween> | ||
</Box> | ||
); | ||
}; | ||
|
||
export const PendingSwapContainer: React.FC = () => { | ||
return ( | ||
<SafeSuspense fallback={<></>}> | ||
<PendingSwap /> | ||
</SafeSuspense> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters