Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion scripts/update.types.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,47 @@ const cleanTypes = async ({ dest = `./src/declarations` }) => {
''
);

await writeFile(indexPath, clean, 'utf-8');
const valid = clean.replace(/export const idlFactory = \({ IDL }\) => {/g, '');

await writeFile(indexPath, valid, 'utf-8');

resolve();
})
);

await Promise.all(promises);
};

/**
* We have to manipulate the factory otherwise the editor prompt for following TypeScript error:
*
* TS7031: Binding element 'IDL' implicitly has an 'any' type.
*
*/
const cleanFactory = async ({ dest = `./src/declarations` }) => {
const promises = readdirSync(dest).map(
(dir) =>
new Promise(async (resolve) => {
const factoryPath = join(dest, dir, `${dir}.did.js`);

if (!existsSync(factoryPath)) {
resolve();
return;
}

const content = await readFile(factoryPath, 'utf-8');
const cleanFactory = content.replace(
/export const idlFactory = \({ IDL }\) => {/g,
`// @ts-ignore
export const idlFactory = ({ IDL }) => {`
);
const cleanInit = cleanFactory.replace(
/export const init = \({ IDL }\) => {/g,
`// @ts-ignore
export const init = ({ IDL }) => {`
);

await writeFile(factoryPath, cleanInit, 'utf-8');

resolve();
})
Expand Down Expand Up @@ -58,6 +98,8 @@ const renameFactory = async ({ dest = `./src/declarations` }) => {
try {
await cleanTypes({});

await cleanFactory({});

await renameFactory({});

console.log(`Types declarations copied!`);
Expand Down
2 changes: 1 addition & 1 deletion src/console/console.did
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ service : {
get_credits : () -> (Tokens) query;
get_releases_version : () -> (ReleasesVersion) query;
get_user_mission_control_center : () -> (opt MissionControl) query;
init_user_mission_control_center : (opt text) -> (MissionControl);
init_user_mission_control_center : () -> (MissionControl);
list_user_mission_control_centers : () -> (
vec record { principal; MissionControl },
) query;
Expand Down
4 changes: 2 additions & 2 deletions src/console/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ fn list_user_mission_control_centers() -> MissionControls {

#[candid_method(update)]
#[update]
async fn init_user_mission_control_center(invitation_code: Option<String>) -> MissionControl {
async fn init_user_mission_control_center() -> MissionControl {
let caller = caller();
let console = id();

init_user_mission_control(&console, &caller, &invitation_code)
init_user_mission_control(&console, &caller)
.await
.unwrap_or_else(|e| trap(&e))
}
Expand Down
16 changes: 5 additions & 11 deletions src/console/src/mission_control.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::controllers::update_mission_control_controllers;
use crate::store::{
add_mission_control, delete_mission_control, get_mission_control,
increment_mission_controls_rate, init_empty_mission_control, redeem_invitation_code,
increment_mission_controls_rate, init_empty_mission_control,
};
use crate::types::state::MissionControl;
use crate::wasm::mission_control_wasm_arg;
Expand All @@ -13,23 +13,17 @@ use shared::types::state::UserId;
pub async fn init_user_mission_control(
console: &Principal,
caller: &Principal,
invitation_code: &Option<String>,
) -> Result<MissionControl, String> {
let result = get_mission_control(caller);
match result {
Err(error) => Err(error.to_string()),
Ok(mission_control) => match mission_control {
Some(mission_control) => Ok(mission_control),
None => match invitation_code {
None => Err("No invitation code provided.".to_string()),
Some(invitation_code) => {
// Guard too many requests
increment_mission_controls_rate()?;
None => {
// Guard too many requests
increment_mission_controls_rate()?;

redeem_invitation_code(caller, invitation_code)?;

create_mission_control(caller, console).await
}
create_mission_control(caller, console).await
},
},
}
Expand Down
2 changes: 2 additions & 0 deletions src/declarations/cmc/cmc.factory.did.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-ignore
export const idlFactory = ({ IDL }) => {
const BlockIndex = IDL.Nat64;
const CyclesCanisterInitPayload = IDL.Record({
Expand Down Expand Up @@ -53,6 +54,7 @@ export const idlFactory = ({ IDL }) => {
notify_top_up: IDL.Func([NotifyTopUpArg], [NotifyTopUpResult], [])
});
};
// @ts-ignore
export const init = ({ IDL }) => {
const BlockIndex = IDL.Nat64;
const CyclesCanisterInitPayload = IDL.Record({
Expand Down
2 changes: 1 addition & 1 deletion src/declarations/console/console.did.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export interface _SERVICE {
get_credits: ActorMethod<[], Tokens>;
get_releases_version: ActorMethod<[], ReleasesVersion>;
get_user_mission_control_center: ActorMethod<[], [] | [MissionControl]>;
init_user_mission_control_center: ActorMethod<[[] | [string]], MissionControl>;
init_user_mission_control_center: ActorMethod<[], MissionControl>;
list_user_mission_control_centers: ActorMethod<[], Array<[Principal, MissionControl]>>;
load_release: ActorMethod<[Segment, Uint8Array | number[], string], LoadRelease>;
reset_release: ActorMethod<[Segment], undefined>;
Expand Down
4 changes: 3 additions & 1 deletion src/declarations/console/console.factory.did.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-ignore
export const idlFactory = ({ IDL }) => {
const AssertMissionControlCenterArgs = IDL.Record({
mission_control_id: IDL.Principal,
Expand Down Expand Up @@ -49,7 +50,7 @@ export const idlFactory = ({ IDL }) => {
get_credits: IDL.Func([], [Tokens], ['query']),
get_releases_version: IDL.Func([], [ReleasesVersion], ['query']),
get_user_mission_control_center: IDL.Func([], [IDL.Opt(MissionControl)], ['query']),
init_user_mission_control_center: IDL.Func([IDL.Opt(IDL.Text)], [MissionControl], []),
init_user_mission_control_center: IDL.Func([], [MissionControl], []),
list_user_mission_control_centers: IDL.Func(
[],
[IDL.Vec(IDL.Tuple(IDL.Principal, MissionControl))],
Expand All @@ -62,6 +63,7 @@ export const idlFactory = ({ IDL }) => {
version: IDL.Func([], [IDL.Text], ['query'])
});
};
// @ts-ignore
export const init = ({ IDL }) => {
return [];
};
4 changes: 3 additions & 1 deletion src/declarations/console/console.factory.did.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-ignore
export const idlFactory = ({ IDL }) => {
const AssertMissionControlCenterArgs = IDL.Record({
mission_control_id: IDL.Principal,
Expand Down Expand Up @@ -49,7 +50,7 @@ export const idlFactory = ({ IDL }) => {
get_credits: IDL.Func([], [Tokens], ['query']),
get_releases_version: IDL.Func([], [ReleasesVersion], ['query']),
get_user_mission_control_center: IDL.Func([], [IDL.Opt(MissionControl)], ['query']),
init_user_mission_control_center: IDL.Func([IDL.Opt(IDL.Text)], [MissionControl], []),
init_user_mission_control_center: IDL.Func([], [MissionControl], []),
list_user_mission_control_centers: IDL.Func(
[],
[IDL.Vec(IDL.Tuple(IDL.Principal, MissionControl))],
Expand All @@ -62,6 +63,7 @@ export const idlFactory = ({ IDL }) => {
version: IDL.Func([], [IDL.Text], ['query'])
});
};
// @ts-ignore
export const init = ({ IDL }) => {
return [];
};
2 changes: 2 additions & 0 deletions src/declarations/frontend/frontend.factory.did.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-ignore
export const idlFactory = ({ IDL }) => {
const ClearArguments = IDL.Record({});
const BatchId = IDL.Nat;
Expand Down Expand Up @@ -203,6 +204,7 @@ export const idlFactory = ({ IDL }) => {
validate_revoke_permission: IDL.Func([RevokePermission], [ValidationResult], [])
});
};
// @ts-ignore
export const init = ({ IDL }) => {
return [];
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-ignore
export const idlFactory = ({ IDL }) => {
const ArchiveConfig = IDL.Record({
polling_interval_ns: IDL.Nat64,
Expand Down Expand Up @@ -212,6 +213,7 @@ export const idlFactory = ({ IDL }) => {
verify_tentative_device: IDL.Func([UserNumber, IDL.Text], [VerifyTentativeDeviceResponse], [])
});
};
// @ts-ignore
export const init = ({ IDL }) => {
const ArchiveConfig = IDL.Record({
polling_interval_ns: IDL.Nat64,
Expand Down
2 changes: 2 additions & 0 deletions src/declarations/ledger/ledger.factory.did.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-ignore
export const idlFactory = ({ IDL }) => {
const AccountIdentifier = IDL.Vec(IDL.Nat8);
const AccountBalanceArgs = IDL.Record({ account: AccountIdentifier });
Expand Down Expand Up @@ -93,6 +94,7 @@ export const idlFactory = ({ IDL }) => {
transfer_fee: IDL.Func([TransferFeeArg], [TransferFee], ['query'])
});
};
// @ts-ignore
export const init = ({ IDL }) => {
return [];
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-ignore
export const idlFactory = ({ IDL }) => {
const Satellite = IDL.Record({
updated_at: IDL.Nat64,
Expand Down Expand Up @@ -92,6 +93,7 @@ export const idlFactory = ({ IDL }) => {
version: IDL.Func([], [IDL.Text], ['query'])
});
};
// @ts-ignore
export const init = ({ IDL }) => {
return [];
};
2 changes: 2 additions & 0 deletions src/declarations/observatory/observatory.factory.did.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-ignore
export const idlFactory = ({ IDL }) => {
const DeleteControllersArgs = IDL.Record({
controllers: IDL.Vec(IDL.Principal)
Expand Down Expand Up @@ -83,6 +84,7 @@ export const idlFactory = ({ IDL }) => {
version: IDL.Func([], [IDL.Text], ['query'])
});
};
// @ts-ignore
export const init = ({ IDL }) => {
return [];
};
2 changes: 2 additions & 0 deletions src/declarations/observatory/observatory.factory.did.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-ignore
export const idlFactory = ({ IDL }) => {
const DeleteControllersArgs = IDL.Record({
controllers: IDL.Vec(IDL.Principal)
Expand Down Expand Up @@ -83,6 +84,7 @@ export const idlFactory = ({ IDL }) => {
version: IDL.Func([], [IDL.Text], ['query'])
});
};
// @ts-ignore
export const init = ({ IDL }) => {
return [];
};
2 changes: 2 additions & 0 deletions src/declarations/satellite/satellite.factory.did.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-ignore
export const idlFactory = ({ IDL }) => {
const CommitBatch = IDL.Record({
batch_id: IDL.Nat,
Expand Down Expand Up @@ -187,6 +188,7 @@ export const idlFactory = ({ IDL }) => {
version: IDL.Func([], [IDL.Text], ['query'])
});
};
// @ts-ignore
export const init = ({ IDL }) => {
return [];
};
2 changes: 2 additions & 0 deletions src/declarations/satellite/satellite.factory.did.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-ignore
export const idlFactory = ({ IDL }) => {
const CommitBatch = IDL.Record({
batch_id: IDL.Nat,
Expand Down Expand Up @@ -187,6 +188,7 @@ export const idlFactory = ({ IDL }) => {
version: IDL.Func([], [IDL.Text], ['query'])
});
};
// @ts-ignore
export const init = ({ IDL }) => {
return [];
};
7 changes: 2 additions & 5 deletions src/frontend/src/lib/api/mission-control.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,22 @@ import { Principal } from '@dfinity/principal';

export const initMissionControl = async ({
identity,
invitationCode,
onInitMissionControlSuccess
}: {
identity: Identity;
invitationCode: string | undefined | null;
onInitMissionControlSuccess: (missionControlId: Principal) => Promise<void>;
}) =>
// eslint-disable-next-line no-async-promise-executor
new Promise<void>(async (resolve, reject) => {
try {
const { actor, missionControlId } = await getMissionControl({
identity,
invitationCode
identity
});

if (!actor || !missionControlId) {
setTimeout(async () => {
try {
await initMissionControl({ identity, invitationCode, onInitMissionControlSuccess });
await initMissionControl({ identity, onInitMissionControlSuccess });
resolve();
} catch (err: unknown) {
reject(err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,33 @@
</script>

<p class="sign-in-now">
<slot />Sign-in now on
Juno uses
<button
class="text action"
on:click={async () => await doSignIn('internetcomputer.org')}
disabled={$isBusy}>internetcomputer.org</button
>
(or
> by default.
</p>

<p>
You can also sign-in for now with deprecated method
<button class="text action" on:click={async () => await doSignIn('ic0.app')} disabled={$isBusy}
>ic0.app</button
>).
>.
</p>

<style lang="scss">
.sign-in-now {
margin: 0;
margin: var(--padding-12x) 0 0;
}

.action {
margin: 0;
}

p {
font-size: var(--font-size-ultra-small);
margin: 0;
padding: 0 0 var(--padding-0_25x);
}
</style>
Loading