-
Notifications
You must be signed in to change notification settings - Fork 47
feat: show list pending offer in Transfers page #441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,6 +122,10 @@ abstract class BaseWalletTransfersFrontendIntegrationTest | |
| offerCard.childElement(className("transfer-offer-sender")) | ||
| ) should matchText(expectedAns(aliceUserParty, aliceAnsName)) | ||
|
|
||
| seleniumText( | ||
| offerCard.childElement(className("transfer-offer-received")) | ||
| ) should matchText(expectedAns(bobUserParty, bobAnsName)) | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this pass? You shouldn't see both the sender and receiver at the same time according to the rendering logic below |
||
| offerCard | ||
| .childElement(className("transfer-offer-amulet-amount")) | ||
| .text should matchText( | ||
|
|
@@ -143,6 +147,7 @@ abstract class BaseWalletTransfersFrontendIntegrationTest | |
| val aliceDamlUser = aliceWalletClient.config.ledgerApiUser | ||
| val aliceUserParty = onboardWalletUser(aliceWalletClient, aliceValidatorBackend) | ||
| val aliceAnsName = perTestCaseName("alice") | ||
| val aliceAnsDisplay = expectedAns(aliceUserParty, aliceAnsName) | ||
|
|
||
| val bobUserParty = onboardWalletUser(bobWalletClient, bobValidatorBackend) | ||
| val bobAnsName = perTestCaseName("bob") | ||
|
|
@@ -190,6 +195,10 @@ abstract class BaseWalletTransfersFrontendIntegrationTest | |
| offerCard.childElement(className("transfer-offer-sender")) | ||
| ) should matchText(bobAnsDisplay) | ||
|
|
||
| seleniumText( | ||
| offerCard.childElement(className("transfer-offer-received")) | ||
| ) should matchText(aliceAnsDisplay) | ||
|
|
||
| offerCard.childElement(className("transfer-offer-expiry")).text should matchText( | ||
| s"Expires $expectedExpiry" | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,8 +34,14 @@ type PartialWalletTransferOffer = { | |
| sender: string; | ||
| expiresAt: string; | ||
| isTokenStandard: boolean; | ||
| receiver: string; | ||
| }; | ||
| export const TransferOffers: React.FC = () => { | ||
|
|
||
| type TransferOffersListProps = { | ||
| mode: 'sent' | 'received'; | ||
| }; | ||
|
|
||
| export const TransferOffers: React.FC<TransferOffersListProps> = ({ mode }) => { | ||
| const [offers, setOffers] = useState<WalletTransferOffer[]>([]); | ||
| const amuletPriceQuery = useAmuletPrice(); | ||
| const primaryPartyId = usePrimaryParty(); | ||
|
|
@@ -46,7 +52,9 @@ export const TransferOffers: React.FC = () => { | |
| amuletPrice: BigNumber | ||
| ): Promise<WalletTransferOffer[]> => { | ||
| return items | ||
| .filter(item => item.sender !== primaryPartyId) | ||
| .filter(item => | ||
| mode === 'received' ? item.sender === primaryPartyId : item.sender !== primaryPartyId | ||
|
||
| ) | ||
| .map(item => { | ||
| return { | ||
| contractId: item.contractId, | ||
|
|
@@ -59,12 +67,13 @@ export const TransferOffers: React.FC = () => { | |
| amuletPrice | ||
| ), | ||
| senderId: item.sender, | ||
| receiverId: item.receiver, | ||
| expiry: item.expiresAt, | ||
| isTokenStandard: item.isTokenStandard, | ||
| }; | ||
| }); | ||
| }, | ||
| [primaryPartyId] | ||
| [primaryPartyId, mode] | ||
| ); | ||
|
|
||
| const transferOfferContractsQuery = useTransferOffers(amuletPriceQuery.data); | ||
|
|
@@ -82,6 +91,7 @@ export const TransferOffers: React.FC = () => { | |
| contractId: offer.contractId, | ||
| amount: offer.payload.amount.amount, | ||
| sender: offer.payload.sender, | ||
| receiver: offer.payload.receiver, | ||
| expiresAt: offer.payload.expiresAt, | ||
| }; | ||
| return item; | ||
|
|
@@ -93,6 +103,7 @@ export const TransferOffers: React.FC = () => { | |
| contractId: transfer.contractId, | ||
| amount: transfer.payload.transfer.amount, | ||
| sender: transfer.payload.transfer.sender, | ||
| receiver: transfer.payload.transfer.receiver, | ||
| expiresAt: transfer.payload.transfer.executeBefore, | ||
| }; | ||
| return item; | ||
|
|
@@ -110,11 +121,12 @@ export const TransferOffers: React.FC = () => { | |
| amuletPriceQuery.isError || | ||
| transferOfferContractsQuery.isError || | ||
| tokenStandardTransfersQuery.isError; | ||
| const heading = mode === 'received' ? 'Pending Offers ' : 'Action Needed '; | ||
|
||
|
|
||
| return ( | ||
| <Stack spacing={4} direction="column" justifyContent="center" id="transfer-offers"> | ||
| <Typography mt={6} variant="h4"> | ||
| Action Needed{' '} | ||
| {heading} | ||
| <Chip label={offers.length} color="success" className="transfer-offers-count" /> | ||
| </Typography> | ||
| {isLoading ? ( | ||
|
|
@@ -127,7 +139,7 @@ export const TransferOffers: React.FC = () => { | |
| </Box> | ||
| ) : ( | ||
| offers.map((offer, index) => ( | ||
| <TransferOfferDisplay key={'offer-' + index} transferOffer={offer} /> | ||
| <TransferOfferDisplay key={'offer-' + index} transferOffer={offer} mode={mode} /> | ||
| )) | ||
| )} | ||
| </Stack> | ||
|
|
@@ -136,11 +148,14 @@ export const TransferOffers: React.FC = () => { | |
|
|
||
| interface TransferOfferProps { | ||
| transferOffer: WalletTransferOffer; | ||
| mode: 'sent' | 'received'; | ||
| } | ||
|
|
||
| export const TransferOfferDisplay: React.FC<TransferOfferProps> = props => { | ||
| const config = useWalletConfig(); | ||
| const offer = props.transferOffer; | ||
| const mode = props.mode; | ||
|
|
||
| const { | ||
| acceptTransferOffer, | ||
| rejectTransferOffer, | ||
|
|
@@ -163,11 +178,19 @@ export const TransferOfferDisplay: React.FC<TransferOfferProps> = props => { | |
| <ArrowCircleLeftOutlined fontSize="large" /> | ||
| <Stack direction="row" alignItems="center"> | ||
| <Stack direction="column"> | ||
| <BftAnsEntry | ||
| partyId={offer.senderId} | ||
| variant="h5" | ||
| className={'transfer-offer-sender'} | ||
| /> | ||
| {mode === 'sent' ? ( | ||
| <BftAnsEntry | ||
| partyId={offer.senderId} | ||
| variant="h5" | ||
| className={'transfer-offer-sender'} | ||
| /> | ||
| ) : ( | ||
| <BftAnsEntry | ||
| partyId={offer.receiverId} | ||
| variant="h5" | ||
| className={'transfer-offer-received'} | ||
| /> | ||
| )} | ||
| </Stack> | ||
| </Stack> | ||
| <Stack direction="column" alignItems="flex-end"> | ||
|
|
@@ -186,23 +209,31 @@ export const TransferOfferDisplay: React.FC<TransferOfferProps> = props => { | |
| </Typography> | ||
| </Stack> | ||
| <Stack direction="row" alignItems="center" spacing={2}> | ||
| <Button | ||
| variant="pill" | ||
| size="small" | ||
| onClick={() => accept(offer.contractId)} | ||
| className="transfer-offer-accept" | ||
| > | ||
| Accept | ||
| </Button> | ||
| <Button | ||
| variant="pill" | ||
| color="warning" | ||
| size="small" | ||
| onClick={() => reject(offer.contractId)} | ||
| className="transfer-offer-reject" | ||
| > | ||
| Reject | ||
| </Button> | ||
| {mode === 'sent' ? ( | ||
| <> | ||
| <Button | ||
| variant="pill" | ||
| size="small" | ||
| onClick={() => accept(offer.contractId)} | ||
| className="transfer-offer-accept" | ||
| > | ||
| Accept | ||
| </Button> | ||
| <Button | ||
| variant="pill" | ||
| color="warning" | ||
| size="small" | ||
| onClick={() => reject(offer.contractId)} | ||
| className="transfer-offer-reject" | ||
| > | ||
| Reject | ||
| </Button> | ||
| </> | ||
| ) : ( | ||
| <Typography variant="pill" className="pending-offer"> | ||
| Pending acceptance | ||
|
||
| </Typography> | ||
| )} | ||
| </Stack> | ||
| <Typography variant="caption" className="transfer-offer-expiry"> | ||
| Expires <DateDisplay datetime={offer.expiry} /> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
transfer-offer-receiver