Implement payments for app deployments #17
@ -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} />
|
||||||
<div>
|
{accounts && accounts?.length > 0 && (
|
||||||
<Button
|
<div>
|
||||||
{...buttonSize}
|
<Button
|
||||||
type="submit"
|
{...buttonSize}
|
||||||
disabled={isLoading}
|
type="submit"
|
||||||
rightIcon={
|
disabled={isLoading || isPaymentLoading}
|
||||||
isLoading ? (
|
rightIcon={
|
||||||
<LoadingIcon className="animate-spin" />
|
isLoading || isPaymentLoading ? (
|
||||||
) : (
|
<LoadingIcon className="animate-spin" />
|
||||||
<ArrowRightCircleFilledIcon />
|
) : (
|
||||||
)
|
<ArrowRightCircleFilledIcon />
|
||||||
}
|
)
|
||||||
>
|
}
|
||||||
{isLoading ? 'Deploying repo' : 'Deploy repo'}
|
>
|
||||||
</Button>
|
{!isPaymentDone
|
||||||
</div>
|
? isPaymentLoading
|
||||||
|
? 'Paying'
|
||||||
|
: 'Pay and Deploy'
|
||||||
|
: isLoading
|
||||||
|
? 'Deploying repo'
|
||||||
|
: 'Deploy'}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</form>
|
</form>
|
||||||
</FormProvider>
|
</FormProvider>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user