Skip to content

Commit

Permalink
Merge branch '116-credential-storage' of github.com:GoodDollar/GoodWe…
Browse files Browse the repository at this point in the history
…b3-Mono into goodid-out-of-gas
  • Loading branch information
L03TJ3 committed Oct 23, 2024
2 parents 3e7cfba + 005e91b commit 0bd880f
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 87 deletions.
2 changes: 1 addition & 1 deletion packages/good-design/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@gooddollar/good-design",
"repository": "https://github.com/GoodDollar/GoodWeb3-mono/packages/good-design",
"version": "0.1.58-beta.844d8ce1",
"version": "0.1.58-beta.d4ddc54b",
"scripts": {
"build": "yarn install && yarn dev:clean && tsc && yarn copy:assets && yalc publish --push",
"build:release": "yarn dev:clean && tsc -p tsconfig.release.json && yarn copy:assets",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ const redtentOffer = [
},
Gender: "Female"
}
// {
// campaign: "RedTent",
// Location: {
// countryCode: "PH" // not confirmed yet
// },
// Gender: "Female"
// }
];

const CheckAvailableOffers: FC<CheckAvailableOffersProps> = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const CardContent = () => (
fontWeight="400"
color="goodGrey.600"
/>
<TransText t={"800G$"} fontFamily="heading" color="gdPrimary" fontSize="l" fontWeight="700" />
<TransText t={"8G$"} fontFamily="heading" color="gdPrimary" fontSize="l" fontWeight="700" />
</VStack>
);

Expand Down
26 changes: 13 additions & 13 deletions packages/good-design/src/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ msgstr ""
"X-Crowdin-File: /goodid-claim-flow/packages/good-design/src/locales/en/messages.po\n"
"X-Crowdin-File-ID: 140\n"

#. js-lingui-explicit-id
#: src/apps/goodid/wizards/RedtentWizard.tsx:136
msgid "You are eligible to claim more GoodDollars!"
msgstr "You are eligible to claim more GoodDollars!"

#. js-lingui-explicit-id
#: src/apps/goodid/components/GoodIdCard.tsx:31
msgid "Age"
Expand Down Expand Up @@ -356,6 +351,11 @@ msgstr "Have verified your country as {country} in your GoodID"
msgid "Submit a video selfie saying: "
msgstr ""

#. js-lingui-explicit-id
#: src/apps/goodid/wizards/RedtentWizard.tsx:136
msgid "You are eligible to claim more GoodDollars!"
msgstr "You are eligible to claim more GoodDollars!"

#. js-lingui-explicit-id
#: src/apps/goodid/wizards/RedtentWizard.tsx:144
msgid "Learn more>>"
Expand Down Expand Up @@ -414,19 +414,19 @@ msgid "GoodCollective. You can claim this additional UBI daily."
msgstr ""

#. js-lingui-explicit-id
#: src/apps/goodid/wizards/SegmentationWizard.tsx:61
#: src/apps/goodid/wizards/SegmentationWizard.tsx:60
msgid ""
"We're checking \n"
" your information"
msgstr ""

#. js-lingui-explicit-id
#: src/apps/goodid/wizards/SegmentationWizard.tsx:73
#: src/apps/goodid/wizards/SegmentationWizard.tsx:71
msgid "yes, i am"
msgstr ""

#. js-lingui-explicit-id
#: src/apps/goodid/wizards/SegmentationWizard.tsx:76
#: src/apps/goodid/wizards/SegmentationWizard.tsx:74
msgid "no, i am not"
msgstr ""

Expand All @@ -436,7 +436,7 @@ msgid "News"
msgstr ""

#. js-lingui-explicit-id
#: src/apps/ubi/components/TransactionStateCard.tsx:83
#: src/apps/ubi/components/TransactionStateCard.tsx:81
msgid "Your Daily Basic Income"
msgstr ""

Expand All @@ -446,22 +446,22 @@ msgid "An unknown error occurred while claiming"
msgstr ""

#. js-lingui-explicit-id
#: src/apps/ubi/screens/PostClaim.tsx:62
#: src/apps/ubi/screens/PostClaim.tsx:63
msgid "Your Next Claim"
msgstr ""

#. js-lingui-explicit-id
#: src/apps/ubi/screens/PostClaim.tsx:108
#: src/apps/ubi/screens/PostClaim.tsx:109
msgid "You've claimed today"
msgstr ""

#. js-lingui-explicit-id
#: src/apps/ubi/screens/PostClaim.tsx:116
#: src/apps/ubi/screens/PostClaim.tsx:117
msgid "CLAIM ON {altChain}"
msgstr ""

#. js-lingui-explicit-id
#: src/apps/ubi/screens/PostClaim.tsx:131
#: src/apps/ubi/screens/PostClaim.tsx:132
msgid "See all news >"
msgstr ""

Expand Down
2 changes: 1 addition & 1 deletion packages/good-design/src/locales/en/messages.ts

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions packages/good-design/src/locales/es-419/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ msgstr ""
"X-Crowdin-File: /goodid-claim-flow/packages/good-design/src/locales/en/messages.po\n"
"X-Crowdin-File-ID: 140\n"

#. js-lingui-explicit-id
#: src/apps/goodid/wizards/RedtentWizard.tsx:136
msgid "You are eligible to claim more GoodDollars!"
msgstr ""

#. js-lingui-explicit-id
#: src/apps/goodid/components/GoodIdCard.tsx:31
msgid "Age"
Expand Down Expand Up @@ -366,6 +361,11 @@ msgstr ""
msgid "Submit a video selfie saying: "
msgstr "Enviar un video selfie diciendo: "

#. js-lingui-explicit-id
#: src/apps/goodid/wizards/RedtentWizard.tsx:136
msgid "You are eligible to claim more GoodDollars!"
msgstr ""

#. js-lingui-explicit-id
#: src/apps/goodid/wizards/RedtentWizard.tsx:144
msgid "Learn more>>"
Expand Down Expand Up @@ -426,7 +426,7 @@ msgid "GoodCollective. You can claim this additional UBI daily."
msgstr "GoodCollective. Puedes reclamar este UBI adicional diariamente."

#. js-lingui-explicit-id
#: src/apps/goodid/wizards/SegmentationWizard.tsx:61
#: src/apps/goodid/wizards/SegmentationWizard.tsx:60
msgid ""
"We're checking \n"
" your information"
Expand All @@ -435,12 +435,12 @@ msgstr ""
" tu información"

#. js-lingui-explicit-id
#: src/apps/goodid/wizards/SegmentationWizard.tsx:73
#: src/apps/goodid/wizards/SegmentationWizard.tsx:71
msgid "yes, i am"
msgstr "sí, soy"

#. js-lingui-explicit-id
#: src/apps/goodid/wizards/SegmentationWizard.tsx:76
#: src/apps/goodid/wizards/SegmentationWizard.tsx:74
msgid "no, i am not"
msgstr "no, no soy"

Expand All @@ -450,7 +450,7 @@ msgid "News"
msgstr "Noticias"

#. js-lingui-explicit-id
#: src/apps/ubi/components/TransactionStateCard.tsx:83
#: src/apps/ubi/components/TransactionStateCard.tsx:81
msgid "Your Daily Basic Income"
msgstr "Su ingreso básico diario"

Expand All @@ -460,22 +460,22 @@ msgid "An unknown error occurred while claiming"
msgstr "Se ha producido un error desconocido al reclamar"

#. js-lingui-explicit-id
#: src/apps/ubi/screens/PostClaim.tsx:62
#: src/apps/ubi/screens/PostClaim.tsx:63
msgid "Your Next Claim"
msgstr "Tu próximo reclamo"

#. js-lingui-explicit-id
#: src/apps/ubi/screens/PostClaim.tsx:108
#: src/apps/ubi/screens/PostClaim.tsx:109
msgid "You've claimed today"
msgstr "Has reclamado hoy"

#. js-lingui-explicit-id
#: src/apps/ubi/screens/PostClaim.tsx:116
#: src/apps/ubi/screens/PostClaim.tsx:117
msgid "CLAIM ON {altChain}"
msgstr "Reclamar en {altChain}"

#. js-lingui-explicit-id
#: src/apps/ubi/screens/PostClaim.tsx:131
#: src/apps/ubi/screens/PostClaim.tsx:132
msgid "See all news >"
msgstr "Ver todas las noticias >"

Expand Down
2 changes: 1 addition & 1 deletion packages/good-design/src/locales/es-419/messages.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/good-design/src/theme/GoodUIi18nProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const GoodUIi18nProvider: FC<PropsWithChildren<{ defaultLanguage?: string
const [language, setLanguage] = useState(defaultLanguage);

useEffect(() => {
locali18n.activate(language);
locali18n.activate(["en", "es-419"].includes(language) ? language : defaultLanguage);
}, [/*used*/ language]);

return (
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-v2/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@gooddollar/web3sdk-v2",
"repository": "https://github.com/GoodDollar/GoodWeb3-mono/packages/sdk-v2",
"version": "0.2.35-beta.844d8ce1",
"version": "0.2.35-beta.d4ddc54b",
"description": "ethers and react hooks based on usedapp sdk for GoodDollar protocol",
"scripts": {
"build": "yarn dev:clean && ctix c && tsc && yarn copy:assets && yalc publish --push",
Expand Down
7 changes: 4 additions & 3 deletions packages/sdk-v2/src/sdk/claim/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ export const useGetMemberUBIPools = () => {
const [poolsDetails, setPoolsDetails] = useState<PoolDetails[] | undefined>(undefined);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const { defaultEnv } = useGetEnvChainId();
//todo: change to take current envs name, awaiting staging/production contracts to be deployed.
const pool = GoodCollectiveContracts["42220"]?.find(envs => envs.name === "development-celo")?.contracts.UBIPool;
const pool = GoodCollectiveContracts["42220"]?.find(envs => envs.name === defaultEnv)?.contracts.UBIPool;

const fetchPools = useCallback(async () => {
setLoading(true);
Expand All @@ -191,7 +192,7 @@ export const useGetMemberUBIPools = () => {
return;
}

const sdk = new GoodCollectiveSDK("42220", library as ethers.providers.Provider, { network: "development-celo" });
const sdk = new GoodCollectiveSDK("42220", library as ethers.providers.Provider, { network: defaultEnv });

const memberUbiPools = await sdk.getMemberUBIPools(account);

Expand All @@ -209,7 +210,7 @@ export const useGetMemberUBIPools = () => {
} finally {
setLoading(false);
}
}, [account, library, chainId]);
}, [account, library, chainId, defaultEnv]);

useEffect(() => {
if (poolsDetails === undefined) {
Expand Down
72 changes: 37 additions & 35 deletions packages/sdk-v2/src/sdk/faucet/react.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Faucet } from "@gooddollar/goodprotocol/types";
import { QueryParams, useCalls, useEtherBalance, useEthers, useNotifications } from "@usedapp/core";
import { QueryParams, useCalls, useEthers, useNotifications } from "@usedapp/core";
import { BigNumber } from "ethers";
import { maxBy, throttle } from "lodash";
import { useEffect, useMemo, useRef } from "react";
import { useEffect, useMemo, useRef, useState } from "react";
import useRefreshOrNever from "../../hooks/useRefreshOrNever";
import { useGasFees } from "../base/hooks/useGasFees";
import { useGetContract, useGetEnvChainId } from "../base/react";
Expand All @@ -11,23 +11,29 @@ import { Envs, SupportedChains } from "../constants";
const throttledFetch = throttle(fetch, 60000, { leading: true });

// default wait roughly 1 minute
export const useFaucet = async (refresh: QueryParams["refresh"] = 12) => {
let refreshOrNever = useRefreshOrNever(refresh);
export const useFaucet = (refresh: QueryParams["refresh"] = 12) => {
const [refreshRate, setRefreshRate] = useState(refresh);
const refreshOrNever = useRefreshOrNever(refreshRate);
const { notifications } = useNotifications();
const latest = useMemo(() => maxBy(notifications, "submittedAt"), [notifications]);
const lastNotification = useRef(latest?.submittedAt || 0);
const { account, chainId } = useEthers();
const { account, chainId, library } = useEthers();

const { ethereum } = window as any;
const isMinipay = ethereum?.isMiniPay;

// if we connected wallet or did a tx then force a refresh
if (latest && latest.type !== "transactionStarted" && latest?.submittedAt > lastNotification.current) {
if (
library &&
account &&
latest &&
latest.type !== "transactionStarted" &&
latest?.submittedAt > lastNotification.current
) {
lastNotification.current = latest?.submittedAt;
refreshOrNever = 1;
setRefreshRate(1);
}

const balance = useEtherBalance(account, { refresh: refreshOrNever }); // refresh roughly once in 1 minute
const { baseEnv } = useGetEnvChainId(); // get the env the user is connected to
const faucet = useGetContract(chainId === SupportedChains.FUSE ? "FuseFaucet" : "Faucet", true, "base") as Faucet;

Expand All @@ -36,11 +42,6 @@ export const useFaucet = async (refresh: QueryParams["refresh"] = 12) => {

const faucetResult = useCalls(
[
{
contract: faucet,
method: "canTop",
args: [account]
},
{
contract: faucet,
method: "getToppingAmount",
Expand All @@ -54,30 +55,31 @@ export const useFaucet = async (refresh: QueryParams["refresh"] = 12) => {
if (!account || isMinipay) {
return;
}
const check = async () => {
const balance = await library?.getBalance(account);
const [toppingAmount] = faucetResult.map(_ => _?.value?.[0] as boolean | BigNumber | undefined) || [];
const threshold = (toppingAmount as BigNumber)?.mul(50)?.div(100) || minBalance;

const [canTop, toppingAmount] = faucetResult.map(_ => _?.value?.[0] as boolean | BigNumber | undefined) || [];
const threshold = (toppingAmount as BigNumber)?.mul(50)?.div(100) || minBalance;
// console.log("useFacuet:", { canTop, toppingAmount, balance, threshold, minBalance, refreshOrNever });

// console.log("useFaucet:", {
// canTop,
// toppingAmount,
// balance: balance?.toString(),
// threshold: threshold?.toString(),
// minBalance: minBalance?.toString(),
// refreshOrNever
// });
if (balance?.lte(threshold)) {
const devEnv = baseEnv === "fuse" ? "development" : baseEnv;
const { backend } = Envs[devEnv];

if (canTop && balance && balance.lte(threshold)) {
const devEnv = baseEnv === "fuse" ? "development" : baseEnv;
const { backend } = Envs[devEnv];
await throttledFetch(backend + "/verify/topWallet", {
method: "POST",
body: JSON.stringify({ chainId, account }),
headers: { "content-type": "application/json" }
})?.catch(e => {
console.error("topping wallet failed:", e.message, e);
});
setRefreshRate(refresh);
}
if (balance?.gt(threshold)) {
setRefreshRate(refresh);
}
};

throttledFetch(backend + "/verify/topWallet", {
method: "POST",
body: JSON.stringify({ chainId, account }),
headers: { "content-type": "application/json" }
})?.catch(e => {
console.error("topping wallet failed:", e.message, e);
});
}
}, [faucetResult, account, balance, baseEnv, chainId, minBalance]);
void check();
}, [faucetResult, account, baseEnv, chainId, minBalance.toString(), library, lastNotification.current]);
};
21 changes: 14 additions & 7 deletions packages/sdk-v2/src/stories/faucet/FaucetHooks.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import React, { useState } from "react";
import React from "react";
import { W3Wrapper } from "../W3Wrapper";
import { ComponentStory, ComponentMeta } from "@storybook/react";
import { useEthers, useSendTransaction } from "@usedapp/core";
import { useFaucet } from "../../sdk/faucet/react";
import { useNetwork } from "@usedapp/core";

export interface PageProps {
address?: string;
firstName?: string;
}

const Web3Component = (params: PageProps) => {
useFaucet();
return <div></div>;
const Web3Component = () => {
const { account } = useEthers();

const send = useSendTransaction({ transactionName: "x" });
const onSend = async () => {
const res = await send.sendTransaction({ to: account, value: 0 });
console.log({ res });
};
void useFaucet();
return <div onClick={onSend}>Send test tx</div>;
};
const Page = (params: PageProps) => (
const Page = () => (
<W3Wrapper withMetaMask>
<Web3Component {...params} />
<Web3Component />
</W3Wrapper>
);

Expand Down
Loading

0 comments on commit 0bd880f

Please sign in to comment.