Skip to content

Commit

Permalink
Merge pull request #228 from TokenScript/feat/wip-multi-auth
Browse files Browse the repository at this point in the history
Feat/wip multi auth
  • Loading branch information
nicktaras authored Jul 18, 2023
2 parents ae4344b + 78617e4 commit 6a4ba87
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
19 changes: 6 additions & 13 deletions hotel-bogota-passive-negotiation-website/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ function App() {
// legacy version output.
setTokenProofData({proof: result.data});
}
alert("Your discount has been applied");
});
}, [selectedPendingTokenInstances]);

Expand All @@ -120,13 +121,8 @@ function App() {
return mockRoomData;
};

// example to return a discount
const getApplicableDiscount = (ticketNum) => {
return mockRoomDiscountData * ticketNum;
};

// When a ticket is present and user applies it, the discount will be shown
const applyDiscount = async (ticket, roomType) => {
const applyDiscountTicket = async (ticket, roomType) => {
// tickets selected, but owner is not yet authenticated.
let updatedTicketSelection = [];
if (selectedPendingTokenInstances?.length) {
Expand All @@ -148,12 +144,8 @@ function App() {
localStorage.setItem("booking-room-type", roomType);
};

useEffect(() => {
localStorage.setItem(
"token-instances",
JSON.stringify(selectedPendingTokenInstances)
);
if (selectedPendingTokenInstances && selectedPendingTokenInstances.length) {
const applyDiscount = async () => {
if (selectedPendingTokenInstances?.length) {
if (selectedPendingTokenInstances.length === 1) {
window.negotiator.authenticate({
issuer: config.collectionID,
Expand All @@ -176,7 +168,7 @@ function App() {
tokenInstance: []
});
}
}, [selectedPendingTokenInstances]);
};

// This is the example at which the hotel would begin a hotel room booking transaction.
const book = async (formData) => {
Expand Down Expand Up @@ -228,6 +220,7 @@ function App() {
key={index}
room={room}
applyDiscount={applyDiscount}
applyDiscountTicket={applyDiscountTicket}
discount={discount}
tokens={tokens}
book={book}
Expand Down
13 changes: 10 additions & 3 deletions hotel-bogota-passive-negotiation-website/src/BookingModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import "./BookingModal.css";

export default function BookingModal({
roomType,
applyDiscountTicket,
applyDiscount,
discount,
price,
Expand Down Expand Up @@ -123,17 +124,18 @@ export default function BookingModal({
<div>
{tokens.length > 0 && (
<p className="smallCopy">
Select ticket(s) to apply discount:
Select ticket(s) and apply discount:
</p>
)}
</div>
<div className="ticketWrapper">
{tokens?.map((token, index) => (
<div key={index}>
<TokenCard
applyDiscount={(token) => {
applyDiscount(token, roomType);
applyDiscountTicket={(token) => {
applyDiscountTicket(token, roomType);
}}
applyDiscount={applyDiscount}
tokenInstance={token}
discount={discount}
selectedPendingTokenInstances={
Expand All @@ -143,6 +145,11 @@ export default function BookingModal({
</div>
))}
</div>
<div style={{display: "flex", justifyContent: "center"}}>
<Button onClick={applyDiscount} color="primary">
Apply Discount
</Button>
</div>
<TextField
id="booking-name"
label="Reference name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const useStyles = makeStyles({

export default function RoomCard({
room,
applyDiscountTicket,
applyDiscount,
discount,
tokens,
Expand All @@ -47,6 +48,7 @@ export default function RoomCard({
<CardActions>
<BookingModal
book={book}
applyDiscountTicket={applyDiscountTicket}
applyDiscount={applyDiscount}
tokens={tokens}
roomType={type}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "./Card.css";

function TokenCard({
tokenInstance,
applyDiscount,
applyDiscountTicket,
selectedPendingTokenInstances
}) {
let tokenSelected = false;
Expand All @@ -20,7 +20,9 @@ function TokenCard({

return (
<div
onClick={(e) => applyDiscount(tokenInstance)}
onClick={(e) => {
applyDiscountTicket(tokenInstance);
}}
className={"tokenCard" + (tokenSelected ? " selected" : "")}
>
<div
Expand Down

0 comments on commit 6a4ba87

Please sign in to comment.