2021-11-21 00:12:24 +02:00
< script >
import OrangeButton from "./OrangeButton.svelte";
import CardBG from "./CardBG.svelte";
import InputField from "./InputField.svelte";
2021-12-30 01:45:14 +02:00
import { createEventDispatcher , onMount } from 'svelte';
2021-11-22 00:33:30 +02:00
import Icon from "@iconify/svelte";
import Overlay from "./Overlay.svelte";
import { fade , fly , slide } from 'svelte/transition';
import { flip } from 'svelte/animate';
2021-12-30 01:45:14 +02:00
import { createaccount , getcurrencies , getaccounttypes } from "./api";
import { getContext } from "svelte";
2021-11-21 00:12:24 +02:00
2021-12-30 01:45:14 +02:00
const token = getContext("token");
2022-01-04 01:22:27 +02:00
const refreshAccounts = getContext("refreshAccounts");
2021-11-21 00:12:24 +02:00
const dispatch = createEventDispatcher();
2021-12-30 01:45:14 +02:00
let type = null;
let name = "";
let currency = null;
2021-11-21 00:12:24 +02:00
let termsAccepted = false;
2021-12-30 01:45:14 +02:00
$: placeholder = type==null ? "Checking Account" : `${ type } Account`;
2021-11-21 00:12:24 +02:00
2021-12-30 01:45:14 +02:00
async function create(){
2022-01-03 14:25:32 +02:00
if(type == null){
2021-12-30 01:45:14 +02:00
alert("Type is not selected!");
}else if(currency == null){
alert("Currency is not selected!");
2021-11-21 00:12:24 +02:00
}else if (!termsAccepted){
alert("Terms of Service not accepted!");
}else{
2021-12-30 01:45:14 +02:00
const result = await createaccount($token, name, currency, type);
if(result.status == "success") {
2022-01-03 14:25:32 +02:00
dispatch("createPopup",{ type : "create_acc_success" } );
2022-01-04 01:22:27 +02:00
if($refreshAccounts){
$refreshAccounts();
}
2021-12-30 01:45:14 +02:00
}else{
dispatch("createPopup",{ type : "create_acc_failed" , reason : "Failed to create account. Error:" + result . status } );
}
2021-11-21 00:12:24 +02:00
}
}
function cancelCreate(){
dispatch("createPopup",{ type : "create_acc_cancelled" } );
}
function failCreate(){
dispatch("createPopup",{ type : "create_acc_failed" , reason : "Invalid arguments. [type: " + type + ", currency: " + currency } );
}
function termsOfService() {
termsAccepted = !termsAccepted;
}
2021-12-30 01:45:14 +02:00
onMount(() => {
getcurrencies().then(result => currency = result.currencies[0]);
getaccounttypes().then(result => type = result.accountTypes[0]);
})
2021-11-21 00:12:24 +02:00
< / script >
2021-11-22 00:33:30 +02:00
< div class = "h-full self-center" in:fade = {{ duration :300 }} out:fade= {{ duration :300 }} >
< div class = "h-full flex flex-col justify-center items-center md:items-start" >
< CardBG padding = { false } class="flex flex-col items-stretch " >
< div class = "m-3" >
< div class = "flex flex-row" >
< h1 class = 'font-sans text-4xl text-gray-50 mt-6 mx-6 mb-1' > Open a new account< / h1 >
< button class = "ml-auto mr-6" on:click = { cancelCreate } > <Icon icon = "akar-icons:cross" color = "rgba(249, 250, 251, 1)" width = "32" height = "32" /> </ button >
< / div >
< div class = "w-full max-w-md self-start border-solid border-gray-50 border mb-3" > < / div >
2021-11-21 00:12:24 +02:00
2021-11-22 00:33:30 +02:00
< div class = "mx-1 flex-shrink" >
< h2 class = 'font-sans text-2xl text-gray-50 mb-2 ' > Account name:< / h2 >
2021-12-30 01:45:14 +02:00
< InputField placeholder = { placeholder } isPassword= { false } bind:value = { name } > </InputField >
< / div >
< div class = "mx-1 flex-shrink" >
< h2 class = 'font-sans text-2xl text-gray-50 mb-2 ' > Type:< / h2 >
< select bind:value = { type } >
{ #await getaccounttypes () then result }
{ #each result . accountTypes as option }
< option class = "custom-option" value = { option } > { option } </option >
{ /each }
{ /await }
< / select >
2021-11-22 00:33:30 +02:00
< / div >
< div class = "mx-1 flex-shrink" >
< h2 class = 'font-sans text-2xl text-gray-50 mb-2 ' > Currency:< / h2 >
2021-12-08 16:21:06 +02:00
< select bind:value = { currency } >
2021-12-30 01:45:14 +02:00
{ #await getcurrencies () then result }
{ #each result . currencies as option }
< option class = "custom-option" value = { option } > { option } </option >
{ /each }
{ /await }
2021-12-08 16:21:06 +02:00
< / select >
2021-11-22 00:33:30 +02:00
< / div >
2021-11-21 00:12:24 +02:00
2021-11-22 00:33:30 +02:00
< div class = "mx-1 flex-shrink max-w-2xl" >
< h2 class = " font-sans text-2xl text-gray-50 mb-2 " > Terms of Service:< / h2 >
< button class = "mb-1" on:click = { termsOfService } > <Icon icon = { termsAccepted ? "akar-icons:check-box" : "akar-icons:box" } color="rgba(249, 250 , 251 , 1 )" width = "18" height = "18" /> </ button >
< h3 class = "inline m-0 mb-0 text-gray-300" > I have read and accepted the < a class = "font-sans text-gray-50" href = "https://c.tenor.com/TVRtbC8jKY0AAAAC/positive-fox-you-can-do-it.gif" target = "_blank" > terms and conditions< / a > for creating a new account at FOXBANK. < / h3 >
< / div >
< div class = "m-10" > < / div >
< / div >
< div class = "flex-shrink flex flex-row mb-4" style = "background: linear-gradient(89.1deg, rgba(236, 98, 68, 0.95) 0.77%, rgba(236, 98, 68, 0) 99.12%);" >
< div class = "flex-1" > < / div >
< OrangeButton class = "flex-1 m-4" on:click = { create } > Confirm</OrangeButton >
< / div >
< / CardBG >
< / div >
2021-11-21 00:12:24 +02:00
< / div >
2021-12-08 16:21:06 +02:00
< style >
select{
min-width: 120px;
min-height: 32px;
color: rgba(233, 231, 231, 0.842);
background: linear-gradient(92.55deg, rgba(76, 172, 135, 0.95) -28.27%, rgba(249, 224, 127, 0.096) 115.79%);
filter: drop-shadow(0px 8px 4px rgba(0, 0, 0, 0.25));
border-radius: 3px;
}
select option{
min-width: 120px;
min-height: 32px;
color: rgba(233, 231, 231, 0.842);
background: linear-gradient(92.55deg, rgba(76, 172, 135, 0.95) -28.27%, rgba(249, 224, 127, 0.096) 115.79%);
filter: drop-shadow(0px 8px 4px rgba(0, 0, 0, 0.25));
border-radius: 3px;
}
< / style >