-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
113 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/desktop/components/popups/WithdrawFromL2Popup.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<script lang="ts"> | ||
import { closePopup } from '@auxiliary/popup' | ||
import { getSelectedAccount } from '@core/account' | ||
import { localize } from '@core/i18n' | ||
import { getArchivedBaseTokens } from '@core/layer-2/helpers/getArchivedBaseTokens' | ||
import { getBaseToken } from '@core/profile' | ||
import { truncateString } from '@core/utils' | ||
import { formatTokenAmountPrecise } from '@core/wallet' | ||
import { Button, FontWeight, KeyValueBox, Spinner, Text, TextType } from 'shared/components' | ||
import { onMount } from 'svelte' | ||
let address: string | undefined = undefined | ||
let withdrawableAmount: number | undefined = undefined | ||
const isBusy = false | ||
const isWithdrawing = false | ||
function onCancelClick(): void { | ||
closePopup() | ||
} | ||
async function onWithdrawFromL2Click(): Promise<void> { | ||
// todo: implement withdrawing | ||
// await withdrawFunds(address) | ||
} | ||
onMount(async () => { | ||
address = getSelectedAccount().depositAddress | ||
withdrawableAmount = await getArchivedBaseTokens(address) | ||
}) | ||
</script> | ||
|
||
<div class="flex flex-col space-y-6"> | ||
<Text type={TextType.h3} fontWeight={FontWeight.semibold} lineHeight="6"> | ||
{localize('popups.withdrawFromL2.title')} | ||
</Text> | ||
<Text fontSize="15" color="gray-700" classes="text-left">{localize('popups.withdrawFromL2.body')}</Text> | ||
{#if address} | ||
<KeyValueBox | ||
classes="flex items-center w-full py-4" | ||
keyText={truncateString(address, 15, 15)} | ||
valueText={formatTokenAmountPrecise(withdrawableAmount, getBaseToken())} | ||
/> | ||
{:else} | ||
<div class="flex items-center justify-center"> | ||
<Spinner /> | ||
</div> | ||
{/if} | ||
<div class="flex flex-row flex-nowrap w-full space-x-4 mt-6"> | ||
<Button classes="w-full" outline onClick={onCancelClick} disabled={isBusy}> | ||
{localize('actions.cancel')} | ||
</Button> | ||
<Button | ||
classes="w-full" | ||
onClick={onWithdrawFromL2Click} | ||
disabled={isBusy || isWithdrawing || !withdrawableAmount} | ||
{isBusy} | ||
busyMessage={localize('popups.withdrawFromL2.withdrawing')} | ||
> | ||
{localize('popups.withdrawFromL2.withdraw')} | ||
</Button> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/shared/lib/core/layer-2/constants/withdraw.constant.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export const WITHDRAW = 0x9dcc0f41; | ||
export const WITHDRAW = 0x9dcc0f41 |
24 changes: 13 additions & 11 deletions
24
packages/shared/lib/core/layer-2/helpers/getArchivedBaseTokens.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
const URL = | ||
"https://archive.evm.shimmer.shimmer.network/v1/chains/smr1prxvwqvwf7nru5q5xvh5thwg54zsm2y4wfnk6yk56hj3exxkg92mx20wl3s/core/accounts/account/{address}/balance"; | ||
import { get } from 'svelte/store' | ||
import { activeProfile } from '@core/profile' | ||
import { DEFAULT_CHAIN_CONFIGURATIONS } from '@core/network' | ||
|
||
interface Response { | ||
baseTokens: number; | ||
baseTokens: number | ||
} | ||
|
||
export async function getArchivedBaseTokens(address: string): Promise<number> { | ||
const url = URL.replace("{address}", address); | ||
try { | ||
const res: Response = await fetch(url) | ||
.then((r) => r.json()); | ||
const defaultChainConfig = DEFAULT_CHAIN_CONFIGURATIONS[get(activeProfile)?.network?.id] | ||
const URL = `${defaultChainConfig?.archiveEndpoint}/core/accounts/account/${address}/balance` | ||
|
||
return res.baseTokens; | ||
} catch (_) { | ||
return 0; | ||
} | ||
try { | ||
const res: Response = await fetch(URL).then((r) => r.json()) | ||
|
||
return res.baseTokens | ||
} catch (_) { | ||
return 0 | ||
} | ||
} |
26 changes: 14 additions & 12 deletions
26
packages/shared/lib/core/layer-2/helpers/widthdrawL2Funds.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
const URL = | ||
"https://archive.evm.shimmer.shimmer.network/v1/chains/smr1prxvwqvwf7nru5q5xvh5thwg54zsm2y4wfnk6yk56hj3exxkg92mx20wl3s/core/accounts/account/{address}/balance"; | ||
import { get } from 'svelte/store' | ||
import { activeProfile } from '@core/profile' | ||
import { DEFAULT_CHAIN_CONFIGURATIONS } from '@core/network' | ||
|
||
interface Response { | ||
baseTokens: number; | ||
baseTokens: number | ||
} | ||
|
||
export async function withdrawFunds(address: string): Promise<number> { | ||
const defaultChainConfig = DEFAULT_CHAIN_CONFIGURATIONS[get(activeProfile)?.network?.id] | ||
// todo: change to withdraw endpoint | ||
const URL = `${defaultChainConfig?.archiveEndpoint}/core/accounts/account/${address}/balance` | ||
|
||
export async function withdrawFunds(address: string) { | ||
const url = URL.replace("{address}", address); | ||
try { | ||
const res: Response = await fetch(url) | ||
.then((r) => r.json()); | ||
try { | ||
const res: Response = await fetch(URL).then((r) => r.json()) | ||
|
||
return res.baseTokens; | ||
} catch (_) { | ||
return 0; | ||
} | ||
return res.baseTokens | ||
} catch (_) { | ||
return 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters