Skip to content

Commit

Permalink
fix: notify if using reloadly sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
EresDev committed Jan 7, 2025
1 parent 22fdde4 commit fc68542
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
5 changes: 5 additions & 0 deletions functions/get-cards-env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Context } from "./utils/types";

export async function onRequest(ctx: Context): Promise<Response> {
return Response.json({ USE_RELOADLY_SANDBOX: ctx.env.USE_RELOADLY_SANDBOX }, { status: 200 });
}
22 changes: 22 additions & 0 deletions static/scripts/rewards/gift-cards/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,25 @@ export async function getUserCountryCode() {
}
return null;
}

export async function isReloadlySandbox() {
const response = await fetch(`${getApiBaseUrl()}/get-cards-env`);
if (response.status == 200) {
const responseJson = await response.json();
return responseJson.USE_RELOADLY_SANDBOX === "true";
}
return false;
}

export async function detectCardsEnv() {
const isCardsSandbox = await isReloadlySandbox();
if (isCardsSandbox) {
const cardEnvElement = document.createElement("div");
cardEnvElement.setAttribute("class", "cards-env");
cardEnvElement.textContent = "You are using Reloadly Sandbox.";
const footer = document.getElementsByTagName("footer");
if (footer.length) {
footer[0].parentNode?.insertBefore(cardEnvElement, footer[0].nextSibling);
}
}
}
5 changes: 4 additions & 1 deletion static/scripts/rewards/gift-cards/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getGiftCardOrderId, isGiftCardAvailable } from "../../../../shared/help
import { GiftCard, OrderTransaction } from "../../../../shared/types";
import { AppState } from "../app-state";
import { getGiftCardHtml } from "./gift-card";
import { getApiBaseUrl, getUserCountryCode } from "./helpers";
import { detectCardsEnv, getApiBaseUrl, getUserCountryCode } from "./helpers";
import { attachMintAction } from "./mint/mint-action";
import { getRedeemCodeHtml } from "./reveal/redeem-code-html";
import { attachRevealAction } from "./reveal/reveal-action";
Expand All @@ -16,7 +16,10 @@ export async function initClaimGiftCard(app: AppState) {
}
giftCardsSection.innerHTML = "Loading...";

void detectCardsEnv();

const countryCode = await getUserCountryCode();

if (!countryCode) {
giftCardsSection.innerHTML = `<p class="card-error">Failed to load suitable virtual cards for you. Refresh or try disabling adblocker.</p>`;
return;
Expand Down
9 changes: 9 additions & 0 deletions static/styles/rewards/gift-cards.css
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@
color: #fff;
}

.cards-env {
background: yellow;
position: fixed;
bottom: 0;
width: 100%;
padding: 4px;
color: #000;
}

.disclaimer {
text-align: center;
padding: 24px 12px;
Expand Down

0 comments on commit fc68542

Please sign in to comment.