Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(share): add share functionality for backup seed phrase on mobile #942

Merged
merged 6 commits into from
Dec 17, 2024
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
1 change: 1 addition & 0 deletions android/app/capacitor.build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies {
implementation project(':capacitor-filesystem')
implementation project(':capacitor-keyboard')
implementation project(':capacitor-screen-orientation')
implementation project(':capacitor-share')
implementation project(':capacitor-splash-screen')
implementation project(':capacitor-status-bar')
}
Expand Down
3 changes: 3 additions & 0 deletions android/capacitor.settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ project(':capacitor-keyboard').projectDir = new File('../node_modules/@capacitor
include ':capacitor-screen-orientation'
project(':capacitor-screen-orientation').projectDir = new File('../node_modules/@capacitor/screen-orientation/android')

include ':capacitor-share'
project(':capacitor-share').projectDir = new File('../node_modules/@capacitor/share/android')

include ':capacitor-splash-screen'
project(':capacitor-splash-screen').projectDir = new File('../node_modules/@capacitor/splash-screen/android')

Expand Down
1 change: 1 addition & 0 deletions ios/App/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def capacitor_pods
pod 'CapacitorFilesystem', :path => '../../node_modules/@capacitor/filesystem'
pod 'CapacitorKeyboard', :path => '../../node_modules/@capacitor/keyboard'
pod 'CapacitorScreenOrientation', :path => '../../node_modules/@capacitor/screen-orientation'
pod 'CapacitorShare', :path => '../../node_modules/@capacitor/share'
pod 'CapacitorSplashScreen', :path => '../../node_modules/@capacitor/splash-screen'
pod 'CapacitorStatusBar', :path => '../../node_modules/@capacitor/status-bar'
end
Expand Down
8 changes: 7 additions & 1 deletion ios/App/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ PODS:
- Capacitor
- CapacitorScreenOrientation (6.0.3):
- Capacitor
- CapacitorShare (6.0.3):
- Capacitor
- CapacitorSplashScreen (6.0.3):
- Capacitor
- CapacitorStatusBar (6.0.2):
Expand All @@ -28,6 +30,7 @@ DEPENDENCIES:
- "CapacitorFilesystem (from `../../node_modules/@capacitor/filesystem`)"
- "CapacitorKeyboard (from `../../node_modules/@capacitor/keyboard`)"
- "CapacitorScreenOrientation (from `../../node_modules/@capacitor/screen-orientation`)"
- "CapacitorShare (from `../../node_modules/@capacitor/share`)"
- "CapacitorSplashScreen (from `../../node_modules/@capacitor/splash-screen`)"
- "CapacitorStatusBar (from `../../node_modules/@capacitor/status-bar`)"

Expand All @@ -48,6 +51,8 @@ EXTERNAL SOURCES:
:path: "../../node_modules/@capacitor/keyboard"
CapacitorScreenOrientation:
:path: "../../node_modules/@capacitor/screen-orientation"
CapacitorShare:
:path: "../../node_modules/@capacitor/share"
CapacitorSplashScreen:
:path: "../../node_modules/@capacitor/splash-screen"
CapacitorStatusBar:
Expand All @@ -62,9 +67,10 @@ SPEC CHECKSUMS:
CapacitorFilesystem: c832a3f6d4870c3872688e782ae8e33665e6ecbf
CapacitorKeyboard: 460c6f9ec5e52c84f2742d5ce2e67bbc7ab0ebb0
CapacitorScreenOrientation: 3bb823f5d265190301cdc5d58a568a287d98972a
CapacitorShare: 7af6ca761ce62030e8e9fbd2eb82416f5ceced38
CapacitorSplashScreen: 68893659d77b5f82d753b3a70475082845e3039c
CapacitorStatusBar: 3b9ac7d0684770522c532d1158a1434512ab1477

PODFILE CHECKSUM: 97c46b79f9ec807c302bf24e1511e3e277306740
PODFILE CHECKSUM: cecd7e9afdf00b54ffac291bfc0edab8a2ebdc11

COCOAPODS: 1.16.2
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"@capacitor/ios": "^6.2.0",
"@capacitor/keyboard": "^6.0.3",
"@capacitor/screen-orientation": "^6.0.3",
"@capacitor/splash-screen": "^6.0.2",
"@capacitor/share": "^6.0.3",
"@capacitor/splash-screen": "^6.0.3",
"@capacitor/status-bar": "^6.0.2",
"@dicebear/collection": "^9.0.1",
"@dicebear/core": "^9.0.1",
Expand Down
1 change: 1 addition & 0 deletions src/lib/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@
"title": "Backup your seed!",
"save_warning": "Please ensure you write down this message with all words recorded in the order they appear. It can be helpful to write down the numbers along with the words.",
"download": "Download Backup",
"share": "Share Backup Seed Phrase",
"next_step": "Next Step"
},
"new_account": {
Expand Down
27 changes: 24 additions & 3 deletions src/lib/layouts/login/RecoveryCopy.svelte
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
<script lang="ts">
import { goto } from "$app/navigation"
import { OrderedPhrase } from "$lib/components"
import Controls from "$lib/layouts/Controls.svelte"
import { Button, Icon, Text, Title } from "$lib/elements"
import { Appearance, Route, Shape } from "$lib/enums"
import { Appearance, Shape } from "$lib/enums"

import { _ } from "svelte-i18n"
import { createEventDispatcher } from "svelte"
import { TesseractStoreInstance } from "$lib/wasm/TesseractStore"
import { isAndroidOriOS } from "$lib/utils/Mobile"
import { Share } from "@capacitor/share"
import { log } from "$lib/utils/Logger"

const dispatch = createEventDispatcher()

let phrase = TesseractStoreInstance.fetchSeed()?.split(" ")
let loading = false

// Function to handle downloading the seed phrase as a txt file
function downloadPhrase() {
async function downloadPhrase() {
if (!phrase) return

// Join the phrase array into a single string
const phraseText = phrase.join(" ")

if (isAndroidOriOS()) {
await sharePhraseIfMobile(phraseText)
return
}

const blob = new Blob([phraseText], { type: "text/plain" })

const link = document.createElement("a")
Expand All @@ -31,6 +38,20 @@

URL.revokeObjectURL(link.href)
}

async function sharePhraseIfMobile(phraseText: string) {
try {
await Share.share({
title: $_("pages.auth.recovery.title"),
text: phraseText,
dialogTitle: $_("pages.auth.recovery.share"),
})

log.info("Seed phrase shared successfully")
} catch (error) {
log.error("Error to share seed phrase:", error)
}
}
</script>

<div id="auth-recover">
Expand Down
Loading