-
Notifications
You must be signed in to change notification settings - Fork 6
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
1 parent
0bb9b4d
commit 04b2ddb
Showing
38 changed files
with
726 additions
and
192 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,6 @@ dist | |
dist-* | ||
.yarn | ||
.DS_Store | ||
yarn-error | ||
yarn-error | ||
|
||
tmp |
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,26 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
const appRoot = fs.realpathSync(process.cwd()); | ||
const appRoot = fs.realpathSync(path.resolve(__dirname, '..')); | ||
|
||
const desktopRepo = process.env.RABBY_DESKTOP_REPO || path.join(appRoot, '../RabbyDesktop'); | ||
if (!fs.existsSync(desktopRepo)) { | ||
console.log('RabbyDesktop repo not found at ' + desktopRepo); | ||
desktopRepo = null; | ||
} else { | ||
console.log('Using RabbyDesktop repo at ' + desktopRepo); | ||
}; | ||
|
||
const rootResolve = path.resolve.bind(path, appRoot); | ||
|
||
module.exports = { | ||
root: appRoot, | ||
src: rootResolve('src'), | ||
popupHtml: rootResolve('src/ui/popup.html'), | ||
popupHtml: rootResolve('src/ui/popup.ejs'), | ||
notificationHtml: rootResolve('src/ui/notification.html'), | ||
indexHtml: rootResolve('src/ui/index.html'), | ||
backgroundHtml: rootResolve('src/background/background.html'), | ||
dist: rootResolve('dist'), | ||
dist: desktopRepo ? path.resolve(desktopRepo, './assets/chrome_exts/rabby') : rootResolve('dist'), | ||
|
||
rootResolve, | ||
} |
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,11 @@ | ||
script_dir="$( cd "$( dirname "$0" )" && pwd )" | ||
project_dir=$(dirname "$script_dir") | ||
|
||
if [ -z $RABBY_DESKTOP_REPO ]; then | ||
export RABBY_DESKTOP_REPO=$( cd "$project_dir/../RabbyDesktop" && pwd ) | ||
echo "[clean-assets] RABBY_DESKTOP_REPO is not set, use default: $RABBY_DESKTOP_REPO" | ||
else | ||
echo "[clean-assets] RABBY_DESKTOP_REPO is set to: $RABBY_DESKTOP_REPO" | ||
fi | ||
|
||
mkdir -p $RABBY_DESKTOP_REPO/assets/chrome_exts/rabby && rm -rf $RABBY_DESKTOP_REPO/assets/chrome_exts/rabby/* && cp -r _raw/* $RABBY_DESKTOP_REPO/assets/chrome_exts/rabby |
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,43 @@ | ||
#!/usr/bin/env sh | ||
|
||
script_dir="$( cd "$( dirname "$0" )" && pwd )" | ||
project_dir=$(dirname "$script_dir") | ||
|
||
RABBY_DESKTOP_REPO=$( cd "$project_dir/../RabbyDesktop" && pwd ) | ||
|
||
export VERSION=0.60.1; | ||
export RABBYX_GIT_HASH=$(git rev-parse --short HEAD); | ||
|
||
TARGET_FILE=$project_dir/tmp/RabbyX-v${VERSION}-${RABBYX_GIT_HASH}.zip; | ||
|
||
echo "[pack] RABBY_DESKTOP_REPO is $RABBY_DESKTOP_REPO"; | ||
|
||
# for windows, download zip.exe from http://stahlworks.com/dev/index.php?tool=zipunzip and add to your path | ||
|
||
# rm -rf $RABBY_DESKTOP_REPO/assets/chrome_exts/rabby; | ||
if [ -z $NO_BUILD ]; then | ||
yarn build:pro; | ||
fi | ||
echo "[pack] built finished"; | ||
|
||
cd $RABBY_DESKTOP_REPO/assets/chrome_exts/rabby; | ||
|
||
rm -rf $project_dir/tmp/ && mkdir -p $project_dir/tmp/ && \ | ||
zip -r $TARGET_FILE ./* | ||
|
||
cd $project_dir; | ||
cp $TARGET_FILE $project_dir/tmp/RabbyX-latest.zip | ||
|
||
# upload to storage | ||
if [ -z $NO_UPLOAD ]; then | ||
aws s3 cp $project_dir/tmp/ s3://$RABBY_BUILD_BUCKET/rabby/_tools/ --recursive --exclude="*" --include "*.zip" --acl public-read | ||
aws cloudfront create-invalidation --distribution-id E1F7UQCCQWLXXZ --paths '/_tools/*.zip' | ||
echo "[pack] uploaded."; | ||
fi | ||
|
||
# cp to RabbyDesktop | ||
rm -rf $RABBY_DESKTOP_REPO/release/rabbyx/ && mkdir -p $RABBY_DESKTOP_REPO/release/rabbyx/; | ||
cp $TARGET_FILE $RABBY_DESKTOP_REPO/release/rabbyx/ | ||
cp $TARGET_FILE $RABBY_DESKTOP_REPO/release/rabbyx/RabbyX-latest.zip | ||
|
||
echo "[pack] finished."; |
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,2 +1,4 @@ | ||
export { default as providerController } from './provider'; | ||
export { default as walletController } from './wallet'; | ||
|
||
import './wallet-bridge'; |
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,140 @@ | ||
import walletController from "./wallet"; | ||
|
||
type LooseErrorObj = { | ||
code?: string; | ||
message?: string; | ||
stack?: string; | ||
} | ||
async function runAndCatchErr<T = any>(proc: Function, mark?: string): Promise<{ | ||
result: T | null | ||
error?: LooseErrorObj | ||
}> { | ||
try { | ||
console.debug('[debug] runAndCatchErr:: mark', mark); | ||
const result = await proc(); | ||
// console.debug('[debug] runAndCatchErr:: result', result); | ||
|
||
return { | ||
result: result | ||
}; | ||
} catch (err) { | ||
console.error(err) | ||
|
||
return { | ||
result: null, | ||
error: { | ||
code: (err as any).code, | ||
message: err.message, | ||
stack: err.stack, | ||
} | ||
}; | ||
} | ||
} | ||
|
||
type BridgePayload = { | ||
rpcId: string | ||
method: string | ||
params: any[] | ||
} | ||
|
||
async function onRabbyxRpcQuery (payload: BridgePayload) { | ||
if (!payload.rpcId) { | ||
throw new Error('[rabbyx-rpc-query] rpcId is required'); | ||
} | ||
|
||
let retPayload = { | ||
result: null, | ||
error: null | ||
} as any; | ||
|
||
switch (payload.method) { | ||
case 'walletController.boot': { | ||
const [password] = payload.params; | ||
retPayload = await runAndCatchErr(() => { | ||
return walletController.boot(password); | ||
}, payload.method) | ||
break; | ||
} | ||
case 'walletController.isBooted': { | ||
retPayload = await runAndCatchErr(() => { | ||
return walletController.isBooted.apply(walletController); | ||
}, payload.method) | ||
break; | ||
} | ||
case 'walletController.isUnlocked': { | ||
retPayload = await runAndCatchErr(() => { | ||
return walletController.isUnlocked.apply(walletController); | ||
}, payload.method) | ||
break; | ||
} | ||
case 'walletController.lockWallet': { | ||
retPayload = await runAndCatchErr(() => { | ||
return walletController.lockWallet.apply(walletController); | ||
}, payload.method) | ||
break; | ||
} | ||
case 'walletController.unlock': { | ||
retPayload = await runAndCatchErr(() => { | ||
return walletController.unlock.apply(walletController, payload.params as any); | ||
}, payload.method) | ||
break; | ||
} | ||
case 'walletController.getConnectedSites': { | ||
retPayload = await runAndCatchErr(() => { | ||
return walletController.getConnectedSites.apply(walletController); | ||
}, payload.method) | ||
break; | ||
} | ||
case 'walletController.importPrivateKey': { | ||
retPayload = await runAndCatchErr(() => { | ||
const [password] = payload.params || []; | ||
return walletController.importPrivateKey.apply(walletController, [password]); | ||
}, payload.method) | ||
break; | ||
} | ||
case 'walletController.getAlianName': { | ||
retPayload = await runAndCatchErr(() => { | ||
const [address] = payload.params || []; | ||
return walletController.getAlianName.apply(walletController, [address]); | ||
}, payload.method) | ||
break; | ||
} | ||
case 'walletController.updateAlianName': { | ||
retPayload = await runAndCatchErr(() => { | ||
const [address, name] = payload.params || []; | ||
return walletController.updateAlianName.apply(walletController, [address, name]); | ||
}, payload.method) | ||
break; | ||
} | ||
default: { | ||
const [ns, method] = payload.method.split('.'); | ||
|
||
if (ns === 'walletController' && typeof walletController[method] === 'function') { | ||
retPayload = await runAndCatchErr(() => { | ||
return walletController[method].apply(walletController, payload.params); | ||
}, payload.method) | ||
} else { | ||
retPayload.error = { | ||
message: `[rabbyx-rpc-query] method ${payload.method} is not supported` | ||
} | ||
} | ||
} | ||
} | ||
|
||
// console.debug('[debug] retPayload', retPayload); | ||
|
||
window.rabbyDesktop.ipcRenderer.sendMessage('rabbyx-rpc-respond', JSON.stringify({ | ||
rpcId: payload.rpcId, | ||
result: retPayload?.result, | ||
error: retPayload?.error, | ||
})); | ||
} | ||
|
||
if (window.rabbyDesktop?.ipcRenderer.on) { | ||
console.warn('[debug] window.rabbyDesktop?.ipcRenderer.on', window.rabbyDesktop?.ipcRenderer.on); | ||
window.rabbyDesktop?.ipcRenderer.on('rabbyx-rpc-query', onRabbyxRpcQuery); | ||
} else { | ||
document.addEventListener('rabbyx-rpc-query', (e: any) => { | ||
onRabbyxRpcQuery(e.detail); | ||
}); | ||
} |
Oops, something went wrong.