Implement payments for app deployments #17

Merged
nabarun merged 27 commits from iv-integrate-payments into main 2024-10-28 09:46:19 +00:00
Showing only changes of commit c52514e833 - Show all commits

View File

@ -36,11 +36,13 @@ type ConfigureFormValues = ConfigureDeploymentFormValues &
EnvironmentVariablesFormValues; EnvironmentVariablesFormValues;
const Configure = () => { const Configure = () => {
const { signClient, session } = useWalletConnectClient(); const { signClient, session, accounts } = useWalletConnectClient();
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [deployers, setDeployers] = useState<Deployer[]>([]); const [deployers, setDeployers] = useState<Deployer[]>([]);
const [selectedAccount, setSelectedAccount] = useState<string>(); const [selectedAccount, setSelectedAccount] = useState<string>();
const [isPaymentLoading, setIsPaymentLoading] = useState(false);
const [isPaymentDone, setIsPaymentDone] = useState(false);
const [searchParams] = useSearchParams(); const [searchParams] = useSearchParams();
const templateId = searchParams.get('templateId'); const templateId = searchParams.get('templateId');
@ -271,6 +273,16 @@ const Configure = () => {
const snowballAddress = await client.getAddress(); const snowballAddress = await client.getAddress();
try { try {
setIsPaymentDone(false);
setIsPaymentLoading(true);
toast({
id: 'sending-payment-request',
title: 'Check your wallet and approve payment request',
variant: 'loading',
onDismiss: dismiss,
});
const result: { signature: string } = await signClient.request({ const result: { signature: string } = await signClient.request({
topic: session.topic, topic: session.topic,
chainId: `cosmos:${chainId}`, chainId: `cosmos:${chainId}`,
@ -290,12 +302,28 @@ const Configure = () => {
throw new Error('Error completing transaction'); throw new Error('Error completing transaction');
} }
toast({
id: 'payment-successful',
title: 'Payment successful',
variant: 'success',
onDismiss: dismiss,
});
return result.signature; return result.signature;
} catch (error: any) { } catch (error: any) {
throw error; console.error('Error sending tokens', error);
toast({
id: 'error-sending-tokens',
title: 'Error sending tokens',
variant: 'error',
onDismiss: dismiss,
});
} finally {
setIsPaymentLoading(false);
setIsPaymentDone(true);
} }
}, },
[session, signClient], [session, signClient, toast],
); );
useEffect(() => { useEffect(() => {
@ -440,22 +468,30 @@ const Configure = () => {
Connect to your wallet Connect to your wallet
</Heading> </Heading>
<ConnectWallet onAccountChange={onAccountChange} /> <ConnectWallet onAccountChange={onAccountChange} />
{accounts && accounts?.length > 0 && (
<div> <div>
<Button <Button
{...buttonSize} {...buttonSize}
type="submit" type="submit"
disabled={isLoading} disabled={isLoading || isPaymentLoading}
rightIcon={ rightIcon={
isLoading ? ( isLoading || isPaymentLoading ? (
<LoadingIcon className="animate-spin" /> <LoadingIcon className="animate-spin" />
) : ( ) : (
<ArrowRightCircleFilledIcon /> <ArrowRightCircleFilledIcon />
) )
} }
> >
{isLoading ? 'Deploying repo' : 'Deploy repo'} {!isPaymentDone
? isPaymentLoading
? 'Paying'
: 'Pay and Deploy'
: isLoading
? 'Deploying repo'
: 'Deploy'}
</Button> </Button>
</div> </div>
)}
</form> </form>
</FormProvider> </FormProvider>
</div> </div>