forked from cerc-io/snowballtools-base
Compare commits
47
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59329c18f6 | ||
|
|
8553c30b0d | ||
|
|
b409d43e51 | ||
|
|
b50efe315b | ||
|
|
ced815802e | ||
|
|
22bb409617 | ||
|
|
8322f877c0 | ||
|
|
fd38127cb5 | ||
|
|
b6084008b8 | ||
|
|
d1e6171874 | ||
|
|
ce56a4dc29 | ||
|
|
c685b7d5b1 | ||
|
|
32001b3d5a | ||
|
|
6f32ea4da8 | ||
|
|
a16b44b43a | ||
|
|
a17386eb68 | ||
|
|
f318a95641 | ||
|
|
e9f746cd8b | ||
|
|
e59c14440c | ||
|
|
22f8a8c943 | ||
|
|
df5062c75f | ||
|
|
22e814840e | ||
|
|
9d27dd568a | ||
|
|
fc62392c83 | ||
|
|
2ee65b8fd8 | ||
|
|
d0302d0153 | ||
|
|
90e9260eb6 | ||
|
|
6dcee29487 | ||
|
|
5be10b6b0a | ||
|
|
6e8af82dc2 | ||
|
|
1a5ab4d47e | ||
|
|
6df685831f | ||
|
|
13892015a5 | ||
|
|
55500b5914 | ||
|
|
a7190ed804 | ||
|
|
6a79ee5c47 | ||
|
|
f2ba931961 | ||
|
|
85b4265fbe | ||
|
|
63223a4807 | ||
|
|
9784eb4f4a | ||
|
|
624f36155a | ||
|
|
82c4b71694 | ||
|
|
5d9c965f54 | ||
|
|
56eccb48b3 | ||
|
|
b5762432e6 | ||
|
|
4ae4670dca | ||
|
|
c202554002 |
No files matched your search
@@ -15,6 +15,7 @@ VITE_GITHUB_CLIENT_ID = 'LACONIC_HOSTED_CONFIG_github_clientid'
|
||||
VITE_GITHUB_PWA_TEMPLATE_REPO = 'LACONIC_HOSTED_CONFIG_github_pwa_templaterepo'
|
||||
VITE_GITHUB_IMAGE_UPLOAD_PWA_TEMPLATE_REPO = 'LACONIC_HOSTED_CONFIG_github_image_upload_templaterepo'
|
||||
VITE_GITHUB_NEXT_APP_TEMPLATE_REPO = 'LACONIC_HOSTED_CONFIG_github_next_app_templaterepo'
|
||||
VITE_WALLET_CONNECT_ID = 'LACONIC_HOSTED_CONFIG_wallet_connect_id'
|
||||
VITE_LACONICD_CHAIN_ID = 'LACONIC_HOSTED_CONFIG_laconicd_chain_id'
|
||||
VITE_WALLET_IFRAME_URL = 'LACONIC_HOSTED_CONFIG_wallet_iframe_url'
|
||||
VITE_LIT_RELAY_API_KEY = 'LACONIC_HOSTED_CONFIG_lit_relay_api_key'
|
||||
|
||||
@@ -158,9 +158,10 @@ export class Database {
|
||||
.leftJoinAndSelect(
|
||||
'project.deployments',
|
||||
'deployments',
|
||||
'deployments.isCurrent = true AND deployments.isCanonical = true'
|
||||
'deployments.isCurrent = true AND deployments.isDNS = true'
|
||||
)
|
||||
.leftJoinAndSelect('deployments.createdBy', 'user')
|
||||
.leftJoinAndSelect('deployments.domain', 'domain')
|
||||
.leftJoinAndSelect('deployments.deployer', 'deployer')
|
||||
.leftJoinAndSelect('project.owner', 'owner')
|
||||
.leftJoinAndSelect('project.deployers', 'deployers')
|
||||
@@ -202,8 +203,9 @@ export class Database {
|
||||
.leftJoinAndSelect(
|
||||
'project.deployments',
|
||||
'deployments',
|
||||
'deployments.isCurrent = true AND deployments.isCanonical = true'
|
||||
'deployments.isCurrent = true AND deployments.isDNS = true'
|
||||
)
|
||||
.leftJoinAndSelect('deployments.domain', 'domain')
|
||||
.leftJoin('project.projectMembers', 'projectMembers')
|
||||
.leftJoin('project.organization', 'organization')
|
||||
.where(
|
||||
@@ -234,6 +236,7 @@ export class Database {
|
||||
return this.getDeployments({
|
||||
relations: {
|
||||
project: true,
|
||||
domain: true,
|
||||
createdBy: true,
|
||||
deployer: true,
|
||||
},
|
||||
@@ -248,10 +251,11 @@ export class Database {
|
||||
});
|
||||
}
|
||||
|
||||
async getNonCanonicalDeploymentsByProjectId(projectId: string): Promise<Deployment[]> {
|
||||
async getCommitDeploymentsByProjectId(projectId: string): Promise<Deployment[]> {
|
||||
return this.getDeployments({
|
||||
relations: {
|
||||
project: true,
|
||||
domain: true,
|
||||
createdBy: true,
|
||||
deployer: true,
|
||||
},
|
||||
@@ -259,7 +263,7 @@ export class Database {
|
||||
project: {
|
||||
id: projectId
|
||||
},
|
||||
isCanonical: false
|
||||
isDNS: false
|
||||
},
|
||||
order: {
|
||||
createdAt: 'DESC'
|
||||
|
||||
@@ -39,7 +39,6 @@ export interface ApplicationDeploymentRequest {
|
||||
config: string;
|
||||
meta: string;
|
||||
payment?: string;
|
||||
dns?: string;
|
||||
}
|
||||
|
||||
export interface ApplicationDeploymentRemovalRequest {
|
||||
@@ -78,6 +77,13 @@ export class Deployment {
|
||||
@JoinColumn({ name: 'projectId' })
|
||||
project!: Project;
|
||||
|
||||
@Column({ nullable: true })
|
||||
domainId!: string | null;
|
||||
|
||||
@OneToOne(() => Domain)
|
||||
@JoinColumn({ name: 'domainId' })
|
||||
domain!: Domain | null;
|
||||
|
||||
@Column('varchar')
|
||||
branch!: string;
|
||||
|
||||
@@ -135,8 +141,9 @@ export class Deployment {
|
||||
@Column('boolean', { default: false })
|
||||
isCurrent!: boolean;
|
||||
|
||||
// TODO: Rename field
|
||||
@Column('boolean', { default: false })
|
||||
isCanonical!: boolean;
|
||||
isDNS!: boolean;
|
||||
|
||||
@Column({
|
||||
enum: DeploymentStatus
|
||||
|
||||
@@ -414,8 +414,12 @@ export class Registry {
|
||||
* Fetch record by Id
|
||||
*/
|
||||
async getRecordById(id: string): Promise<RegistryRecord | null> {
|
||||
const [record] = await this.registry.getRecordsByIds([id]);
|
||||
return record ?? null;
|
||||
const record = await this.registry.getRecordsByIds([id]);
|
||||
if (record.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return record[0];
|
||||
}
|
||||
|
||||
async createApplicationDeploymentRemovalRequest(data: {
|
||||
|
||||
@@ -38,7 +38,7 @@ export const createResolvers = async (service: Service): Promise<any> => {
|
||||
},
|
||||
|
||||
deployments: async (_: any, { projectId }: { projectId: string }) => {
|
||||
return service.getNonCanonicalDeploymentsByProjectId(projectId);
|
||||
return service.getCommitDeploymentsByProjectId(projectId);
|
||||
},
|
||||
|
||||
environmentVariables: async (
|
||||
|
||||
@@ -94,4 +94,13 @@ router.get('/session', (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/logout', (req, res) => {
|
||||
req.session.destroy((err) => {
|
||||
if (err) {
|
||||
return res.send({ success: false });
|
||||
}
|
||||
res.send({ success: true });
|
||||
});
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -100,6 +100,7 @@ type ProjectMember {
|
||||
|
||||
type Deployment {
|
||||
id: String!
|
||||
domain: Domain
|
||||
branch: String!
|
||||
commitHash: String!
|
||||
commitMessage: String!
|
||||
|
||||
+100
-104
@@ -228,12 +228,12 @@ export class Service {
|
||||
deployment.isCurrent = deployment.environment === Environment.Production;
|
||||
deployment.dnsRecordData = dnsRecordData;
|
||||
|
||||
if (deployment.isCanonical) {
|
||||
const previousCanonicalDeployment = await this.db.getDeployment({
|
||||
if (deployment.isDNS) {
|
||||
const oldDNSDeployment = await this.db.getDeployment({
|
||||
where: {
|
||||
projectId: deployment.project.id,
|
||||
deployer: deployment.deployer,
|
||||
isCanonical: true,
|
||||
isDNS: true,
|
||||
isCurrent: true,
|
||||
},
|
||||
relations: {
|
||||
@@ -242,18 +242,26 @@ export class Service {
|
||||
}
|
||||
});
|
||||
|
||||
if (previousCanonicalDeployment) {
|
||||
// Send removal request for the previous canonical deployment and delete DB entry
|
||||
if (previousCanonicalDeployment.url !== deployment.url) {
|
||||
if (oldDNSDeployment) {
|
||||
// Send removal request for the previous DNS deployment and delete DB entry
|
||||
if (oldDNSDeployment.url !== deployment.url) {
|
||||
await this.laconicRegistry.createApplicationDeploymentRemovalRequest({
|
||||
deploymentId: previousCanonicalDeployment.applicationDeploymentRecordId!,
|
||||
deployerLrn: previousCanonicalDeployment.deployer.deployerLrn,
|
||||
auctionId: previousCanonicalDeployment.project.auctionId,
|
||||
payment: previousCanonicalDeployment.project.txHash
|
||||
deploymentId: oldDNSDeployment.applicationDeploymentRecordId!,
|
||||
deployerLrn: oldDNSDeployment.deployer.deployerLrn,
|
||||
auctionId: oldDNSDeployment.project.auctionId,
|
||||
payment: oldDNSDeployment.project.txHash
|
||||
});
|
||||
}
|
||||
|
||||
await this.db.deleteDeploymentById(previousCanonicalDeployment.id);
|
||||
await this.db.deleteDeploymentById(oldDNSDeployment.id);
|
||||
}
|
||||
|
||||
// Update domain after the previous DNS deployment is deleted due to unique key constraint for domain
|
||||
// Set the domain for the new current DNS deployment to the custom domain that was added for that project
|
||||
const customDomain = await this.db.getOldestDomainByProjectId(deployment.project.id);
|
||||
|
||||
if (customDomain) {
|
||||
deployment.domain = customDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,7 +301,7 @@ export class Service {
|
||||
projectDeployment.deployer.deployerLrn ===
|
||||
deployment.deployer.deployerLrn &&
|
||||
projectDeployment.id !== deployment.id &&
|
||||
projectDeployment.isCanonical == deployment.isCanonical,
|
||||
projectDeployment.isDNS == deployment.isDNS,
|
||||
);
|
||||
for (const oldDeployment of oldDeployments) {
|
||||
await this.db.updateDeployment(
|
||||
@@ -485,14 +493,14 @@ export class Service {
|
||||
return dbProjects;
|
||||
}
|
||||
|
||||
async getNonCanonicalDeploymentsByProjectId(projectId: string): Promise<Deployment[]> {
|
||||
const nonCanonicalDeployments = await this.db.getNonCanonicalDeploymentsByProjectId(projectId);
|
||||
return nonCanonicalDeployments;
|
||||
async getCommitDeploymentsByProjectId(projectId: string): Promise<Deployment[]> {
|
||||
const commitDeployments = await this.db.getCommitDeploymentsByProjectId(projectId);
|
||||
return commitDeployments;
|
||||
}
|
||||
|
||||
async getLatestDNSRecordByProjectId(projectId: string): Promise<DNSRecordAttributes | null> {
|
||||
const dnsRecord = await this.db.getLatestDNSRecordByProjectId(projectId);
|
||||
return dnsRecord;
|
||||
const dnsDeployments = await this.db.getLatestDNSRecordByProjectId(projectId);
|
||||
return dnsDeployments;
|
||||
}
|
||||
|
||||
async getEnvironmentVariablesByProjectId(
|
||||
@@ -634,7 +642,6 @@ export class Service {
|
||||
where: { id: deploymentId },
|
||||
relations: {
|
||||
project: true,
|
||||
deployer: true,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -642,12 +649,18 @@ export class Service {
|
||||
throw new Error('Deployment does not exist');
|
||||
}
|
||||
|
||||
const prodBranchDomains = await this.db.getDomainsByProjectId(
|
||||
oldDeployment.project.id,
|
||||
{ branch: oldDeployment.project.prodBranch },
|
||||
);
|
||||
|
||||
const octokit = await this.getOctokit(user.id);
|
||||
|
||||
const newDeployment = await this.createDeployment(user.id, octokit, {
|
||||
project: oldDeployment.project,
|
||||
branch: oldDeployment.branch,
|
||||
environment: Environment.Production,
|
||||
domain: prodBranchDomains[0],
|
||||
commitHash: oldDeployment.commitHash,
|
||||
commitMessage: oldDeployment.commitMessage,
|
||||
deployer: oldDeployment.deployer
|
||||
@@ -676,6 +689,19 @@ export class Service {
|
||||
commitHash: data.commitHash!,
|
||||
});
|
||||
|
||||
// Update previous deployment with prod branch domain
|
||||
// TODO: Fix unique constraint error for domain
|
||||
if (data.domain) {
|
||||
await this.db.updateDeployment(
|
||||
{
|
||||
domainId: data.domain.id,
|
||||
},
|
||||
{
|
||||
domain: null,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
let deployer;
|
||||
if (deployerLrn) {
|
||||
deployer = await this.db.getDeployerByLRN(deployerLrn);
|
||||
@@ -684,26 +710,26 @@ export class Service {
|
||||
}
|
||||
|
||||
const deployment = await this.createDeploymentFromData(userId, data, deployer!.deployerLrn!, applicationRecordId, applicationRecordData, false);
|
||||
const dnsDeployment = await this.createDeploymentFromData(userId, data, deployer!.deployerLrn!, applicationRecordId, applicationRecordData, true);
|
||||
|
||||
const address = await this.getAddress();
|
||||
const { repo, repoUrl } = await getRepoDetails(octokit, data.project.repository, data.commitHash);
|
||||
const environmentVariablesObj = await this.getEnvVariables(data.project!.id!);
|
||||
|
||||
// If a custom domain is present then use that as the DNS in the deployment request
|
||||
const customDomain = await this.db.getOldestDomainByProjectId(data.project!.id!);
|
||||
|
||||
// To set project DNS
|
||||
if (data.environment === Environment.Production) {
|
||||
const canonicalDeployment = await this.createDeploymentFromData(userId, data, deployer!.deployerLrn!, applicationRecordId, applicationRecordData, true);
|
||||
// If a custom domain is present then use that as the DNS in the deployment request
|
||||
const customDomain = await this.db.getOldestDomainByProjectId(data.project!.id!);
|
||||
|
||||
// On deleting deployment later, project canonical deployment is also deleted
|
||||
// So publish project canonical deployment first so that ApplicationDeploymentRecord for the same is available when deleting deployment later
|
||||
// On deleting deployment later, project DNS deployment is also deleted
|
||||
// So publish project DNS deployment first so that ApplicationDeploymentRecord for the same is available when deleting deployment later
|
||||
const { applicationDeploymentRequestData, applicationDeploymentRequestId } =
|
||||
await this.laconicRegistry.createApplicationDeploymentRequest({
|
||||
deployment: canonicalDeployment,
|
||||
deployment: dnsDeployment,
|
||||
appName: repo,
|
||||
repository: repoUrl,
|
||||
environmentVariables: environmentVariablesObj,
|
||||
dns: customDomain?.name ?? `${canonicalDeployment.project.name}`,
|
||||
dns: customDomain?.name ?? `${dnsDeployment.project.name}`,
|
||||
lrn: deployer!.deployerLrn!,
|
||||
apiUrl: deployer!.deployerApiUrl!,
|
||||
payment: data.project.txHash,
|
||||
@@ -712,7 +738,7 @@ export class Service {
|
||||
publicKey: deployer!.publicKey!
|
||||
});
|
||||
|
||||
await this.db.updateDeploymentById(canonicalDeployment.id, {
|
||||
await this.db.updateDeploymentById(dnsDeployment.id, {
|
||||
applicationDeploymentRequestId,
|
||||
applicationDeploymentRequestData,
|
||||
});
|
||||
@@ -782,24 +808,21 @@ export class Service {
|
||||
};
|
||||
|
||||
const deployment = await this.createDeploymentFromData(project.ownerId!, deploymentData, deployerLrn, applicationRecordId, applicationRecordData, false);
|
||||
const dnsDeployment = await this.createDeploymentFromData(project.ownerId!, deploymentData, deployerLrn, applicationRecordId, applicationRecordData, true);
|
||||
const address = await this.getAddress();
|
||||
|
||||
const environmentVariablesObj = await this.getEnvVariables(project!.id!);
|
||||
// To set project DNS
|
||||
if (deploymentData.environment === Environment.Production) {
|
||||
const canonicalDeployment = await this.createDeploymentFromData(project.ownerId!, deploymentData, deployerLrn, applicationRecordId, applicationRecordData, true);
|
||||
// If a custom domain is present then use that as the DNS in the deployment request
|
||||
const customDomain = await this.db.getOldestDomainByProjectId(project!.id!);
|
||||
|
||||
// On deleting deployment later, project canonical deployment is also deleted
|
||||
// So publish project canonical deployment first so that ApplicationDeploymentRecord for the same is available when deleting deployment later
|
||||
// On deleting deployment later, project DNS deployment is also deleted
|
||||
// So publish project DNS deployment first so that ApplicationDeploymentRecord for the same is available when deleting deployment later
|
||||
const { applicationDeploymentRequestId, applicationDeploymentRequestData } =
|
||||
await this.laconicRegistry.createApplicationDeploymentRequest({
|
||||
deployment: canonicalDeployment,
|
||||
deployment: dnsDeployment,
|
||||
appName: repo,
|
||||
repository: repoUrl,
|
||||
environmentVariables: environmentVariablesObj,
|
||||
dns: customDomain?.name ?? `${canonicalDeployment.project.name}`,
|
||||
dns: `${dnsDeployment.project.name}`,
|
||||
auctionId: project.auctionId!,
|
||||
lrn: deployerLrn,
|
||||
apiUrl: deployer!.deployerApiUrl!,
|
||||
@@ -807,7 +830,7 @@ export class Service {
|
||||
publicKey: deployer!.publicKey!
|
||||
});
|
||||
|
||||
await this.db.updateDeploymentById(canonicalDeployment.id, {
|
||||
await this.db.updateDeploymentById(dnsDeployment.id, {
|
||||
applicationDeploymentRequestId,
|
||||
applicationDeploymentRequestData,
|
||||
});
|
||||
@@ -842,7 +865,7 @@ export class Service {
|
||||
deployerLrn: string,
|
||||
applicationRecordId: string,
|
||||
applicationRecordData: ApplicationRecord,
|
||||
isCanonical: boolean,
|
||||
isDNS: boolean,
|
||||
): Promise<Deployment> {
|
||||
const newDeployment = await this.db.addDeployment({
|
||||
project: data.project,
|
||||
@@ -853,13 +876,14 @@ export class Service {
|
||||
status: DeploymentStatus.Building,
|
||||
applicationRecordId,
|
||||
applicationRecordData,
|
||||
domain: data.domain,
|
||||
createdBy: Object.assign(new User(), {
|
||||
id: userId,
|
||||
}),
|
||||
deployer: Object.assign(new Deployer(), {
|
||||
deployerLrn,
|
||||
}),
|
||||
isCanonical
|
||||
isDNS
|
||||
});
|
||||
|
||||
log(`Created deployment ${newDeployment.id}`);
|
||||
@@ -1092,6 +1116,9 @@ export class Service {
|
||||
|
||||
for await (const project of projects) {
|
||||
const octokit = await this.getOctokit(project.ownerId);
|
||||
const [domain] = await this.db.getDomainsByProjectId(project.id, {
|
||||
branch,
|
||||
});
|
||||
|
||||
const deployers = project.deployers;
|
||||
if (!deployers) {
|
||||
@@ -1109,6 +1136,7 @@ export class Service {
|
||||
project.prodBranch === branch
|
||||
? Environment.Production
|
||||
: Environment.Preview,
|
||||
domain,
|
||||
commitHash: headCommit.id,
|
||||
commitMessage: headCommit.message,
|
||||
deployer: deployer
|
||||
@@ -1150,6 +1178,7 @@ export class Service {
|
||||
const oldDeployment = await this.db.getDeployment({
|
||||
relations: {
|
||||
project: true,
|
||||
domain: true,
|
||||
deployer: true,
|
||||
createdBy: true,
|
||||
},
|
||||
@@ -1175,6 +1204,7 @@ export class Service {
|
||||
// TODO: Put isCurrent field in project
|
||||
branch: oldDeployment.branch,
|
||||
environment: Environment.Production,
|
||||
domain: oldDeployment.domain,
|
||||
commitHash: oldDeployment.commitHash,
|
||||
commitMessage: oldDeployment.commitMessage,
|
||||
deployer: oldDeployment.deployer
|
||||
@@ -1192,6 +1222,7 @@ export class Service {
|
||||
// TODO: Implement transactions
|
||||
const oldCurrentDeployment = await this.db.getDeployment({
|
||||
relations: {
|
||||
domain: true,
|
||||
project: true,
|
||||
deployer: true,
|
||||
},
|
||||
@@ -1200,7 +1231,7 @@ export class Service {
|
||||
id: projectId,
|
||||
},
|
||||
isCurrent: true,
|
||||
isCanonical: false,
|
||||
isDNS: false,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1210,34 +1241,22 @@ export class Service {
|
||||
|
||||
const oldCurrentDeploymentUpdate = await this.db.updateDeploymentById(
|
||||
oldCurrentDeployment.id,
|
||||
{ isCurrent: false },
|
||||
{ isCurrent: false, domain: null },
|
||||
);
|
||||
|
||||
const newCurrentDeploymentUpdate = await this.db.updateDeploymentById(
|
||||
deploymentId,
|
||||
{ isCurrent: true },
|
||||
{ isCurrent: true, domain: oldCurrentDeployment.domain },
|
||||
);
|
||||
|
||||
if (!newCurrentDeploymentUpdate || !oldCurrentDeploymentUpdate){
|
||||
return false;
|
||||
}
|
||||
|
||||
const newCurrentDeployment = await this.db.getDeployment({ where: { id: deploymentId }, relations: { project: true, deployer: true } });
|
||||
|
||||
if (!newCurrentDeployment) {
|
||||
throw new Error(`Deployment with Id ${deploymentId} not found`);
|
||||
}
|
||||
|
||||
const applicationDeploymentRequestData = newCurrentDeployment.applicationDeploymentRequestData;
|
||||
|
||||
const customDomain = await this.db.getOldestDomainByProjectId(projectId);
|
||||
|
||||
if (customDomain && applicationDeploymentRequestData) {
|
||||
applicationDeploymentRequestData.dns = customDomain.name
|
||||
}
|
||||
|
||||
// Create a canonical deployment for the new current deployment
|
||||
const canonicalDeployment = await this.createDeploymentFromData(
|
||||
// Create a DNS deployment for the new current deployment
|
||||
const dnsDeployment = await this.createDeploymentFromData(
|
||||
newCurrentDeployment.project.ownerId,
|
||||
newCurrentDeployment,
|
||||
newCurrentDeployment.deployer!.deployerLrn!,
|
||||
@@ -1246,6 +1265,9 @@ export class Service {
|
||||
true,
|
||||
);
|
||||
|
||||
const applicationDeploymentRequestData = newCurrentDeployment.applicationDeploymentRequestData;
|
||||
|
||||
applicationDeploymentRequestData!.version = (Number(applicationDeploymentRequestData?.version) + 1).toString();
|
||||
applicationDeploymentRequestData!.meta = JSON.stringify({
|
||||
...JSON.parse(applicationDeploymentRequestData!.meta),
|
||||
note: `Updated by Snowball @ ${DateTime.utc().toFormat(
|
||||
@@ -1259,12 +1281,12 @@ export class Service {
|
||||
|
||||
log(`Application deployment request record published: ${result.id}`)
|
||||
|
||||
const updateResult = await this.db.updateDeploymentById(canonicalDeployment.id, {
|
||||
await this.db.updateDeploymentById(dnsDeployment.id, {
|
||||
applicationDeploymentRequestId: result.id,
|
||||
applicationDeploymentRequestData,
|
||||
});
|
||||
|
||||
return updateResult;
|
||||
return newCurrentDeploymentUpdate && oldCurrentDeploymentUpdate;
|
||||
}
|
||||
|
||||
async deleteDeployment(deploymentId: string): Promise<boolean> {
|
||||
@@ -1281,11 +1303,11 @@ export class Service {
|
||||
if (deployment && deployment.applicationDeploymentRecordId) {
|
||||
// If deployment is current, remove deployment for project subdomain as well
|
||||
if (deployment.isCurrent) {
|
||||
const canonicalDeployment = await this.db.getDeployment({
|
||||
const dnsDeployment = await this.db.getDeployment({
|
||||
where: {
|
||||
projectId: deployment.project.id,
|
||||
deployer: deployment.deployer,
|
||||
isCanonical: true
|
||||
isDNS: true
|
||||
},
|
||||
relations: {
|
||||
project: true,
|
||||
@@ -1293,53 +1315,27 @@ export class Service {
|
||||
},
|
||||
})
|
||||
|
||||
// If the canonical deployment is not present then query the chain for the deployment record for backward compatibility
|
||||
if (!canonicalDeployment) {
|
||||
log(`Canonical deployment for deployment with id ${deployment.id} not found, querying the chain..`);
|
||||
const currentDeploymentURL = `https://${(deployment.project.name).toLowerCase()}.${deployment.deployer.baseDomain}`;
|
||||
if (!dnsDeployment) {
|
||||
log(`DNS deployment for deployment with id ${deployment.id} not found`);
|
||||
|
||||
const deploymentRecords =
|
||||
await this.laconicRegistry.getDeploymentRecordsByFilter({
|
||||
application: deployment.applicationRecordId,
|
||||
url: currentDeploymentURL,
|
||||
});
|
||||
|
||||
if (!deploymentRecords.length) {
|
||||
log(
|
||||
`No ApplicationDeploymentRecord found for URL ${currentDeploymentURL} and ApplicationDeploymentRecord id ${deployment.applicationDeploymentRecordId}`,
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Multiple records are fetched, take the latest record
|
||||
const latestRecord = deploymentRecords
|
||||
.sort((a, b) => new Date(b.createTime).getTime() - new Date(a.createTime).getTime())[0];
|
||||
|
||||
await this.laconicRegistry.createApplicationDeploymentRemovalRequest({
|
||||
deploymentId: latestRecord.id,
|
||||
deployerLrn: deployment.deployer.deployerLrn,
|
||||
auctionId: deployment.project.auctionId,
|
||||
payment: deployment.project.txHash
|
||||
});
|
||||
} else {
|
||||
// If canonical deployment is found in the DB, then send the removal request with that deployment record Id
|
||||
const result =
|
||||
await this.laconicRegistry.createApplicationDeploymentRemovalRequest({
|
||||
deploymentId: canonicalDeployment.applicationDeploymentRecordId!,
|
||||
deployerLrn: canonicalDeployment.deployer.deployerLrn,
|
||||
auctionId: canonicalDeployment.project.auctionId,
|
||||
payment: canonicalDeployment.project.txHash
|
||||
});
|
||||
|
||||
await this.db.updateDeploymentById(canonicalDeployment.id, {
|
||||
status: DeploymentStatus.Deleting,
|
||||
applicationDeploymentRemovalRequestId:
|
||||
result.applicationDeploymentRemovalRequestId,
|
||||
applicationDeploymentRemovalRequestData:
|
||||
result.applicationDeploymentRemovalRequestData,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
const dnsResult =
|
||||
await this.laconicRegistry.createApplicationDeploymentRemovalRequest({
|
||||
deploymentId: dnsDeployment.applicationDeploymentRecordId!,
|
||||
deployerLrn: dnsDeployment.deployer.deployerLrn,
|
||||
auctionId: dnsDeployment.project.auctionId,
|
||||
payment: dnsDeployment.project.txHash
|
||||
});
|
||||
|
||||
await this.db.updateDeploymentById(dnsDeployment.id, {
|
||||
status: DeploymentStatus.Deleting,
|
||||
applicationDeploymentRemovalRequestId:
|
||||
dnsResult.applicationDeploymentRemovalRequestId,
|
||||
applicationDeploymentRemovalRequestData:
|
||||
dnsResult.applicationDeploymentRemovalRequestData,
|
||||
});
|
||||
}
|
||||
|
||||
const result =
|
||||
|
||||
@@ -133,6 +133,7 @@ record:
|
||||
LACONIC_HOSTED_CONFIG_github_pwa_templaterepo: laconic-templates/test-progressive-web-app
|
||||
LACONIC_HOSTED_CONFIG_github_image_upload_templaterepo: laconic-templates/image-upload-pwa-example
|
||||
LACONIC_HOSTED_CONFIG_github_next_app_templaterepo: laconic-templates/starter.nextjs-react-tailwind
|
||||
LACONIC_HOSTED_CONFIG_wallet_connect_id: 63cad7ba97391f63652161f484670e15
|
||||
LACONIC_HOSTED_CONFIG_laconicd_chain_id: laconic-testnet-2
|
||||
LACONIC_HOSTED_CONFIG_wallet_iframe_url: https://wallet.laconic.com
|
||||
meta:
|
||||
|
||||
@@ -127,6 +127,7 @@ record:
|
||||
LACONIC_HOSTED_CONFIG_github_pwa_templaterepo: laconic-templates/test-progressive-web-app
|
||||
LACONIC_HOSTED_CONFIG_github_image_upload_templaterepo: laconic-templates/image-upload-pwa-example
|
||||
LACONIC_HOSTED_CONFIG_github_next_app_templaterepo: laconic-templates/starter.nextjs-react-tailwind
|
||||
LACONIC_HOSTED_CONFIG_wallet_connect_id: 63cad7ba97391f63652161f484670e15
|
||||
LACONIC_HOSTED_CONFIG_laconicd_chain_id: laconic-testnet-2
|
||||
meta:
|
||||
note: Added by Snowball @ $CURRENT_DATE_TIME
|
||||
|
||||
@@ -5,6 +5,8 @@ VITE_GITHUB_PWA_TEMPLATE_REPO="snowball-tools/test-progressive-web-app"
|
||||
VITE_GITHUB_IMAGE_UPLOAD_PWA_TEMPLATE_REPO="snowball-tools/image-upload-pwa-example"
|
||||
VITE_GITHUB_NEXT_APP_TEMPLATE_REPO="snowball-tools/starter.nextjs-react-tailwind"
|
||||
|
||||
VITE_WALLET_CONNECT_ID=
|
||||
|
||||
VITE_LIT_RELAY_API_KEY=
|
||||
|
||||
VITE_BUGSNAG_API_KEY=
|
||||
|
||||
@@ -41,12 +41,13 @@
|
||||
"@turnkey/http": "^2.10.0",
|
||||
"@turnkey/sdk-react": "^0.1.0",
|
||||
"@turnkey/webauthn-stamper": "^0.5.0",
|
||||
"@walletconnect/ethereum-provider": "^2.16.1",
|
||||
"@web3modal/siwe": "4.0.5",
|
||||
"@web3modal/wagmi": "4.0.5",
|
||||
"assert": "^2.1.0",
|
||||
"axios": "^1.6.7",
|
||||
"clsx": "^2.1.0",
|
||||
"date-fns": "^3.3.1",
|
||||
"ethers": "^5.6.2",
|
||||
"downshift": "^8.3.2",
|
||||
"framer-motion": "^11.0.8",
|
||||
"gql-client": "^1.0.0",
|
||||
@@ -68,6 +69,7 @@
|
||||
"usehooks-ts": "^2.15.1",
|
||||
"uuid": "^9.0.1",
|
||||
"viem": "^2.7.11",
|
||||
"wagmi": "2.5.7",
|
||||
"web-vitals": "^2.1.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -11,8 +11,8 @@ import ProjectSearchLayout from './layouts/ProjectSearch';
|
||||
import Index from './pages';
|
||||
import AuthPage from './pages/AuthPage';
|
||||
import { DashboardLayout } from './pages/org-slug/layout';
|
||||
import Web3Provider from 'context/Web3Provider';
|
||||
import { BASE_URL } from 'utils/constants';
|
||||
import BuyPrepaidService from './pages/BuyPrepaidService';
|
||||
|
||||
const router = createBrowserRouter([
|
||||
{
|
||||
@@ -50,10 +50,6 @@ const router = createBrowserRouter([
|
||||
path: '/login',
|
||||
element: <AuthPage />,
|
||||
},
|
||||
{
|
||||
path: '/buy-prepaid-service',
|
||||
element: <BuyPrepaidService />,
|
||||
},
|
||||
]);
|
||||
|
||||
function App() {
|
||||
@@ -79,7 +75,9 @@ function App() {
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<RouterProvider router={router} />
|
||||
<Web3Provider>
|
||||
<RouterProvider router={router} />
|
||||
</Web3Provider>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import {
|
||||
Select,
|
||||
Option,
|
||||
Spinner,
|
||||
} from '@snowballtools/material-tailwind-react-fork';
|
||||
|
||||
const AccountsDropdown = ({
|
||||
accounts,
|
||||
isDataReceived,
|
||||
onAccountChange,
|
||||
}: {
|
||||
accounts: string[];
|
||||
isDataReceived: boolean;
|
||||
onAccountChange: (selectedAccount: string) => void;
|
||||
}) => {
|
||||
return (
|
||||
<div className="p-6 bg-slate-100 dark:bg-overlay3 rounded-lg mb-6 shadow-md">
|
||||
{isDataReceived ? (
|
||||
!accounts.length ? (
|
||||
<div className="text-center">
|
||||
<p className="text-gray-700 dark:text-gray-300 mb-4">
|
||||
No accounts found. Please visit{' '}
|
||||
<a
|
||||
href="https://store.laconic.com"
|
||||
target="_blank"
|
||||
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"
|
||||
>
|
||||
{accounts.map((account, index) => (
|
||||
<Option key={index} value={account}>
|
||||
{account}
|
||||
</Option>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
)
|
||||
) : (
|
||||
<div className="flex items-center justify-center h-12">
|
||||
<Spinner className="h-6 w-6" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default AccountsDropdown;
|
||||
@@ -1,67 +0,0 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
import { Modal } from '@mui/material';
|
||||
|
||||
import { VITE_WALLET_IFRAME_URL } from 'utils/constants';
|
||||
import useCheckBalance from '../../../hooks/useCheckBalance';
|
||||
|
||||
const CHECK_BALANCE_INTERVAL = 5000;
|
||||
const IFRAME_ID = 'checkBalanceIframe';
|
||||
|
||||
const CheckBalanceIframe = ({
|
||||
onBalanceChange,
|
||||
isPollingEnabled,
|
||||
amount,
|
||||
}: {
|
||||
onBalanceChange: (value: boolean | undefined) => void;
|
||||
isPollingEnabled: boolean;
|
||||
amount: string;
|
||||
}) => {
|
||||
const { isBalanceSufficient, checkBalance } = useCheckBalance(
|
||||
amount,
|
||||
IFRAME_ID,
|
||||
);
|
||||
|
||||
const [isLoaded, setIsLoaded] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isLoaded) {
|
||||
return;
|
||||
}
|
||||
checkBalance();
|
||||
}, [amount, checkBalance, isLoaded]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isPollingEnabled || !isLoaded || isBalanceSufficient) {
|
||||
return;
|
||||
}
|
||||
|
||||
const interval = setInterval(() => {
|
||||
checkBalance();
|
||||
}, CHECK_BALANCE_INTERVAL);
|
||||
|
||||
return () => {
|
||||
clearInterval(interval);
|
||||
};
|
||||
}, [isBalanceSufficient, isPollingEnabled, checkBalance, isLoaded]);
|
||||
|
||||
useEffect(() => {
|
||||
onBalanceChange(isBalanceSufficient);
|
||||
}, [isBalanceSufficient]);
|
||||
|
||||
return (
|
||||
<Modal open={false} disableEscapeKeyDown keepMounted>
|
||||
<iframe
|
||||
onLoad={() => setIsLoaded(true)}
|
||||
id={IFRAME_ID}
|
||||
src={VITE_WALLET_IFRAME_URL}
|
||||
width="100%"
|
||||
height="100%"
|
||||
sandbox="allow-scripts allow-same-origin"
|
||||
className="border rounded-md shadow-sm"
|
||||
/>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default CheckBalanceIframe;
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useCallback, useState, useEffect, useMemo } from 'react';
|
||||
import { useCallback, useState, useEffect } from 'react';
|
||||
import { useForm, Controller } from 'react-hook-form';
|
||||
import { FormProvider, FieldValues } from 'react-hook-form';
|
||||
import { useNavigate, useSearchParams } from 'react-router-dom';
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
AuctionParams,
|
||||
Deployer,
|
||||
} from 'gql-client';
|
||||
import { BigNumber } from 'ethers';
|
||||
|
||||
import { Select, MenuItem, FormControl, FormHelperText } from '@mui/material';
|
||||
|
||||
@@ -21,19 +20,19 @@ import { Button } from '../../shared/Button';
|
||||
import { Input } from 'components/shared/Input';
|
||||
import { useToast } from 'components/shared/Toast';
|
||||
import { useGQLClient } from '../../../context/GQLClientContext';
|
||||
import ApproveTransactionModal from './ApproveTransactionModal';
|
||||
import IFrameModal from './IFrameModal';
|
||||
import EnvironmentVariablesForm from 'pages/org-slug/projects/id/settings/EnvironmentVariablesForm';
|
||||
import { EnvironmentVariablesFormValues } from 'types/types';
|
||||
import {
|
||||
VITE_LACONICD_CHAIN_ID,
|
||||
VITE_WALLET_IFRAME_URL,
|
||||
} from 'utils/constants';
|
||||
import CheckBalanceIframe from './CheckBalanceIframe';
|
||||
import AccountsDropdown from './AccountsDropdown';
|
||||
|
||||
type ConfigureDeploymentFormValues = {
|
||||
option: string;
|
||||
lrn?: string;
|
||||
numProviders?: string;
|
||||
numProviders?: number;
|
||||
maxPrice?: string;
|
||||
};
|
||||
|
||||
@@ -47,13 +46,12 @@ const Configure = () => {
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [deployers, setDeployers] = useState<Deployer[]>([]);
|
||||
const [selectedAccount, setSelectedAccount] = useState<string>();
|
||||
const [accounts, setAccounts] = useState<string[]>([]);
|
||||
const [selectedDeployer, setSelectedDeployer] = useState<Deployer>();
|
||||
const [isPaymentLoading, setIsPaymentLoading] = useState(false);
|
||||
const [isPaymentDone, setIsPaymentDone] = useState(false);
|
||||
const [isFrameVisible, setIsFrameVisible] = useState(false);
|
||||
const [isAccountsDataReceived, setIsAccountsDataReceived] = useState(false);
|
||||
const [balanceMessage, setBalanceMessage] = useState<string>();
|
||||
const [isBalanceSufficient, setIsBalanceSufficient] = useState<boolean>();
|
||||
|
||||
const [searchParams] = useSearchParams();
|
||||
const templateId = searchParams.get('templateId');
|
||||
@@ -77,40 +75,16 @@ const Configure = () => {
|
||||
option: 'Auction',
|
||||
maxPrice: DEFAULT_MAX_PRICE,
|
||||
lrn: '',
|
||||
numProviders: '1',
|
||||
numProviders: 1,
|
||||
variables: [],
|
||||
},
|
||||
});
|
||||
|
||||
const selectedOption = methods.watch('option');
|
||||
const selectedNumProviders = methods.watch('numProviders') ?? '1';
|
||||
const selectedMaxPrice = methods.watch('maxPrice') ?? DEFAULT_MAX_PRICE;
|
||||
|
||||
const isTabletView = useMediaQuery('(min-width: 720px)'); // md:
|
||||
const buttonSize = isTabletView ? { size: 'lg' as const } : {};
|
||||
|
||||
const amountToBePaid = useMemo(() => {
|
||||
let amount: string;
|
||||
|
||||
if (selectedOption === 'LRN') {
|
||||
amount = selectedDeployer?.minimumPayment?.replace(/\D/g, '') ?? '0';
|
||||
} else {
|
||||
if (!selectedNumProviders || !selectedMaxPrice) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const bigMaxPrice = BigNumber.from(selectedMaxPrice);
|
||||
amount = bigMaxPrice.mul(selectedNumProviders).toString();
|
||||
}
|
||||
|
||||
return amount;
|
||||
}, [
|
||||
selectedOption,
|
||||
selectedDeployer?.minimumPayment,
|
||||
selectedMaxPrice,
|
||||
selectedNumProviders,
|
||||
]);
|
||||
|
||||
const createProject = async (
|
||||
data: FieldValues,
|
||||
envVariables: AddEnvironmentVariableInput[],
|
||||
@@ -212,6 +186,7 @@ const Configure = () => {
|
||||
(deployer) => deployer.deployerLrn === deployerLrn,
|
||||
);
|
||||
|
||||
let amount: string;
|
||||
let senderAddress: string;
|
||||
let txHash: string | null = null;
|
||||
if (createFormData.option === 'LRN' && !deployer?.minimumPayment) {
|
||||
@@ -229,6 +204,16 @@ const Configure = () => {
|
||||
|
||||
senderAddress = selectedAccount;
|
||||
|
||||
if (createFormData.option === 'LRN') {
|
||||
amount = deployer?.minimumPayment!;
|
||||
} else {
|
||||
amount = (
|
||||
createFormData.numProviders * createFormData.maxPrice
|
||||
).toString();
|
||||
}
|
||||
|
||||
const amountToBePaid = amount.replace(/\D/g, '').toString();
|
||||
|
||||
txHash = await cosmosSendTokensHandler(senderAddress, amountToBePaid);
|
||||
|
||||
if (!txHash) {
|
||||
@@ -318,7 +303,7 @@ const Configure = () => {
|
||||
throw new Error(error);
|
||||
}
|
||||
},
|
||||
[client, createProject, dismiss, toast, amountToBePaid],
|
||||
[client, createProject, dismiss, toast],
|
||||
);
|
||||
|
||||
const fetchDeployers = useCallback(async () => {
|
||||
@@ -326,6 +311,10 @@ const Configure = () => {
|
||||
setDeployers(res.deployers);
|
||||
}, [client]);
|
||||
|
||||
const onAccountChange = useCallback((account: string) => {
|
||||
setSelectedAccount(account);
|
||||
}, []);
|
||||
|
||||
const onDeployerChange = useCallback(
|
||||
(selectedLrn: string) => {
|
||||
const deployer = deployers.find((d) => d.deployerLrn === selectedLrn);
|
||||
@@ -351,20 +340,12 @@ const Configure = () => {
|
||||
await requestTx(senderAddress, snowballAddress, amount);
|
||||
|
||||
const txHash = await new Promise<string | null>((resolve, reject) => {
|
||||
// Call cleanup method only if appropriate event type is recieved
|
||||
const cleanup = () => {
|
||||
setIsFrameVisible(false);
|
||||
window.removeEventListener('message', handleTxStatus);
|
||||
};
|
||||
|
||||
const handleTxStatus = async (event: MessageEvent) => {
|
||||
if (event.origin !== VITE_WALLET_IFRAME_URL) return;
|
||||
|
||||
if (event.data.type === 'TRANSACTION_RESPONSE') {
|
||||
const txResponse = event.data.data;
|
||||
resolve(txResponse);
|
||||
|
||||
cleanup();
|
||||
} else if (event.data.type === 'ERROR') {
|
||||
console.error('Error from wallet:', event.data.message);
|
||||
reject(new Error('Transaction failed'));
|
||||
@@ -374,9 +355,10 @@ const Configure = () => {
|
||||
variant: 'error',
|
||||
onDismiss: dismiss,
|
||||
});
|
||||
|
||||
cleanup();
|
||||
}
|
||||
setIsFrameVisible(false);
|
||||
|
||||
window.removeEventListener('message', handleTxStatus);
|
||||
};
|
||||
|
||||
window.addEventListener('message', handleTxStatus);
|
||||
@@ -436,12 +418,6 @@ const Configure = () => {
|
||||
fetchDeployers();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (isBalanceSufficient) {
|
||||
setBalanceMessage(undefined);
|
||||
}
|
||||
}, [isBalanceSufficient]);
|
||||
|
||||
return (
|
||||
<div className="space-y-7 px-4 py-6">
|
||||
<div className="flex justify-between mb-6">
|
||||
@@ -558,7 +534,6 @@ const Configure = () => {
|
||||
type="number"
|
||||
value={value}
|
||||
onChange={(e) => onChange(e)}
|
||||
min={1}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
@@ -572,7 +547,7 @@ const Configure = () => {
|
||||
control={methods.control}
|
||||
rules={{ required: true }}
|
||||
render={({ field: { value, onChange } }) => (
|
||||
<Input type="number" value={value} onChange={onChange} min={1} />
|
||||
<Input type="number" value={value} onChange={onChange} />
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
@@ -604,83 +579,49 @@ const Configure = () => {
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex gap-4">
|
||||
<Button
|
||||
{...buttonSize}
|
||||
type="submit"
|
||||
shape="default"
|
||||
disabled={
|
||||
isLoading ||
|
||||
isPaymentLoading ||
|
||||
!selectedAccount ||
|
||||
!isBalanceSufficient ||
|
||||
amountToBePaid === '' ||
|
||||
selectedNumProviders === ''
|
||||
}
|
||||
rightIcon={
|
||||
isLoading || isPaymentLoading ? (
|
||||
<LoadingIcon className="animate-spin" />
|
||||
) : (
|
||||
<ArrowRightCircleFilledIcon />
|
||||
)
|
||||
}
|
||||
>
|
||||
{!isPaymentDone
|
||||
? isPaymentLoading
|
||||
? 'Transaction Requested'
|
||||
: 'Pay and Deploy'
|
||||
: isLoading
|
||||
? 'Deploying'
|
||||
: 'Deploy'}
|
||||
</Button>
|
||||
{isAccountsDataReceived && isBalanceSufficient !== undefined ? (
|
||||
!selectedAccount || !isBalanceSufficient ? (
|
||||
<div className="flex items-center gap-4">
|
||||
<Button
|
||||
{...buttonSize}
|
||||
shape="default"
|
||||
onClick={(e: any) => {
|
||||
e.preventDefault();
|
||||
setBalanceMessage('Waiting for payment');
|
||||
window.open(
|
||||
'https://store.laconic.com',
|
||||
'_blank',
|
||||
'noopener,noreferrer',
|
||||
);
|
||||
}}
|
||||
>
|
||||
Buy prepaid service
|
||||
</Button>
|
||||
<p className="text-gray-700 dark:text-gray-300">
|
||||
{balanceMessage !== undefined ? (
|
||||
<div className="flex items-center gap-2 text-white">
|
||||
<LoadingIcon className="animate-spin w-5 h-5" />
|
||||
<p>{balanceMessage}</p>
|
||||
</div>
|
||||
) : !selectedAccount ? (
|
||||
'No accounts found. Create a wallet.'
|
||||
<>
|
||||
<AccountsDropdown
|
||||
accounts={accounts}
|
||||
onAccountChange={onAccountChange}
|
||||
isDataReceived={isAccountsDataReceived}
|
||||
/>
|
||||
{accounts.length > 0 && (
|
||||
<div>
|
||||
<Button
|
||||
{...buttonSize}
|
||||
type="submit"
|
||||
shape="default"
|
||||
disabled={
|
||||
isLoading || isPaymentLoading || !selectedAccount
|
||||
}
|
||||
rightIcon={
|
||||
isLoading || isPaymentLoading ? (
|
||||
<LoadingIcon className="animate-spin" />
|
||||
) : (
|
||||
'Insufficient funds.'
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
) : null
|
||||
) : null}
|
||||
</div>
|
||||
<ArrowRightCircleFilledIcon />
|
||||
)
|
||||
}
|
||||
>
|
||||
{!isPaymentDone
|
||||
? isPaymentLoading
|
||||
? 'Transaction Requested'
|
||||
: 'Pay and Deploy'
|
||||
: isLoading
|
||||
? 'Deploying'
|
||||
: 'Deploy'}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</form>
|
||||
</FormProvider>
|
||||
|
||||
<ApproveTransactionModal
|
||||
setAccount={setSelectedAccount}
|
||||
<IFrameModal
|
||||
setAccounts={setAccounts}
|
||||
setIsDataReceived={setIsAccountsDataReceived}
|
||||
isVisible={isFrameVisible}
|
||||
/>
|
||||
<CheckBalanceIframe
|
||||
onBalanceChange={setIsBalanceSufficient}
|
||||
amount={amountToBePaid}
|
||||
isPollingEnabled={true}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
+7
-15
@@ -7,12 +7,12 @@ import {
|
||||
VITE_WALLET_IFRAME_URL,
|
||||
} from 'utils/constants';
|
||||
|
||||
const ApproveTransactionModal = ({
|
||||
setAccount,
|
||||
const IFrameModal = ({
|
||||
setAccounts,
|
||||
setIsDataReceived,
|
||||
isVisible,
|
||||
}: {
|
||||
setAccount: (account: string) => void;
|
||||
setAccounts: (accounts: string[]) => void;
|
||||
setIsDataReceived: (isReceived: boolean) => void;
|
||||
isVisible: boolean;
|
||||
}) => {
|
||||
@@ -20,18 +20,10 @@ const ApproveTransactionModal = ({
|
||||
const handleMessage = (event: MessageEvent) => {
|
||||
if (event.origin !== VITE_WALLET_IFRAME_URL) return;
|
||||
|
||||
setIsDataReceived(true);
|
||||
if (event.data.type === 'WALLET_ACCOUNTS_DATA') {
|
||||
setIsDataReceived(true);
|
||||
|
||||
if (event.data.data.length === 0) {
|
||||
console.error(`Accounts not present for chainId: ${VITE_LACONICD_CHAIN_ID}`);
|
||||
return;
|
||||
}
|
||||
|
||||
setAccount(event.data.data[0].address);
|
||||
}
|
||||
|
||||
if (event.data.type === 'ERROR') {
|
||||
setAccounts(event.data.data);
|
||||
} else if (event.data.type === 'ERROR') {
|
||||
console.error('Error from wallet:', event.data.message);
|
||||
}
|
||||
};
|
||||
@@ -93,4 +85,4 @@ const ApproveTransactionModal = ({
|
||||
);
|
||||
};
|
||||
|
||||
export default ApproveTransactionModal;
|
||||
export default IFrameModal;
|
||||
@@ -0,0 +1,42 @@
|
||||
import { CopyBlock, atomOneLight } from 'react-code-blocks';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
import { Modal } from 'components/shared/Modal';
|
||||
import { Button } from 'components/shared/Button';
|
||||
|
||||
interface AssignDomainProps {
|
||||
open: boolean;
|
||||
handleOpen: () => void;
|
||||
}
|
||||
|
||||
const AssignDomainDialog = ({ open, handleOpen }: AssignDomainProps) => {
|
||||
return (
|
||||
<Modal open={open} onOpenChange={handleOpen}>
|
||||
<Modal.Content>
|
||||
<Modal.Header>Assign Domain</Modal.Header>
|
||||
<Modal.Body>
|
||||
In order to assign a domain to your production deployments, configure
|
||||
it in the{' '}
|
||||
{/* TODO: Fix selection of project settings tab on navigation to domains */}
|
||||
<Link to="../settings/domains" className="text-light-blue-800 inline">
|
||||
project settings{' '}
|
||||
</Link>
|
||||
(recommended). If you want to assign to this specific deployment,
|
||||
however, you can do so using our command-line interface:
|
||||
{/* https://github.com/rajinwonderland/react-code-blocks/issues/138 */}
|
||||
<CopyBlock
|
||||
text="snowball alias <deployment> <domain>"
|
||||
language=""
|
||||
showLineNumbers={false}
|
||||
theme={atomOneLight}
|
||||
/>
|
||||
</Modal.Body>
|
||||
<Modal.Footer className="flex justify-start">
|
||||
<Button onClick={handleOpen}>Okay</Button>
|
||||
</Modal.Footer>
|
||||
</Modal.Content>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default AssignDomainDialog;
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
import { Deployment, Domain, Environment, Project } from 'gql-client';
|
||||
import { Button } from 'components/shared/Button';
|
||||
import {
|
||||
GlobeIcon,
|
||||
HorizontalDotIcon,
|
||||
LinkIcon,
|
||||
RefreshIcon,
|
||||
@@ -17,6 +18,7 @@ import {
|
||||
UndoIcon,
|
||||
CrossCircleIcon,
|
||||
} from 'components/shared/CustomIcon';
|
||||
import AssignDomainDialog from './AssignDomainDialog';
|
||||
import { useGQLClient } from 'context/GQLClientContext';
|
||||
import { cn } from 'utils/classnames';
|
||||
import { ChangeStateToProductionDialog } from 'components/projects/Dialog/ChangeStateToProductionDialog';
|
||||
@@ -47,8 +49,8 @@ export const DeploymentMenu = ({
|
||||
const [redeployToProduction, setRedeployToProduction] = useState(false);
|
||||
const [deleteDeploymentDialog, setDeleteDeploymentDialog] = useState(false);
|
||||
const [isConfirmDeleteLoading, setIsConfirmDeleteLoading] = useState(false);
|
||||
const [isConfirmUpdateLoading, setIsConfirmUpdateLoading] = useState(false);
|
||||
const [rollbackDeployment, setRollbackDeployment] = useState(false);
|
||||
const [assignDomainDialog, setAssignDomainDialog] = useState(false);
|
||||
const [isConfirmButtonLoading, setConfirmButtonLoadingLoading] =
|
||||
useState(false);
|
||||
|
||||
@@ -56,8 +58,6 @@ export const DeploymentMenu = ({
|
||||
const isUpdated = await client.updateDeploymentToProd(deployment.id);
|
||||
if (isUpdated.updateDeploymentToProd) {
|
||||
await onUpdate();
|
||||
setIsConfirmUpdateLoading(false);
|
||||
|
||||
toast({
|
||||
id: 'deployment_changed_to_production',
|
||||
title: 'Deployment changed to production',
|
||||
@@ -102,8 +102,6 @@ export const DeploymentMenu = ({
|
||||
);
|
||||
if (isRollbacked.rollbackDeployment) {
|
||||
await onUpdate();
|
||||
setIsConfirmUpdateLoading(false);
|
||||
|
||||
toast({
|
||||
id: 'deployment_rolled_back',
|
||||
title: 'Deployment rolled back',
|
||||
@@ -175,6 +173,12 @@ export const DeploymentMenu = ({
|
||||
<LinkIcon /> Visit
|
||||
</a>
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
className="hover:bg-base-bg-emphasized flex items-center gap-3"
|
||||
onClick={() => setAssignDomainDialog(!assignDomainDialog)}
|
||||
>
|
||||
<GlobeIcon /> Assign domain
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
className="hover:bg-base-bg-emphasized flex items-center gap-3"
|
||||
onClick={() => setChangeToProduction(!changeToProduction)}
|
||||
@@ -222,11 +226,9 @@ export const DeploymentMenu = ({
|
||||
handleCancel={() => setChangeToProduction((preVal) => !preVal)}
|
||||
open={changeToProduction}
|
||||
handleConfirm={async () => {
|
||||
setIsConfirmUpdateLoading(true);
|
||||
await updateDeployment();
|
||||
setChangeToProduction((preVal) => !preVal);
|
||||
}}
|
||||
isConfirmButtonLoading={isConfirmUpdateLoading}
|
||||
deployment={deployment}
|
||||
domains={prodBranchDomains}
|
||||
/>
|
||||
@@ -241,7 +243,7 @@ export const DeploymentMenu = ({
|
||||
setRedeployToProduction((preVal) => !preVal);
|
||||
}}
|
||||
deployment={deployment}
|
||||
domains={prodBranchDomains}
|
||||
domains={deployment.domain ? [deployment.domain] : []}
|
||||
isConfirmButtonLoading={isConfirmButtonLoading}
|
||||
/>
|
||||
{Boolean(currentDeployment) && (
|
||||
@@ -251,16 +253,18 @@ export const DeploymentMenu = ({
|
||||
open={rollbackDeployment}
|
||||
confirmButtonTitle="Rollback"
|
||||
handleConfirm={async () => {
|
||||
setIsConfirmUpdateLoading(true);
|
||||
await rollbackDeploymentHandler();
|
||||
setRollbackDeployment((preVal) => !preVal);
|
||||
}}
|
||||
deployment={currentDeployment}
|
||||
newDeployment={deployment}
|
||||
domains={prodBranchDomains}
|
||||
isConfirmButtonLoading={isConfirmUpdateLoading}
|
||||
domains={currentDeployment.domain ? [currentDeployment.domain] : []}
|
||||
/>
|
||||
)}
|
||||
<AssignDomainDialog
|
||||
open={assignDomainDialog}
|
||||
handleOpen={() => setAssignDomainDialog(!assignDomainDialog)}
|
||||
/>
|
||||
<DeleteDeploymentDialog
|
||||
open={deleteDeploymentDialog}
|
||||
handleConfirm={async () => {
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
import { User } from 'gql-client';
|
||||
import { motion } from 'framer-motion';
|
||||
import { useDisconnect } from 'wagmi';
|
||||
|
||||
import { useGQLClient } from 'context/GQLClientContext';
|
||||
import {
|
||||
GlobeIcon,
|
||||
LifeBuoyIcon,
|
||||
LogoutIcon,
|
||||
QuestionMarkRoundIcon,
|
||||
} from 'components/shared/CustomIcon';
|
||||
import { Tabs } from 'components/shared/Tabs';
|
||||
@@ -13,9 +16,10 @@ import { Logo } from 'components/Logo';
|
||||
import { Avatar } from 'components/shared/Avatar';
|
||||
import { formatAddress } from 'utils/format';
|
||||
import { getInitials } from 'utils/geInitials';
|
||||
import { Button } from 'components/shared/Button';
|
||||
import { cn } from 'utils/classnames';
|
||||
import { useMediaQuery } from 'usehooks-ts';
|
||||
import { SHOPIFY_APP_URL } from '../../../constants';
|
||||
import { BASE_URL } from 'utils/constants';
|
||||
|
||||
interface SidebarProps {
|
||||
mobileOpen?: boolean;
|
||||
@@ -23,10 +27,12 @@ interface SidebarProps {
|
||||
|
||||
export const Sidebar = ({ mobileOpen }: SidebarProps) => {
|
||||
const { orgSlug } = useParams();
|
||||
const navigate = useNavigate();
|
||||
const client = useGQLClient();
|
||||
const isDesktop = useMediaQuery('(min-width: 960px)');
|
||||
|
||||
const [user, setUser] = useState<User>();
|
||||
const { disconnect } = useDisconnect();
|
||||
|
||||
const fetchUser = useCallback(async () => {
|
||||
const { user } = await client.getUser();
|
||||
@@ -37,6 +43,16 @@ export const Sidebar = ({ mobileOpen }: SidebarProps) => {
|
||||
fetchUser();
|
||||
}, []);
|
||||
|
||||
const handleLogOut = useCallback(async () => {
|
||||
await fetch(`${BASE_URL}/auth/logout`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
});
|
||||
localStorage.clear();
|
||||
disconnect();
|
||||
navigate('/login');
|
||||
}, [disconnect, navigate]);
|
||||
|
||||
return (
|
||||
<motion.nav
|
||||
initial={{ x: -320 }}
|
||||
@@ -66,10 +82,19 @@ export const Sidebar = ({ mobileOpen }: SidebarProps) => {
|
||||
<Tabs defaultValue="Projects" orientation="vertical">
|
||||
{/* // TODO: use proper link buttons */}
|
||||
<Tabs.List>
|
||||
<Tabs.Trigger
|
||||
icon={<GlobeIcon />}
|
||||
value=""
|
||||
className="hidden lg:flex"
|
||||
>
|
||||
<a className="cursor-pointer font-mono" onClick={handleLogOut}>
|
||||
LOG OUT
|
||||
</a>
|
||||
</Tabs.Trigger>
|
||||
<Tabs.Trigger icon={<QuestionMarkRoundIcon />} value="">
|
||||
<a
|
||||
className="cursor-pointer font-mono"
|
||||
href={`${SHOPIFY_APP_URL}/pages/instruction-faq`}
|
||||
href="https://store.laconic.com/pages/instruction-faq"
|
||||
>
|
||||
DOCUMENTATION
|
||||
</a>
|
||||
@@ -100,6 +125,14 @@ export const Sidebar = ({ mobileOpen }: SidebarProps) => {
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
<Button
|
||||
iconOnly
|
||||
variant="ghost"
|
||||
className="text-elements-low-em"
|
||||
onClick={handleLogOut}
|
||||
>
|
||||
<LogoutIcon />
|
||||
</Button>
|
||||
</div>
|
||||
</motion.nav>
|
||||
);
|
||||
|
||||
@@ -1,154 +0,0 @@
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { generateNonce, SiweMessage } from 'siwe';
|
||||
import axios from 'axios';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
import { Box, Modal } from '@mui/material';
|
||||
|
||||
import { BASE_URL, VITE_WALLET_IFRAME_URL } from 'utils/constants';
|
||||
|
||||
const axiosInstance = axios.create({
|
||||
baseURL: BASE_URL,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
},
|
||||
withCredentials: true,
|
||||
});
|
||||
|
||||
const AutoSignInIFrameModal = () => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [accountAddress, setAccountAddress] = useState();
|
||||
|
||||
useEffect(() => {
|
||||
const handleSignInResponse = async (event: MessageEvent) => {
|
||||
if (event.origin !== VITE_WALLET_IFRAME_URL) return;
|
||||
|
||||
if (event.data.type === 'SIGN_IN_RESPONSE') {
|
||||
try {
|
||||
const { success } = (
|
||||
await axiosInstance.post('/auth/validate', {
|
||||
message: event.data.data.message,
|
||||
signature: event.data.data.signature,
|
||||
})
|
||||
).data;
|
||||
|
||||
if (success === true) {
|
||||
navigate('/');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error signing in:', error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('message', handleSignInResponse);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('message', handleSignInResponse);
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const initiateAutoSignIn = async () => {
|
||||
if (!accountAddress) return;
|
||||
|
||||
const iframe = document.getElementById(
|
||||
'autoSignInFrame',
|
||||
) as HTMLIFrameElement;
|
||||
|
||||
if (!iframe.contentWindow) {
|
||||
console.error('Iframe not found or not loaded');
|
||||
return;
|
||||
}
|
||||
|
||||
const message = new SiweMessage({
|
||||
version: '1',
|
||||
domain: window.location.host,
|
||||
uri: window.location.origin,
|
||||
chainId: 1,
|
||||
address: accountAddress,
|
||||
nonce: generateNonce(),
|
||||
// Human-readable ASCII assertion that the user will sign, and it must not contain `\n`.
|
||||
statement: 'Sign in With Ethereum.',
|
||||
}).prepareMessage();
|
||||
|
||||
iframe.contentWindow.postMessage(
|
||||
{
|
||||
type: 'AUTO_SIGN_IN',
|
||||
chainId: '1',
|
||||
message,
|
||||
},
|
||||
VITE_WALLET_IFRAME_URL,
|
||||
);
|
||||
};
|
||||
|
||||
initiateAutoSignIn();
|
||||
}, [accountAddress]);
|
||||
|
||||
useEffect(() => {
|
||||
const handleAccountsDataResponse = async (event: MessageEvent) => {
|
||||
if (event.origin !== VITE_WALLET_IFRAME_URL) return;
|
||||
|
||||
if (event.data.type === 'WALLET_ACCOUNTS_DATA') {
|
||||
setAccountAddress(event.data.data[0].address);
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('message', handleAccountsDataResponse);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('message', handleAccountsDataResponse);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const getAddressFromWallet = useCallback(() => {
|
||||
const iframe = document.getElementById(
|
||||
'autoSignInFrame',
|
||||
) as HTMLIFrameElement;
|
||||
|
||||
if (!iframe.contentWindow) {
|
||||
console.error('Iframe not found or not loaded');
|
||||
return;
|
||||
}
|
||||
|
||||
iframe.contentWindow.postMessage(
|
||||
{
|
||||
type: 'REQUEST_CREATE_OR_GET_ACCOUNTS',
|
||||
chainId: '1',
|
||||
},
|
||||
VITE_WALLET_IFRAME_URL,
|
||||
);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Modal open={true} disableEscapeKeyDown keepMounted>
|
||||
<Box
|
||||
sx={{
|
||||
position: 'absolute',
|
||||
top: '50%',
|
||||
left: '50%',
|
||||
transform: 'translate(-50%, -50%)',
|
||||
width: '90%',
|
||||
maxWidth: '1200px',
|
||||
height: '600px',
|
||||
maxHeight: '80vh',
|
||||
overflow: 'auto',
|
||||
outline: 'none',
|
||||
}}
|
||||
>
|
||||
<iframe
|
||||
onLoad={getAddressFromWallet}
|
||||
id="autoSignInFrame"
|
||||
src={`${VITE_WALLET_IFRAME_URL}/auto-sign-in`}
|
||||
width="100%"
|
||||
height="100%"
|
||||
sandbox="allow-scripts allow-same-origin"
|
||||
></iframe>
|
||||
</Box>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default AutoSignInIFrameModal;
|
||||
@@ -1,5 +1,3 @@
|
||||
export const SHORT_COMMIT_HASH_LENGTH = 8;
|
||||
|
||||
export const SERVER_GQL_PATH = 'graphql';
|
||||
|
||||
export const SHOPIFY_APP_URL = 'https://store.laconic.com';
|
||||
@@ -0,0 +1,116 @@
|
||||
import { ReactNode } from 'react';
|
||||
import assert from 'assert';
|
||||
import { SiweMessage, generateNonce } from 'siwe';
|
||||
import { WagmiProvider } from 'wagmi';
|
||||
import { mainnet } from 'wagmi/chains';
|
||||
import axios from 'axios';
|
||||
|
||||
import { createWeb3Modal } from '@web3modal/wagmi/react';
|
||||
import { defaultWagmiConfig } from '@web3modal/wagmi/react/config';
|
||||
import { createSIWEConfig } from '@web3modal/siwe';
|
||||
import type {
|
||||
SIWECreateMessageArgs,
|
||||
SIWEVerifyMessageArgs,
|
||||
} from '@web3modal/core';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
|
||||
import { VITE_WALLET_CONNECT_ID, BASE_URL } from 'utils/constants';
|
||||
|
||||
if (!VITE_WALLET_CONNECT_ID) {
|
||||
throw new Error('Error: VITE_WALLET_CONNECT_ID env config is not set');
|
||||
}
|
||||
assert(BASE_URL, 'VITE_SERVER_URL is not set in env');
|
||||
|
||||
const queryClient = new QueryClient();
|
||||
const axiosInstance = axios.create({
|
||||
baseURL: BASE_URL,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
},
|
||||
withCredentials: true,
|
||||
});
|
||||
const metadata = {
|
||||
name: 'Deploy App Auth',
|
||||
description: '',
|
||||
url: window.location.origin,
|
||||
icons: ['https://avatars.githubusercontent.com/u/37784886'],
|
||||
};
|
||||
const chains = [mainnet] as const;
|
||||
const config = defaultWagmiConfig({
|
||||
chains,
|
||||
projectId: VITE_WALLET_CONNECT_ID,
|
||||
metadata,
|
||||
});
|
||||
const siweConfig = createSIWEConfig({
|
||||
createMessage: ({ nonce, address, chainId }: SIWECreateMessageArgs) =>
|
||||
new SiweMessage({
|
||||
version: '1',
|
||||
domain: window.location.host,
|
||||
uri: window.location.origin,
|
||||
address,
|
||||
chainId,
|
||||
nonce,
|
||||
// Human-readable ASCII assertion that the user will sign, and it must not contain `\n`.
|
||||
statement: 'Sign in With Ethereum.',
|
||||
}).prepareMessage(),
|
||||
getNonce: async () => {
|
||||
return generateNonce();
|
||||
},
|
||||
getSession: async () => {
|
||||
try {
|
||||
const session = (await axiosInstance.get('/auth/session')).data;
|
||||
const { address, chainId } = session;
|
||||
return { address, chainId };
|
||||
} catch (err) {
|
||||
if (window.location.pathname !== '/login') {
|
||||
window.location.href = '/login';
|
||||
}
|
||||
throw new Error('Failed to get session!');
|
||||
}
|
||||
},
|
||||
verifyMessage: async ({ message, signature }: SIWEVerifyMessageArgs) => {
|
||||
try {
|
||||
const { success } = (
|
||||
await axiosInstance.post('/auth/validate', {
|
||||
message,
|
||||
signature,
|
||||
})
|
||||
).data;
|
||||
return success;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
signOut: async () => {
|
||||
try {
|
||||
const { success } = (await axiosInstance.post('/auth/logout')).data;
|
||||
return success;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
onSignOut: () => {
|
||||
window.location.href = '/login';
|
||||
},
|
||||
onSignIn: () => {
|
||||
window.location.href = '/';
|
||||
},
|
||||
});
|
||||
|
||||
createWeb3Modal({
|
||||
siweConfig,
|
||||
wagmiConfig: config,
|
||||
projectId: VITE_WALLET_CONNECT_ID,
|
||||
});
|
||||
export default function Web3ModalProvider({
|
||||
children,
|
||||
}: {
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<WagmiProvider config={config}>
|
||||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
||||
</WagmiProvider>
|
||||
);
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
|
||||
import { VITE_LACONICD_CHAIN_ID } from 'utils/constants';
|
||||
|
||||
const useCheckBalance = (amount: string, iframeId: string) => {
|
||||
const [isBalanceSufficient, setIsBalanceSufficient] = useState<boolean>();
|
||||
|
||||
const checkBalance = useCallback(() => {
|
||||
const iframe = document.getElementById(iframeId) as HTMLIFrameElement;
|
||||
|
||||
if (!iframe || !iframe.contentWindow) {
|
||||
console.error(`Iframe with ID "${iframeId}" not found or not loaded`);
|
||||
return;
|
||||
}
|
||||
|
||||
iframe.contentWindow.postMessage(
|
||||
{
|
||||
type: 'CHECK_BALANCE',
|
||||
chainId: VITE_LACONICD_CHAIN_ID,
|
||||
amount,
|
||||
},
|
||||
import.meta.env.VITE_WALLET_IFRAME_URL
|
||||
);
|
||||
}, [iframeId, amount]);
|
||||
|
||||
useEffect(() => {
|
||||
const handleMessage = (event: MessageEvent) => {
|
||||
if (event.origin !== import.meta.env.VITE_WALLET_IFRAME_URL) return;
|
||||
|
||||
if (event.data.type !== 'IS_SUFFICIENT') return;
|
||||
|
||||
setIsBalanceSufficient(event.data.data);
|
||||
};
|
||||
|
||||
window.addEventListener('message', handleMessage);
|
||||
return () => {
|
||||
window.removeEventListener('message', handleMessage);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return { isBalanceSufficient, checkBalance };
|
||||
};
|
||||
|
||||
export default useCheckBalance;
|
||||
@@ -14,6 +14,7 @@ import { SERVER_GQL_PATH } from './constants';
|
||||
import { Toaster } from 'components/shared/Toast';
|
||||
import { LogErrorBoundary } from 'utils/log-error';
|
||||
import { BASE_URL } from 'utils/constants';
|
||||
import Web3ModalProvider from './context/Web3Provider';
|
||||
import './index.css';
|
||||
|
||||
console.log(`v-0.0.9`);
|
||||
@@ -31,10 +32,12 @@ root.render(
|
||||
<LogErrorBoundary>
|
||||
<React.StrictMode>
|
||||
<ThemeProvider>
|
||||
<GQLClientProvider client={gqlClient}>
|
||||
<App />
|
||||
<Toaster />
|
||||
</GQLClientProvider>
|
||||
<Web3ModalProvider>
|
||||
<GQLClientProvider client={gqlClient}>
|
||||
<App />
|
||||
<Toaster />
|
||||
</GQLClientProvider>
|
||||
</Web3ModalProvider>
|
||||
</ThemeProvider>
|
||||
</React.StrictMode>
|
||||
</LogErrorBoundary>,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import AutoSignInIFrameModal from 'components/shared/auth/AutoSignInIFrameModal';
|
||||
import { Login } from './auth/Login';
|
||||
|
||||
const AuthPage = () => {
|
||||
return (
|
||||
@@ -13,7 +13,9 @@ const AuthPage = () => {
|
||||
</div>
|
||||
</div>
|
||||
<div className="pb-12 relative z-10 flex-1 flex-center">
|
||||
<AutoSignInIFrameModal />
|
||||
<div className="max-w-[520px] w-full dark:bg-overlay bg-white rounded-xl shadow">
|
||||
<Login />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useMediaQuery } from 'usehooks-ts';
|
||||
|
||||
import { Button } from 'components/shared';
|
||||
import CheckBalanceIframe from 'components/projects/create/CheckBalanceIframe';
|
||||
import { SHOPIFY_APP_URL } from '../constants';
|
||||
|
||||
const BuyPrepaidService = () => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [isBalanceSufficient, setIsBalanceSufficient] = useState<boolean>();
|
||||
|
||||
const isTabletView = useMediaQuery('(min-width: 720px)'); // md:
|
||||
const buttonSize = isTabletView ? { size: 'lg' as const } : {};
|
||||
|
||||
useEffect(() => {
|
||||
if (isBalanceSufficient === true) {
|
||||
navigate('/');
|
||||
}
|
||||
}, [isBalanceSufficient]);
|
||||
|
||||
return (
|
||||
<div className="dark:bg-background flex flex-col min-h-screen">
|
||||
<div className="pb-12 relative z-10 flex-1 flex-center">
|
||||
<Button {...buttonSize} shape={'default'}>
|
||||
<a href={SHOPIFY_APP_URL} target="_blank">
|
||||
Buy prepaid service
|
||||
</a>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<CheckBalanceIframe onBalanceChange={setIsBalanceSufficient} isPollingEnabled={true} amount='1'/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default BuyPrepaidService;
|
||||
@@ -9,6 +9,12 @@ export const Login = () => {
|
||||
</div>
|
||||
</div>
|
||||
<WavyBorder className="self-stretch" variant="stroke" />
|
||||
|
||||
<div className="self-stretch p-4 xs:p-6 flex-col justify-center items-center gap-8 flex">
|
||||
<div className="self-stretch flex-col justify-center items-center gap-3 flex">
|
||||
<w3m-button />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -21,6 +21,15 @@ import { ChangeStateToProductionDialog } from 'components/projects/Dialog/Change
|
||||
|
||||
const deployment: Deployment = {
|
||||
id: '1',
|
||||
domain: {
|
||||
id: 'domain1',
|
||||
branch: 'main',
|
||||
name: 'example.com',
|
||||
status: DomainStatus.Live,
|
||||
redirectTo: null,
|
||||
createdAt: '1677609600', // 2023-02-25T12:00:00Z
|
||||
updatedAt: '1677613200', // 2023-02-25T13:00:00Z
|
||||
},
|
||||
branch: 'main',
|
||||
commitHash: 'a1b2c3d',
|
||||
commitMessage:
|
||||
@@ -245,7 +254,7 @@ const ModalsPage: React.FC = () => {
|
||||
setRedeployToProduction((preVal) => !preVal)
|
||||
}
|
||||
deployment={deployment}
|
||||
domains={domains}
|
||||
domains={deployment.domain ? [deployment.domain] : []}
|
||||
/>
|
||||
{/* Rollback to this deployment */}
|
||||
<Button onClick={() => setRollbackDeployment(true)}>
|
||||
@@ -261,7 +270,7 @@ const ModalsPage: React.FC = () => {
|
||||
}
|
||||
deployment={deployment}
|
||||
newDeployment={deployment}
|
||||
domains={domains}
|
||||
domains={deployment.domain ? [deployment.domain] : []}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,20 +1,16 @@
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { Link, useNavigate, useParams } from 'react-router-dom';
|
||||
import { Link, useParams } from 'react-router-dom';
|
||||
|
||||
import { ProjectCard } from 'components/projects/ProjectCard';
|
||||
import { Heading, Badge, Button } from 'components/shared';
|
||||
import { PlusIcon } from 'components/shared/CustomIcon';
|
||||
import { useGQLClient } from 'context/GQLClientContext';
|
||||
import { Project } from 'gql-client';
|
||||
import CheckBalanceIframe from 'components/projects/create/CheckBalanceIframe';
|
||||
|
||||
const Projects = () => {
|
||||
const [isBalanceSufficient, setIsBalanceSufficient] = useState<boolean>();
|
||||
const [projects, setProjects] = useState<Project[]>([]);
|
||||
|
||||
const navigate = useNavigate();
|
||||
const client = useGQLClient();
|
||||
const { orgSlug } = useParams();
|
||||
const [projects, setProjects] = useState<Project[]>([]);
|
||||
|
||||
const fetchProjects = useCallback(async () => {
|
||||
const { projectsInOrganization } = await client.getProjectsInOrganization(
|
||||
@@ -27,12 +23,6 @@ const Projects = () => {
|
||||
fetchProjects();
|
||||
}, [orgSlug]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isBalanceSufficient === false) {
|
||||
navigate('/buy-prepaid-service');
|
||||
}
|
||||
}, [isBalanceSufficient]);
|
||||
|
||||
return (
|
||||
<section className="px-4 md:px-6 py-6 flex flex-col gap-6">
|
||||
{/* Header */}
|
||||
@@ -59,8 +49,6 @@ const Projects = () => {
|
||||
return <ProjectCard project={project} key={key} />;
|
||||
})}
|
||||
</div>
|
||||
|
||||
<CheckBalanceIframe onBalanceChange={setIsBalanceSufficient} isPollingEnabled={false} amount='1' />
|
||||
</section>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -100,6 +100,7 @@ export const deployment0: Deployment = {
|
||||
environment: Environment.Development,
|
||||
isCurrent: true,
|
||||
commitHash: 'Commit Hash',
|
||||
domain: domain0,
|
||||
commitMessage: 'Commit Message',
|
||||
createdBy: user,
|
||||
deployer: {
|
||||
|
||||
@@ -8,6 +8,7 @@ export const VITE_GITHUB_IMAGE_UPLOAD_PWA_TEMPLATE_REPO = import.meta.env
|
||||
export const VITE_GITHUB_NEXT_APP_TEMPLATE_REPO = import.meta.env
|
||||
.VITE_GITHUB_NEXT_APP_TEMPLATE_REPO;
|
||||
export const VITE_GITHUB_CLIENT_ID = import.meta.env.VITE_GITHUB_CLIENT_ID;
|
||||
export const VITE_WALLET_CONNECT_ID = import.meta.env.VITE_WALLET_CONNECT_ID;
|
||||
export const VITE_BUGSNAG_API_KEY = import.meta.env.VITE_BUGSNAG_API_KEY;
|
||||
export const VITE_LIT_RELAY_API_KEY = import.meta.env.VITE_LIT_RELAY_API_KEY;
|
||||
export const VITE_LACONICD_CHAIN_ID = import.meta.env.VITE_LACONICD_CHAIN_ID;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { WalletConnectModal } from '@walletconnect/modal';
|
||||
|
||||
import { VITE_WALLET_CONNECT_ID } from 'utils/constants';
|
||||
|
||||
export const walletConnectModal = new WalletConnectModal({
|
||||
projectId: VITE_WALLET_CONNECT_ID,
|
||||
chains: [],
|
||||
});
|
||||
@@ -63,6 +63,14 @@ query ($projectId: String!) {
|
||||
deployer {
|
||||
baseDomain
|
||||
}
|
||||
domain {
|
||||
status
|
||||
branch
|
||||
createdAt
|
||||
updatedAt
|
||||
id
|
||||
name
|
||||
}
|
||||
createdBy {
|
||||
id
|
||||
name
|
||||
@@ -110,6 +118,14 @@ query ($organizationSlug: String!) {
|
||||
applicationDeploymentRecordData {
|
||||
url
|
||||
}
|
||||
domain {
|
||||
status
|
||||
branch
|
||||
createdAt
|
||||
updatedAt
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,6 +147,14 @@ export const getDeployments = gql`
|
||||
query ($projectId: String!) {
|
||||
deployments(projectId: $projectId) {
|
||||
id
|
||||
domain{
|
||||
branch
|
||||
createdAt
|
||||
id
|
||||
name
|
||||
status
|
||||
updatedAt
|
||||
}
|
||||
branch
|
||||
commitHash
|
||||
commitMessage
|
||||
|
||||
@@ -99,6 +99,7 @@ export type User = {
|
||||
|
||||
export type Deployment = {
|
||||
id: string;
|
||||
domain: Domain;
|
||||
branch: string;
|
||||
commitHash: string;
|
||||
commitMessage: string;
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
# Initial Commit for QWRK UX Changes
|
||||
|
||||
This is the first commit for QWRK UX changes to a fork of the `snowballtools-base` repository in Gitea. This commit sets the foundation for the upcoming user experience improvements and modifications.
|
||||
|
||||
- Repository: `snowballtools-base`
|
||||
- Platform: Gitea
|
||||
- Purpose: QWRK UX changes
|
||||
Reference in new issue
Block a user