Integrate wallet IFrame for payments #42

Merged
nabarun merged 27 commits from iv-integrate-frame into main 2024-11-13 13:32:28 +00:00
3 changed files with 43 additions and 30 deletions
Showing only changes of commit 88f2cc1117 - Show all commits

View File

@ -1,44 +1,52 @@
import { Select, Option } from '@snowballtools/material-tailwind-react-fork'; import { Select, Option, Spinner } from '@snowballtools/material-tailwind-react-fork';
const AccountsDropdown = ({ const AccountsDropdown = ({
accounts, accounts,
isDataReceived,
onAccountChange, onAccountChange,
}: { }: {
accounts: string[]; accounts: string[];
isDataReceived: boolean;
onAccountChange: (selectedAccount: string) => void; onAccountChange: (selectedAccount: string) => void;
}) => { }) => {
return ( return (
<div className="p-6 bg-slate-100 dark:bg-overlay3 rounded-lg mb-6 shadow-md"> <div className="p-6 bg-slate-100 dark:bg-overlay3 rounded-lg mb-6 shadow-md">
{!accounts.length ? ( {isDataReceived ? (
<div className="text-center"> !accounts.length ? (
<p className="text-gray-700 dark:text-gray-300 mb-4"> <div className="text-center">
No accounts found. Please visit{' '} <p className="text-gray-700 dark:text-gray-300 mb-4">
<a No accounts found. Please visit{' '}
href="https://store.laconic.com" <a
target="_blank" href="https://store.laconic.com"
rel="noopener noreferrer" target="_blank"
className="text-blue-600 underline dark:text-blue-400" rel="noopener noreferrer"
className="text-blue-600 underline dark:text-blue-400"
>
store.laconic.com
</a>{' '}
to create a wallet.
</p>
</div>
) : (
<div>
<Select
label="Select Account"
defaultValue={accounts[0]}
onChange={(value) => value && onAccountChange(value)}
className="dark:bg-overlay2 dark:text-foreground"
aria-label="Wallet Account Selector"
> >
store.laconic.com {accounts.map((account, index) => (
</a>{' '} <Option key={index} value={account}>
to create a wallet. {account}
</p> </Option>
</div> ))}
</Select>
</div>
)
) : ( ) : (
<div> <div className="flex items-center justify-center h-12">
<Select <Spinner className="h-6 w-6" />
label="Select Account"
defaultValue={accounts[0]}
onChange={(value) => value && onAccountChange(value)}
className="dark:bg-overlay2 dark:text-foreground"
aria-label="Wallet Account Selector"
>
{accounts.map((account, index) => (
<Option key={index} value={account}>
{account}
</Option>
))}
</Select>
</div> </div>
)} )}
</div> </div>

View File

@ -48,6 +48,7 @@ const Configure = () => {
const [isPaymentLoading, setIsPaymentLoading] = useState(false); const [isPaymentLoading, setIsPaymentLoading] = useState(false);
const [isPaymentDone, setIsPaymentDone] = useState(false); const [isPaymentDone, setIsPaymentDone] = useState(false);
const [isFrameVisible, setIsFrameVisible] = useState(false); const [isFrameVisible, setIsFrameVisible] = useState(false);
const [isAccountsDataReceived, setIsAccountsDataReceived] = useState(false);
const [searchParams] = useSearchParams(); const [searchParams] = useSearchParams();
const templateId = searchParams.get('templateId'); const templateId = searchParams.get('templateId');
@ -573,9 +574,10 @@ const Configure = () => {
</div> </div>
) : ( ) : (
<> <>
<AccountsDropdown accounts={accounts} onAccountChange={onAccountChange} /> <AccountsDropdown accounts={accounts} onAccountChange={onAccountChange} isDataReceived={isAccountsDataReceived} />
<IFrameModal <IFrameModal
setAccounts={setAccounts} setAccounts={setAccounts}
setIsDataReceived={setIsAccountsDataReceived}
isVisible={isFrameVisible} isVisible={isFrameVisible}
toggleModal={toggleModal} toggleModal={toggleModal}
/> />

View File

@ -6,10 +6,12 @@ import { VITE_LACONICD_CHAIN_ID, VITE_WALLET_IFRAME_URL } from 'utils/constants'
const IFrameModal = ({ const IFrameModal = ({
setAccounts, setAccounts,
setIsDataReceived,
isVisible, isVisible,
toggleModal, toggleModal,
}: { }: {
setAccounts: (accounts: string[]) => void; setAccounts: (accounts: string[]) => void;
setIsDataReceived: (isReceived: boolean) => void;
isVisible: boolean; isVisible: boolean;
toggleModal: () => void; toggleModal: () => void;
}) => { }) => {
@ -18,6 +20,7 @@ const IFrameModal = ({
// TODO: Use env for origin URL // TODO: Use env for origin URL
if (event.origin !== VITE_WALLET_IFRAME_URL) return; if (event.origin !== VITE_WALLET_IFRAME_URL) return;
setIsDataReceived(true);
if (event.data.type === 'WALLET_ACCOUNTS_DATA') { if (event.data.type === 'WALLET_ACCOUNTS_DATA') {
setAccounts(event.data.data); setAccounts(event.data.data);
} else if (event.data.type === 'ERROR') { } else if (event.data.type === 'ERROR') {