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 9e9e8f34aa - Show all commits

View File

@ -164,6 +164,7 @@ const Configure = () => {
`${amount.toString()}alnt`, `${amount.toString()}alnt`,
senderAddress, senderAddress,
); );
return isValid; return isValid;
}; };
@ -174,41 +175,46 @@ const Configure = () => {
} }
const senderAddress = selectedAccount; const senderAddress = selectedAccount;
const deployerLrn = createFormData.lrn;
const deployer = deployers.find(deployer => deployer.deployerLrn === deployerLrn);
let amount: string; let amount: string;
if(createFormData.option === 'LRN') { let txHash: string;
const deployerLrn = createFormData.lrn; if (createFormData.option === 'LRN' && !deployer?.minimumPayment) {
const deployer = deployers.find(deployer => deployer.deployerLrn === deployerLrn); toast({
if (!deployer?.minimumPayment) { id: 'no-payment-required',
toast({ title: 'No payment required. Deploying app...',
id: 'no-payment-required', variant: 'info',
title: 'No payment', onDismiss: dismiss,
variant: 'info', });
onDismiss: dismiss,
});
amount = '' txHash = '';
} else {
amount = deployer!.minimumPayment
}
} else { } else {
amount = (createFormData.numProviders * createFormData.maxPrice).toString(); if (createFormData.option === 'LRN') {
} amount = deployer?.minimumPayment!;
} else {
amount = (createFormData.numProviders * createFormData.maxPrice).toString();
}
const txHash = await cosmosSendTokensHandler( const amountToBePaid = (amount.replace(/\D/g, '')).toString();
selectedAccount,
amount,
);
if(!txHash) { const txHashResponse = await cosmosSendTokensHandler(
console.error('Tx not successful'); selectedAccount,
return; amountToBePaid,
} );
const isTxHashValid = verifyTx(senderAddress, txHash, amount.toString()); if (!txHashResponse) {
if (!isTxHashValid) { console.error('Tx not successful');
console.error("Invalid Tx hash", txHash) return;
return }
txHash = txHashResponse;
const isTxHashValid = verifyTx(senderAddress, txHash, amount.toString());
if (!isTxHashValid) {
console.error("Invalid Tx hash", txHash)
return;
}
} }
const environmentVariables = createFormData.variables.map( const environmentVariables = createFormData.variables.map(
@ -227,7 +233,7 @@ const Configure = () => {
createFormData, createFormData,
environmentVariables, environmentVariables,
senderAddress, senderAddress,
txHash!, txHash,
); );
await client.getEnvironmentVariables(projectId); await client.getEnvironmentVariables(projectId);