Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function* approveTokenDeposit({ address, symbol, amount, options }) {
let confOnDeviceDone;
let confOnDevice;
let signer;
try {
const { nahmiiProvider } = yield select(makeSelectCurrentNetwork());
const wallet = (yield select(makeSelectWallets())).toJS().find((w) => w.address === address);
[signer, confOnDevice, confOnDeviceDone] = yield call(getSdkWalletSigner, wallet);
const nahmiiWallet = new nahmii.Wallet(signer, nahmiiProvider);
if (confOnDevice) yield put(confOnDevice);
const { hash } = yield call(() => nahmiiWallet.approveTokenDeposit(amount, symbol, options));
if (confOnDeviceDone) yield put(confOnDeviceDone);
yield call(() => nahmiiProvider.getTransactionConfirmation(hash));
yield put(actions.nahmiiApproveTokenDepositSuccess());
} catch (e) {
if (confOnDeviceDone) yield put(confOnDeviceDone);
yield put(notify('error', getIntl().formatMessage({ id: 'send_transaction_failed_message_error' }, { message: e.message })));
yield put(actions.nahmiiDepositFailed(`An error occured: ${e.message}`));
}
}
export function* completeTokenDeposit({ address, symbol, amount, options }) {
let confOnDeviceDone;
let confOnDevice;
let signer;
try {
const { nahmiiProvider } = yield select(makeSelectCurrentNetwork());
const wallet = (yield select(makeSelectWallets())).toJS().find((w) => w.address === address);
[signer, confOnDevice, confOnDeviceDone] = yield call(getSdkWalletSigner, wallet);
const nahmiiWallet = new nahmii.Wallet(signer, nahmiiProvider);
if (confOnDevice) yield put(confOnDevice);
const { hash } = yield call(() => nahmiiWallet.completeTokenDeposit(amount, symbol, options));
if (confOnDeviceDone) yield put(confOnDeviceDone);
yield call(() => nahmiiProvider.getTransactionConfirmation(hash));
yield put(actions.nahmiiCompleteTokenDepositSuccess());
yield put(notify('success', getIntl().formatMessage({ id: 'deposit_success' })));
} catch (e) {
if (confOnDeviceDone) yield put(confOnDeviceDone);
yield put(notify('error', getIntl().formatMessage({ id: 'send_transaction_failed_message_error' }, { message: e.message })));
yield put(actions.nahmiiDepositFailed(`An error occured: ${e.message}`));
}
}
export function* makePayment({ monetaryAmount, recipient, walletOverride }) {
let signer;
let confOnDevice;
let confOnDeviceDone;
try {
const wallet = walletOverride || (yield (select(makeSelectCurrentWalletWithInfo()))).toJS();
if (wallet.encrypted && !wallet.decrypted) {
yield put(showDecryptWalletModal(actions.makeNahmiiPayment(monetaryAmount, recipient, walletOverride)));
yield put(actions.nahmiiPaymentError(new Error(getIntl().formatMessage({ id: 'wallet_encrypted_error' }))));
return;
}
const network = yield select(makeSelectCurrentNetwork());
const nahmiiProvider = network.nahmiiProvider;
[signer, confOnDevice, confOnDeviceDone] = yield call(getSdkWalletSigner, wallet);
const nahmiiWallet = new nahmii.Wallet(signer, nahmiiProvider);
const payment = new nahmii.Payment(monetaryAmount, wallet.address, recipient, nahmiiWallet);
if (confOnDevice) yield put(confOnDevice);
yield call([payment, 'sign']);
if (confOnDeviceDone) yield put(confOnDeviceDone);
yield call([payment, 'register']);
yield put(actions.nahmiiPaymentSuccess());
yield put(notify('success', getIntl().formatMessage({ id: 'sent_transaction_success' })));
} catch (e) {
if (confOnDeviceDone) yield put(confOnDeviceDone);
yield put(actions.nahmiiPaymentError(e));
yield put(notify('error', getIntl().formatMessage({ id: 'send_transaction_failed_message_error' }, { message: e.message })));
}
}
export function* depositEth({ address, amount, options }) {
let confOnDeviceDone;
let confOnDevice;
let signer;
try {
const { nahmiiProvider } = yield select(makeSelectCurrentNetwork());
const wallet = (yield select(makeSelectWallets())).toJS().find((w) => w.address === address);
[signer, confOnDevice, confOnDeviceDone] = yield call(getSdkWalletSigner, wallet);
const nahmiiWallet = new nahmii.Wallet(signer, nahmiiProvider);
if (confOnDevice) yield put(confOnDevice);
const { hash } = yield call(() => nahmiiWallet.depositEth(amount, options));
if (confOnDeviceDone) yield put(confOnDeviceDone);
yield call(() => nahmiiProvider.getTransactionConfirmation(hash));
yield put(actions.nahmiiDepositEthSuccess());
yield put(notify('success', getIntl().formatMessage({ id: 'deposit_success' })));
} catch (e) {
if (confOnDeviceDone) yield put(confOnDeviceDone);
yield put(notify('error', getIntl().formatMessage({ id: 'send_transaction_failed_message_error' }, { message: e.message })));
yield put(actions.nahmiiDepositFailed(`An error occured: ${e.message}`));
}
}