diff --git a/cypress/scripts/funding.ts b/cypress/scripts/funding.ts index 0144607d..accc8615 100644 --- a/cypress/scripts/funding.ts +++ b/cypress/scripts/funding.ts @@ -1,5 +1,6 @@ /* eslint-disable sonarjs/no-duplicate-string */ import { SpawnSyncOptionsWithStringEncoding, spawnSync } from "child_process"; +import { chainIdToRewardTokenMap } from "../../shared/constants"; /** * Handles the async funding of the testing environment @@ -16,11 +17,11 @@ class TestFunder { fundingWallet = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8"; beneficiary = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"; permit2 = "0x000000000022D473030F116dDEE9F6B43aC78BA3"; - WXDAI = "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d"; - whale = "0xba12222222228d8ba445958a75a0704d566bf2c8"; + rewardToken = chainIdToRewardTokenMap[100]; + whale = "0xefC0e701A824943b469a694aC564Aa1efF7Ab7dd"; expected = { allowance: "999999999999999111119999999999999999", - balance: "337888400000000000000000", + balance: "10000000000000000000000", }; async execute() { @@ -117,7 +118,7 @@ class TestFunder { private async _fundingAllowanceCheck() { const allowance = await this._exec({ command: "cast", - args: ["call", this.WXDAI, "allowance(address,address)(uint256)", this.fundingWallet, this.permit2, "--rpc-url", this.anvilRPC], + args: ["call", this.rewardToken, "allowance(address,address)(uint256)", this.fundingWallet, this.permit2, "--rpc-url", this.anvilRPC], options: { encoding: "utf8" }, }); @@ -127,7 +128,7 @@ class TestFunder { private async _fundingBalanceCheck() { const balance = await this._exec({ command: "cast", - args: ["call", this.WXDAI, "balanceOf(address)(uint256)", this.fundingWallet, "--rpc-url", this.anvilRPC], + args: ["call", this.rewardToken, "balanceOf(address)(uint256)", this.fundingWallet, "--rpc-url", this.anvilRPC], options: { encoding: "utf8" }, }); @@ -141,7 +142,7 @@ class TestFunder { "send", "--rpc-url", this.anvilRPC, - this.WXDAI, + this.rewardToken, "--unlocked", "--from", address, @@ -173,7 +174,7 @@ class TestFunder { "send", "--rpc-url", this.anvilRPC, - this.WXDAI, + this.rewardToken, "--unlocked", "--from", this.whale, @@ -200,7 +201,7 @@ class TestFunder { "send", "--rpc-url", this.anvilRPC, - this.WXDAI, + this.rewardToken, "--unlocked", "--from", this.fundingWallet, diff --git a/functions/post-order.ts b/functions/post-order.ts index e920851b..dd0086a4 100644 --- a/functions/post-order.ts +++ b/functions/post-order.ts @@ -97,7 +97,7 @@ export async function onRequest(ctx: Context): Promise { return Response.json({ message: "The permit has already claimed a gift card." }, { status: 400 }); } - const order = await orderGiftCard(productId, giftCardValue, orderId, accessToken); + const order = await orderGiftCard(txReceipt.from.toLowerCase(), productId, giftCardValue, orderId, accessToken); if (order.status != "REFUNDED" && order.status != "FAILED") { return Response.json(order, { status: 200 }); @@ -138,7 +138,13 @@ export async function getGiftCardById(productId: number, accessToken: AccessToke return responseJson as GiftCard; } -async function orderGiftCard(productId: number, cardValue: number, identifier: string, accessToken: AccessToken): Promise { +async function orderGiftCard( + userId: string, + productId: number, + cardValue: number, + identifier: string, + accessToken: AccessToken +): Promise { const url = `${getReloadlyApiBaseUrl(accessToken.isSandbox)}/orders`; console.log(`Placing order at url: ${url}`); @@ -148,6 +154,9 @@ async function orderGiftCard(productId: number, cardValue: number, identifier: s unitPrice: cardValue.toFixed(2), customIdentifier: identifier, preOrder: false, + productAdditionalRequirements: { + userId: userId, + }, }); console.log(`Placing order at url: ${url}`); diff --git a/functions/utils/best-card-finder.ts b/functions/utils/best-card-finder.ts index 492fc4b4..bd59ae0a 100644 --- a/functions/utils/best-card-finder.ts +++ b/functions/utils/best-card-finder.ts @@ -4,7 +4,7 @@ import { isGiftCardAvailable } from "../../shared/helpers"; import { GiftCard } from "../../shared/types"; import { commonHeaders, getGiftCards, getReloadlyApiBaseUrl } from "./shared"; import { getGiftCardById } from "../post-order"; -import { fallbackIntlMastercard, fallbackIntlVisa, masterCardIntlSkus, visaIntlSkus } from "./reloadly-lists"; +import { fallbackIntlMastercardFirst, fallbackIntlMastercardSecond, fallbackIntlVisa, masterCardIntlSkus, visaIntlSkus } from "./reloadly-lists"; import { AccessToken, ReloadlyFailureResponse } from "./types"; export async function findBestCard(countryCode: string, amount: BigNumberish, accessToken: AccessToken): Promise { @@ -55,9 +55,14 @@ async function findBestMastercard(masterCards: GiftCard[], countryCode: string, } } - const fallbackMastercard = await getFallbackIntlMastercard(accessToken); - if (fallbackMastercard && isGiftCardAvailable(fallbackMastercard, amount)) { - return fallbackMastercard; + const fallbackMastercardFirst = await getFirstFallbackIntlMastercard(accessToken); + if (fallbackMastercardFirst && isGiftCardAvailable(fallbackMastercardFirst, amount)) { + return fallbackMastercardFirst; + } + + const fallbackMastercardSecond = await getSecondFallbackIntlMastercard(accessToken); + if (fallbackMastercardSecond && isGiftCardAvailable(fallbackMastercardSecond, amount)) { + return fallbackMastercardSecond; } return null; @@ -78,11 +83,20 @@ async function findBestVisaCard(visaCards: GiftCard[], countryCode: string, amou } return null; } -async function getFallbackIntlMastercard(accessToken: AccessToken): Promise { +async function getFirstFallbackIntlMastercard(accessToken: AccessToken): Promise { + try { + return await getGiftCardById(fallbackIntlMastercardFirst.sku, accessToken); + } catch (e) { + console.error(`Failed to load first fallback mastercard: ${JSON.stringify(fallbackIntlMastercardFirst)}`, e); + return null; + } +} + +async function getSecondFallbackIntlMastercard(accessToken: AccessToken): Promise { try { - return await getGiftCardById(fallbackIntlMastercard.sku, accessToken); + return await getGiftCardById(fallbackIntlMastercardSecond.sku, accessToken); } catch (e) { - console.error(`Failed to load international US mastercard: ${JSON.stringify(fallbackIntlMastercard)}`, e); + console.error(`Failed to load second fallback mastercard: ${JSON.stringify(fallbackIntlMastercardSecond)}`, e); return null; } } diff --git a/functions/utils/reloadly-lists.ts b/functions/utils/reloadly-lists.ts index 392255c7..c88b259d 100644 --- a/functions/utils/reloadly-lists.ts +++ b/functions/utils/reloadly-lists.ts @@ -1,7 +1,14 @@ /* eslint-disable sonarjs/no-duplicate-string */ // Keep duplicate country names in different lists -export const fallbackIntlMastercard = { +export const fallbackIntlMastercardFirst = { + country: "United States", + countryCode: "US", + name: "Mastercard Prepaid USD Debit (Virtual only) US", + sku: 18732, +}; + +export const fallbackIntlMastercardSecond = { country: "United States", countryCode: "US", name: "Virtual MasterCard International USD US", @@ -16,6 +23,12 @@ export const fallbackIntlVisa = { }; export const masterCardIntlSkus = [ + { + country: "United States", + countryCode: "US", + name: "Mastercard Prepaid USD Debit (Virtual only) US", + sku: 18732, + }, { country: "United States", countryCode: "US", diff --git a/shared/constants.ts b/shared/constants.ts index d783281a..24bfd677 100644 --- a/shared/constants.ts +++ b/shared/constants.ts @@ -1,6 +1,7 @@ export enum Tokens { DAI = "0x6b175474e89094c44da98b954eedeac495271d0f", WXDAI = "0xe91d153e0b41518a2ce8dd3d7944fa863463a97d", + UUSD = "0xC6ed4f520f6A4e4DC27273509239b7F8A68d2068", } export const permitAllowedChainIds = [1, 5, 10, 100, 31337]; @@ -18,8 +19,15 @@ export const ubiquityDollarChainAddresses: Record = { export const chainIdToRewardTokenMap: Record = { 1: Tokens.DAI, - 100: Tokens.WXDAI, - 31337: Tokens.WXDAI, + 100: Tokens.UUSD, + 31337: Tokens.UUSD, +}; + +export const networkRpcs: Record = { + 1: "https://gateway.tenderly.co/public/mainnet", + 5: "https://eth-goerli.public.blastapi.io", + 100: "https://rpc.gnosischain.com", + 31337: "http://127.0.0.1:8545", }; export const chainIdToNameMap: Record = { diff --git a/shared/helpers.ts b/shared/helpers.ts index 3648f4da..34946fa7 100644 --- a/shared/helpers.ts +++ b/shared/helpers.ts @@ -2,6 +2,7 @@ import { BigNumberish, ethers } from "ethers"; import { GiftCard } from "./types"; import { isRangePriceGiftCardClaimable } from "./pricing"; import { useRpcHandler } from "../static/scripts/rewards/web3/use-rpc-handler"; +import { networkRpcs } from "./constants"; export function getGiftCardOrderId(rewardToAddress: string, signature: string) { const checksumAddress = ethers.utils.getAddress(rewardToAddress); @@ -29,7 +30,12 @@ export function getMintMessageToSign(type: "permit" | "ubiquity-dollar", chainId } export async function getFastestRpcUrl(networkId: number) { - return (await useRpcHandler(networkId)).connection.url; + try { + return (await useRpcHandler(networkId)).connection.url; + } catch (e) { + console.log(`RpcHandler is having issues. Error: ${e} \nUsing backup rpc.`); + return networkRpcs[networkId]; + } } export function isGiftCardAvailable(giftCard: GiftCard, reward: BigNumberish): boolean { diff --git a/static/scripts/rewards/gift-cards/activate/activate-html.ts b/static/scripts/rewards/gift-cards/activate/activate-html.ts index 8798f701..c08f4149 100644 --- a/static/scripts/rewards/gift-cards/activate/activate-html.ts +++ b/static/scripts/rewards/gift-cards/activate/activate-html.ts @@ -8,8 +8,14 @@ export function getGiftCardActivateInfoHtml(giftCard: GiftCard) {
How to use redeem code?
-

${giftCard.redeemInstruction.concise}

- ${giftCard.redeemInstruction.concise != giftCard.redeemInstruction.verbose ? `

${giftCard.redeemInstruction.verbose}

` : ``} +

${giftCard.redeemInstruction.concise.replace("\n", "
")} + ${giftCard.redeemInstruction.concise != giftCard.redeemInstruction.verbose + ? `...Read more` + : ``}

+ +
diff --git a/static/scripts/rewards/gift-cards/gift-card.ts b/static/scripts/rewards/gift-cards/gift-card.ts index 01fb4c04..78fabb88 100644 --- a/static/scripts/rewards/gift-cards/gift-card.ts +++ b/static/scripts/rewards/gift-cards/gift-card.ts @@ -14,9 +14,11 @@ export function getGiftCardHtml(giftCard: GiftCard, rewardAmount: BigNumberish)

${giftCard.productName}

+
${giftCard.denominationType == "FIXED" ? getFixedPricesHtml(giftCard, rewardAmount) : getRangePricesHtml(giftCard, rewardAmount)}
+
SKU: ${giftCard.productId}