Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

feat: allow fund wallet if balance is 0 usdc or eth #2529

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 40 additions & 9 deletions packages/app/components/creator-token/buy-creator-token.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { useState, useEffect } from "react";
import { Linking } from "react-native";

import { useWallets } from "@privy-io/react-auth";
import { createParam } from "solito";

import { Avatar } from "@showtime-xyz/universal.avatar";
import { BottomSheetModalProvider } from "@showtime-xyz/universal.bottom-sheet";
import { Button } from "@showtime-xyz/universal.button";
import { useIsDarkMode } from "@showtime-xyz/universal.hooks";
import {
Ethereum,
InformationCircle,
LockBadge,
} from "@showtime-xyz/universal.icon";
import { InformationCircle, LockBadge } from "@showtime-xyz/universal.icon";
import { Image } from "@showtime-xyz/universal.image";
import { ModalSheet } from "@showtime-xyz/universal.modal-sheet";
import { Pressable } from "@showtime-xyz/universal.pressable";
Expand Down Expand Up @@ -79,6 +76,8 @@ export const BuyCreatorToken = () => {
const [username] = useParam("username");
const [selectedActionParam] = useParam("selectedAction");
const [tokenAmount, setTokenAmount] = useState(1);
const { wallets } = useWallets();
const isPrivyWalletConnected = wallets?.[0]?.walletClientType === "privy";

const { data: profileData } = useUserProfile({ address: username });
const sellToken = useCreatorTokenSell();
Expand Down Expand Up @@ -158,9 +157,25 @@ export const BuyCreatorToken = () => {
);
} else if (
paymentMethod === "USDC" &&
usdcBalance.data?.balance === 0n &&
!wallet.isMagicWallet
Number(usdcBalance.data?.balance) === 0
) {
if (isPrivyWalletConnected) {
return (
<Button
size="regular"
onPress={() => {
wallets[0].fund({
config: {
currencyCode: "USDC_BASE",
},
});
}}
>
Add USDC to your wallet
</Button>
);
}

return (
<Button
onPress={() =>
Expand All @@ -175,9 +190,25 @@ export const BuyCreatorToken = () => {
);
} else if (
paymentMethod === "ETH" &&
ethBalance.data?.balance === 0n &&
!wallet.isMagicWallet
Number(ethBalance.data?.balance) === 0
) {
if (isPrivyWalletConnected) {
return (
<Button
size="regular"
onPress={() => {
wallets[0].fund({
config: {
currencyCode: "ETH_BASE",
},
});
}}
>
Add ETH to your wallet
</Button>
);
}

return (
<Button
onPress={() => Linking.openURL("https://bridge.base.org/deposit")}
Expand Down
3 changes: 3 additions & 0 deletions packages/app/lib/privy/privy-provider.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
accentColor: "#676FFF",
logo: "https://pbs.twimg.com/profile_images/1720182212468051968/CPBHLyGx_400x400.jpg",
},
fiatOnRamp: {
useSandbox: process.env.NEXT_PUBLIC_STAGE === "development",
},
}}
>
{children}
Expand All @@ -38,7 +41,7 @@
current: null,
} as { current: PrivyInterface | null };

export const PrivyAuth = forwardRef(function PrivyAuth(props: any, ref) {

Check warning on line 44 in packages/app/lib/privy/privy-provider.web.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/app/lib/privy/privy-provider.web.tsx#L44

[unused-imports/no-unused-vars] 'ref' is defined but never used. Allowed unused args must match /^_/u.
const privy = usePrivy();
const { authenticationStatus, setAuthenticationStatus, login, logout } =
useAuth();
Expand Down
Loading