-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OK-9286 OK-9149 OK-9126 OK-9099 improve scanqrcode (#825)
* refactor: gotoScanQrcode * feat: add incomingurl for discover * feat: add haptics for image pick button * chore: update svg scan area * chore: update deps * fix: lint error * feat: preview send page (wip) * feat: pass address to send * style: previewsend * feat: pass address to send * fix: lint error * fix: lint error
- Loading branch information
Showing
24 changed files
with
535 additions
and
475 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import * as ImagePicker from 'expo-image-picker'; | ||
|
||
import { UserCreateInputCategory } from '@onekeyhq/engine/src/types/credential'; | ||
import platformEnv from '@onekeyhq/shared/src/platformEnv'; | ||
|
||
import backgroundApiProxy from '../background/instance/backgroundApiProxy'; | ||
import { getAppNavigation } from '../hooks/useAppNavigation'; | ||
import { ModalRoutes, RootRoutes } from '../routes/types'; | ||
import { scanFromURLAsync } from '../views/ScanQrcode/scanFromURLAsync'; | ||
import { ScanQrcodeRoutes, ScanResult } from '../views/ScanQrcode/types'; | ||
|
||
export const handleScanResult = async (data: string) => { | ||
const scanResult: ScanResult = { type: 'other', data }; | ||
if (data.startsWith('https://') || data.startsWith('http://')) { | ||
scanResult.type = 'url'; | ||
} else if (/^wc:.+@.+\?.+/.test(data)) { | ||
// wc:{topic...}@{version...}?bridge={url...}&key={key...} | ||
// https://docs.walletconnect.com/tech-spec | ||
await backgroundApiProxy.walletConnect.connect({ | ||
uri: data, | ||
}); | ||
return; | ||
} else { | ||
const { category, possibleNetworks } = | ||
await backgroundApiProxy.validator.validateCreateInput(data); | ||
if (category === UserCreateInputCategory.ADDRESS) { | ||
scanResult.type = 'address'; | ||
scanResult.possibleNetworks = possibleNetworks; | ||
} | ||
} | ||
return scanResult; | ||
}; | ||
|
||
export const gotoScanQrcode = async ( | ||
onScanCompleted?: (data: string) => void, | ||
) => { | ||
const navigation = getAppNavigation(); | ||
if (platformEnv.isNative) { | ||
navigation.navigate(RootRoutes.Modal, { | ||
screen: ModalRoutes.ScanQrcode, | ||
params: { | ||
screen: ScanQrcodeRoutes.ScanQrcode, | ||
params: onScanCompleted | ||
? { | ||
onScanCompleted, | ||
} | ||
: undefined, | ||
}, | ||
}); | ||
} else { | ||
const result = await ImagePicker.launchImageLibraryAsync({ | ||
base64: true, | ||
allowsMultipleSelection: false, | ||
}); | ||
|
||
if (!result.cancelled) { | ||
const data = await scanFromURLAsync(result.uri); | ||
if (data) { | ||
if (onScanCompleted) { | ||
onScanCompleted(data); | ||
return; | ||
} | ||
const scanResult = await handleScanResult(data); | ||
if (scanResult) { | ||
navigation.navigate(RootRoutes.Modal, { | ||
screen: ModalRoutes.ScanQrcode, | ||
params: { | ||
screen: ScanQrcodeRoutes.ScanQrcodeResult, | ||
params: scanResult, | ||
}, | ||
}); | ||
} | ||
} else { | ||
// TODO invalid qrcode | ||
} | ||
} | ||
} | ||
}; |
Oops, something went wrong.